random-variates 0.1.5.0 → 0.1.5.1
raw patch · 4 files changed
+10/−15 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- random-variates.cabal +1/−1
- src/Stochastic/Distributions/Continuous.hs +2/−5
- src/Stochastic/Distributions/Discrete.hs +5/−7
- src/Stochastic/Uniform.hs +2/−2
random-variates.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: random-variates-version: 0.1.5.0+version: 0.1.5.1 synopsis: "Uniform RNG => Non-Uniform RNGs" description: "Collection of transforms uniform random number generators (RNGs) into any of a dozen common RNGs. Each presenting several common interfaces. Additionally Empirical distributions can be sampled from and tested (chi-squared) against theoretical distributions." license: MIT
src/Stochastic/Distributions/Continuous.hs view
@@ -66,8 +66,6 @@ intWordDbl :: Int -> Double intWordDbl x = fromRational $ toRational ((fromInteger $ toInteger x) :: Word) -randomN :: forall a . forall b . (RandomGen a, Random b) => Int -> a -> ([b], a)-randomN n = genTake (random) n expTransform :: Double -> Double -> Double expTransform y x = -(log $ x) / y@@ -78,13 +76,12 @@ entropy (Sample (Normal mean dev m) u) = (entropy u) + (fromMaybe 0 (fmap (\_->1) m)) rand (Sample (Exponential y) u) =- mapTuple (expTransform y) (Sample $ Exponential y) (random u)+ mapTuple (expTransform y) (Sample $ Exponential y) (rand u) rand (Sample (Normal mean dev m) uni) = f m where f (Just x) = (x, (Sample (Normal mean dev Nothing) uni')) f Nothing = (y, (Sample (Normal mean dev (Just z)) uni'))- (vs, uni') = randomN 2 uni- [u1, u2] = map (id) vs+ ([u1, u2], uni') = rands 2 uni from_u g = mean + dev * (sqrt (-2 * (log u1))) * ( g (2 * pi * u2) ) y = from_u (sin) z = from_u (cos)
src/Stochastic/Distributions/Discrete.hs view
@@ -85,8 +85,6 @@ sub = create (k-1) (j, pmfj, cdfj) = head sub -nextN :: forall a . RandomGen a => Int -> a -> ([Int], a)-nextN n = genTake (next) n instance DiscreteSample Sample where entropy (Sample _ u) = entropy u@@ -96,13 +94,13 @@ (\u -> length $ filter (pred u) cache ) (Sample $ Binomial n p cache)- (random g0)+ (C.rand g0) where pred u (k, pmf, cdf) = cdf < u rand (Sample (Geometric p) g0) = mapTuple ((\u -> ceiling $ (log u) / (log (1-p)))) (Sample $ Geometric p)- (random g0)+ (C.rand g0) rand (Sample (Poisson y) g0) = let f (x, g1) = (C.expTransform y x, g1) in mapTuple@@ -113,19 +111,19 @@ mapTuple (\x -> if (x >= p) then 1 else 0) (Sample $ Bernoulli p)- (random g0)+ (C.rand g0) rand (Sample (ZipF n slope cache) u0) = mapTuple (\u -> 1 + (length $ filter (pred u) cache)) (Sample $ ZipF n slope cache)- (random u0)+ (C.rand u0) where pred u (k, pmf, cdf) = cdf < u rand (Sample (Uniform a b) g0) = mapTuple (\x -> truncate (toDbl (b - a) * x + toDbl a)) (Sample $ Uniform a b)- (random g0)+ (C.rand g0) instance DiscreteDistribution Sample where cdf (Sample d _) = cdf d
src/Stochastic/Uniform.hs view
@@ -15,7 +15,7 @@ import Data.Typeable import Control.Exception(throw, Exception) import Data.Int-+import GHC.Stack(errorWithStackTrace) import System.Random(RandomGen(..)) data UniformRandom = XorShift128Plus Word64 Word64 Integer@@ -53,7 +53,7 @@ instance RandomGen UniformRandom where next (XorShift128Plus high low entropy) - | entropy == 0 = throw EntropyExhausted+ | entropy == 0 = errorWithStackTrace "Entropy Exausted" | otherwise = final where -- eagerly evaluate this function, retain no intermediaries or we might blow the stack