Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Bio.Util.Numeric
Description
Random useful stuff I didn't know where to put.
- wilson :: Double -> Int -> Int -> (Double, Double, Double)
- invnormcdf :: (Ord a, Floating a) => a -> a
- choose :: Integral a => a -> a -> a
- estimateComplexity :: (Integral a, Floating b, Ord b) => a -> a -> Maybe b
- showNum :: Show a => a -> String
- showOOM :: Double -> String
- log1p :: (Floating a, Ord a) => a -> a
- expm1 :: (Floating a, Ord a) => a -> a
- (<#>) :: (Floating a, Ord a) => a -> a -> a
- log1mexp :: (Floating a, Ord a) => a -> a
- log1pexp :: (Floating a, Ord a) => a -> a
- lsum :: (Floating a, Ord a) => [a] -> a
- llerp :: (Floating a, Ord a) => a -> a -> a -> a
Documentation
wilson :: Double -> Int -> Int -> (Double, Double, Double) Source #
Calculates the Wilson Score interval.
If (l,m,h) = wilson c x n
, then m
is the binary proportion and
(l,h)
it's c
-confidence interval for x
positive examples out of
n
observations. c
is typically something like 0.05.
invnormcdf :: (Ord a, Floating a) => a -> a Source #
estimateComplexity :: (Integral a, Floating b, Ord b) => a -> a -> Maybe b Source #
Try to estimate complexity of a whole from a sample. Suppose we
sampled total
things and among those singles
occured only once.
How many different things are there?
Let the total number be m
. The copy number follows a Poisson
distribution with paramter lambda
. Let z:=eλ, then
we have:
P(0)=e−λ=1zP(1)=λe−λ=lnzzP(≥1)=1−e−λ=1−1z singles=mlnzztotal=m(1−1z) D:=totalsingles=(1−1z)∗zlnzf:=z−1−Dlnz=0
To get z
, we solve using Newton iteration and then substitute to
get m
:
df/dz=1−D/zz′=z−z(z−1−Dlnz)z−Dm=singles∗zlnz
It converges as long as the initial z
is large enough, and 10D
(in the line for zz
below) appears to work well.
log1p :: (Floating a, Ord a) => a -> a Source #
Computes log (1+x)
to a relative precision of 10^-8
even for
very small x
. Stolen from http://www.johndcook.com/cpp_log_one_plus_x.html
expm1 :: (Floating a, Ord a) => a -> a Source #
Computes ex−1 to a relative precision of 10^-10
even for
very small x
. Stolen from http://www.johndcook.com/cpp_expm1.html
(<#>) :: (Floating a, Ord a) => a -> a -> a infixl 5 Source #
Computes ln(ex+ey) without leaving the log domain and hence without losing precision.