diff options
Diffstat (limited to 'lib/Data/Packed/Random.hs')
-rw-r--r-- | lib/Data/Packed/Random.hs | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/lib/Data/Packed/Random.hs b/lib/Data/Packed/Random.hs deleted file mode 100644 index e8b0268..0000000 --- a/lib/Data/Packed/Random.hs +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | -- | | ||
3 | -- Module : Data.Packed.Vector | ||
4 | -- Copyright : (c) Alberto Ruiz 2009 | ||
5 | -- License : GPL | ||
6 | -- | ||
7 | -- Maintainer : Alberto Ruiz <aruiz@um.es> | ||
8 | -- Stability : provisional | ||
9 | -- | ||
10 | -- Random vectors and matrices. | ||
11 | -- | ||
12 | ----------------------------------------------------------------------------- | ||
13 | |||
14 | module Data.Packed.Random ( | ||
15 | Seed, | ||
16 | RandDist(..), | ||
17 | randomVector, | ||
18 | gaussianSample, | ||
19 | uniformSample | ||
20 | ) where | ||
21 | |||
22 | import Numeric.GSL.Vector | ||
23 | import Data.Packed | ||
24 | import Numeric.ContainerBoot | ||
25 | import Numeric.LinearAlgebra.Algorithms | ||
26 | |||
27 | |||
28 | type Seed = Int | ||
29 | |||
30 | -- | Obtains a matrix whose rows are pseudorandom samples from a multivariate | ||
31 | -- Gaussian distribution. | ||
32 | gaussianSample :: Seed | ||
33 | -> Int -- ^ number of rows | ||
34 | -> Vector Double -- ^ mean vector | ||
35 | -> Matrix Double -- ^ covariance matrix | ||
36 | -> Matrix Double -- ^ result | ||
37 | gaussianSample seed n med cov = m where | ||
38 | c = dim med | ||
39 | meds = konst' 1 n `outer` med | ||
40 | rs = reshape c $ randomVector seed Gaussian (c * n) | ||
41 | m = rs `mXm` cholSH cov `add` meds | ||
42 | |||
43 | -- | Obtains a matrix whose rows are pseudorandom samples from a multivariate | ||
44 | -- uniform distribution. | ||
45 | uniformSample :: Seed | ||
46 | -> Int -- ^ number of rows | ||
47 | -> [(Double,Double)] -- ^ ranges for each column | ||
48 | -> Matrix Double -- ^ result | ||
49 | uniformSample seed n rgs = m where | ||
50 | (as,bs) = unzip rgs | ||
51 | a = fromList as | ||
52 | cs = zipWith subtract as bs | ||
53 | d = dim a | ||
54 | dat = toRows $ reshape n $ randomVector seed Uniform (n*d) | ||
55 | am = konst' 1 n `outer` a | ||
56 | m = fromColumns (zipWith scale cs dat) `add` am | ||
57 | |||