summaryrefslogtreecommitdiff
path: root/packages/hmatrix/src/Data/Packed
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-05-08 08:56:43 +0200
committerAlberto Ruiz <aruiz@um.es>2014-05-08 08:56:43 +0200
commitd558f5165e7e7f4daffadae1197e53618727971d (patch)
treebfdb293eca4f2e7a8ae5e7230dd244975e3c3a27 /packages/hmatrix/src/Data/Packed
parent1925c123d7d8184a1d2ddc0a413e0fd2776e1083 (diff)
moved Random
Diffstat (limited to 'packages/hmatrix/src/Data/Packed')
-rw-r--r--packages/hmatrix/src/Data/Packed/Random.hs57
1 files changed, 0 insertions, 57 deletions
diff --git a/packages/hmatrix/src/Data/Packed/Random.hs b/packages/hmatrix/src/Data/Packed/Random.hs
deleted file mode 100644
index e8b0268..0000000
--- a/packages/hmatrix/src/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
14module Data.Packed.Random (
15 Seed,
16 RandDist(..),
17 randomVector,
18 gaussianSample,
19 uniformSample
20) where
21
22import Numeric.GSL.Vector
23import Data.Packed
24import Numeric.ContainerBoot
25import Numeric.LinearAlgebra.Algorithms
26
27
28type Seed = Int
29
30-- | Obtains a matrix whose rows are pseudorandom samples from a multivariate
31-- Gaussian distribution.
32gaussianSample :: Seed
33 -> Int -- ^ number of rows
34 -> Vector Double -- ^ mean vector
35 -> Matrix Double -- ^ covariance matrix
36 -> Matrix Double -- ^ result
37gaussianSample 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.
45uniformSample :: Seed
46 -> Int -- ^ number of rows
47 -> [(Double,Double)] -- ^ ranges for each column
48 -> Matrix Double -- ^ result
49uniformSample 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