diff options
Diffstat (limited to 'packages/hmatrix')
-rw-r--r-- | packages/hmatrix/src/Numeric/HMatrix.hs | 2 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs | 27 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/Random.hs | 30 |
3 files changed, 31 insertions, 28 deletions
diff --git a/packages/hmatrix/src/Numeric/HMatrix.hs b/packages/hmatrix/src/Numeric/HMatrix.hs index c8742c4..36fcf70 100644 --- a/packages/hmatrix/src/Numeric/HMatrix.hs +++ b/packages/hmatrix/src/Numeric/HMatrix.hs | |||
@@ -134,4 +134,6 @@ import Numeric.Vector() | |||
134 | import Numeric.Container | 134 | import Numeric.Container |
135 | import Numeric.LinearAlgebra.Algorithms | 135 | import Numeric.LinearAlgebra.Algorithms |
136 | import Numeric.LinearAlgebra.Util | 136 | import Numeric.LinearAlgebra.Util |
137 | import Numeric.Random | ||
138 | |||
137 | 139 | ||
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs b/packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs index 7d134bf..fb2d54c 100644 --- a/packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs +++ b/packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs | |||
@@ -22,7 +22,6 @@ module Numeric.LinearAlgebra.Util( | |||
22 | col, | 22 | col, |
23 | (&), (¦), (——), (#), | 23 | (&), (¦), (——), (#), |
24 | (?), (¿), | 24 | (?), (¿), |
25 | rand, randn, | ||
26 | cross, | 25 | cross, |
27 | norm, | 26 | norm, |
28 | unitary, | 27 | unitary, |
@@ -60,7 +59,6 @@ import Numeric.LinearAlgebra.Algorithms hiding (i) | |||
60 | import Numeric.Matrix() | 59 | import Numeric.Matrix() |
61 | import Numeric.Vector() | 60 | import Numeric.Vector() |
62 | 61 | ||
63 | import System.Random(randomIO) | ||
64 | import Numeric.LinearAlgebra.Util.Convolution | 62 | import Numeric.LinearAlgebra.Util.Convolution |
65 | import Graphics.Plot | 63 | import Graphics.Plot |
66 | 64 | ||
@@ -77,31 +75,6 @@ disp :: Int -> Matrix Double -> IO () | |||
77 | 75 | ||
78 | disp n = putStrLn . dispf n | 76 | disp n = putStrLn . dispf n |
79 | 77 | ||
80 | -- | pseudorandom matrix with uniform elements between 0 and 1 | ||
81 | randm :: RandDist | ||
82 | -> Int -- ^ rows | ||
83 | -> Int -- ^ columns | ||
84 | -> IO (Matrix Double) | ||
85 | randm d r c = do | ||
86 | seed <- randomIO | ||
87 | return (reshape c $ randomVector seed d (r*c)) | ||
88 | |||
89 | -- | pseudorandom matrix with uniform elements between 0 and 1 | ||
90 | rand :: Int -> Int -> IO (Matrix Double) | ||
91 | rand = randm Uniform | ||
92 | |||
93 | {- | pseudorandom matrix with normal elements | ||
94 | |||
95 | >>> x <- randn 3 5 | ||
96 | >>> disp 3 x | ||
97 | 3x5 | ||
98 | 0.386 -1.141 0.491 -0.510 1.512 | ||
99 | 0.069 -0.919 1.022 -0.181 0.745 | ||
100 | 0.313 -0.670 -0.097 -1.575 -0.583 | ||
101 | |||
102 | -} | ||
103 | randn :: Int -> Int -> IO (Matrix Double) | ||
104 | randn = randm Gaussian | ||
105 | 78 | ||
106 | {- | create a real diagonal matrix from a list | 79 | {- | create a real diagonal matrix from a list |
107 | 80 | ||
diff --git a/packages/hmatrix/src/Numeric/Random.hs b/packages/hmatrix/src/Numeric/Random.hs index b4c6cde..7bf9e8b 100644 --- a/packages/hmatrix/src/Numeric/Random.hs +++ b/packages/hmatrix/src/Numeric/Random.hs | |||
@@ -16,13 +16,15 @@ module Numeric.Random ( | |||
16 | RandDist(..), | 16 | RandDist(..), |
17 | randomVector, | 17 | randomVector, |
18 | gaussianSample, | 18 | gaussianSample, |
19 | uniformSample | 19 | uniformSample, |
20 | rand, randn | ||
20 | ) where | 21 | ) where |
21 | 22 | ||
22 | import Numeric.GSL.Vector | 23 | import Numeric.GSL.Vector |
23 | import Data.Packed | 24 | import Data.Packed |
24 | import Data.Packed.Numeric | 25 | import Data.Packed.Numeric |
25 | import Numeric.LinearAlgebra.Algorithms | 26 | import Numeric.LinearAlgebra.Algorithms |
27 | import System.Random(randomIO) | ||
26 | 28 | ||
27 | 29 | ||
28 | type Seed = Int | 30 | type Seed = Int |
@@ -55,3 +57,29 @@ uniformSample seed n rgs = m where | |||
55 | am = konst' 1 n `outer` a | 57 | am = konst' 1 n `outer` a |
56 | m = fromColumns (zipWith scale cs dat) `add` am | 58 | m = fromColumns (zipWith scale cs dat) `add` am |
57 | 59 | ||
60 | -- | pseudorandom matrix with uniform elements between 0 and 1 | ||
61 | randm :: RandDist | ||
62 | -> Int -- ^ rows | ||
63 | -> Int -- ^ columns | ||
64 | -> IO (Matrix Double) | ||
65 | randm d r c = do | ||
66 | seed <- randomIO | ||
67 | return (reshape c $ randomVector seed d (r*c)) | ||
68 | |||
69 | -- | pseudorandom matrix with uniform elements between 0 and 1 | ||
70 | rand :: Int -> Int -> IO (Matrix Double) | ||
71 | rand = randm Uniform | ||
72 | |||
73 | {- | pseudorandom matrix with normal elements | ||
74 | |||
75 | >>> x <- randn 3 5 | ||
76 | >>> disp 3 x | ||
77 | 3x5 | ||
78 | 0.386 -1.141 0.491 -0.510 1.512 | ||
79 | 0.069 -0.919 1.022 -0.181 0.745 | ||
80 | 0.313 -0.670 -0.097 -1.575 -0.583 | ||
81 | |||
82 | -} | ||
83 | randn :: Int -> Int -> IO (Matrix Double) | ||
84 | randn = randm Gaussian | ||
85 | |||