summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Random.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Random.hs')
-rw-r--r--lib/Data/Packed/Random.hs11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/Data/Packed/Random.hs b/lib/Data/Packed/Random.hs
index 3b02225..33a11d7 100644
--- a/lib/Data/Packed/Random.hs
+++ b/lib/Data/Packed/Random.hs
@@ -23,7 +23,6 @@ import Numeric.GSL.Vector
23import Data.Packed.Matrix 23import Data.Packed.Matrix
24import Data.Packed.Vector 24import Data.Packed.Vector
25import Numeric.LinearAlgebra.Algorithms 25import Numeric.LinearAlgebra.Algorithms
26import Numeric.LinearAlgebra.Interface
27import Numeric.LinearAlgebra.Linear 26import Numeric.LinearAlgebra.Linear
28 27
29-- | Obtains a matrix whose rows are pseudorandom samples from a multivariate 28-- | Obtains a matrix whose rows are pseudorandom samples from a multivariate
@@ -37,7 +36,7 @@ gaussianSample seed n med cov = m where
37 c = dim med 36 c = dim med
38 meds = constant 1 n `outer` med 37 meds = constant 1 n `outer` med
39 rs = reshape c $ randomVector seed Gaussian (c * n) 38 rs = reshape c $ randomVector seed Gaussian (c * n)
40 m = rs <> cholSH cov + meds 39 m = rs `mXm` cholSH cov `add` meds
41 40
42-- | Obtains a matrix whose rows are pseudorandom samples from a multivariate 41-- | Obtains a matrix whose rows are pseudorandom samples from a multivariate
43-- uniform distribution. 42-- uniform distribution.
@@ -52,7 +51,7 @@ uniformSample seed n rgs = m where
52 d = dim a 51 d = dim a
53 dat = toRows $ reshape n $ randomVector seed Uniform (n*d) 52 dat = toRows $ reshape n $ randomVector seed Uniform (n*d)
54 am = constant 1 n `outer` a 53 am = constant 1 n `outer` a
55 m = fromColumns (zipWith scale cs dat) + am 54 m = fromColumns (zipWith scale cs dat) `add` am
56 55
57------------ utilities ------------------------------- 56------------ utilities -------------------------------
58 57
@@ -61,7 +60,7 @@ meanCov :: Matrix Double -> (Vector Double, Matrix Double)
61meanCov x = (med,cov) where 60meanCov x = (med,cov) where
62 r = rows x 61 r = rows x
63 k = 1 / fromIntegral r 62 k = 1 / fromIntegral r
64 med = constant k r <> x 63 med = constant k r `vXm` x
65 meds = constant 1 r `outer` med 64 meds = constant 1 r `outer` med
66 xc = x - meds 65 xc = x `sub` meds
67 cov = (trans xc <> xc) / fromIntegral (r-1) 66 cov = flip scale (trans xc `mXm` xc) (recip (fromIntegral (r-1)))