diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-03-28 09:42:19 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-03-28 09:42:19 +0000 |
commit | ef333e80b4c4a87ea1b019a5e7c3934366e14c5f (patch) | |
tree | 7dee4ede9bde8b4b1a685f0d277850c86e8420ee /lib/Data/Packed/Random.hs | |
parent | 9a0c3092e572f6bd11329e9acabc6470ef438203 (diff) |
randomGaussian using chol
Diffstat (limited to 'lib/Data/Packed/Random.hs')
-rw-r--r-- | lib/Data/Packed/Random.hs | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/Data/Packed/Random.hs b/lib/Data/Packed/Random.hs index fea3cdd..7e0f91f 100644 --- a/lib/Data/Packed/Random.hs +++ b/lib/Data/Packed/Random.hs | |||
@@ -34,12 +34,10 @@ gaussianSample :: Int -- ^ seed | |||
34 | -> Matrix Double -- ^ covariance matrix | 34 | -> Matrix Double -- ^ covariance matrix |
35 | -> Matrix Double -- ^ result | 35 | -> Matrix Double -- ^ result |
36 | gaussianSample seed n med cov = m where | 36 | gaussianSample seed n med cov = m where |
37 | (l,v) = eigSH' cov | 37 | c = dim med |
38 | c = dim l | ||
39 | meds = constant 1 n `outer` med | 38 | meds = constant 1 n `outer` med |
40 | rs = reshape c $ randomVector seed Gaussian (c * n) | 39 | rs = reshape c $ randomVector seed Gaussian (c * n) |
41 | ds = sqrt (abs l) | 40 | m = rs <> cholSH cov + meds |
42 | m = rs <> (diag ds <> trans v) + meds | ||
43 | 41 | ||
44 | -- | Obtains a matrix whose rows are pseudorandom samples from a multivariate | 42 | -- | Obtains a matrix whose rows are pseudorandom samples from a multivariate |
45 | -- uniform distribution. | 43 | -- uniform distribution. |