diff options
-rw-r--r-- | examples/Real.hs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/examples/Real.hs b/examples/Real.hs index 02eba9f..9083b87 100644 --- a/examples/Real.hs +++ b/examples/Real.hs | |||
@@ -11,10 +11,10 @@ module Real( | |||
11 | row, | 11 | row, |
12 | col, | 12 | col, |
13 | (#),(&), (//), blocks, | 13 | (#),(&), (//), blocks, |
14 | rand | 14 | rand, randn |
15 | ) where | 15 | ) where |
16 | 16 | ||
17 | import Numeric.LinearAlgebra hiding ((<>), (<|>), (<->), (<\>), (.*), (*/)) | 17 | import Numeric.LinearAlgebra hiding ((<>), (<\>)) |
18 | import System.Random(randomIO) | 18 | import System.Random(randomIO) |
19 | 19 | ||
20 | infixl 7 <> | 20 | infixl 7 <> |
@@ -44,12 +44,21 @@ infixl 7 \> | |||
44 | m \> v = flatten (m <\> reshape 1 v) | 44 | m \> v = flatten (m <\> reshape 1 v) |
45 | 45 | ||
46 | -- | Pseudorandom matrix with uniform elements between 0 and 1. | 46 | -- | Pseudorandom matrix with uniform elements between 0 and 1. |
47 | rand :: Int -- ^ rows | 47 | randm :: RandDist |
48 | -> Int -- ^ rows | ||
48 | -> Int -- ^ columns | 49 | -> Int -- ^ columns |
49 | -> IO (Matrix Double) | 50 | -> IO (Matrix Double) |
50 | rand r c = do | 51 | randm d r c = do |
51 | seed <- randomIO | 52 | seed <- randomIO |
52 | return (reshape c $ randomVector seed Uniform (r*c)) | 53 | return (reshape c $ randomVector seed d (r*c)) |
54 | |||
55 | -- | Pseudorandom matrix with uniform elements between 0 and 1. | ||
56 | rand :: Int -> Int -> IO (Matrix Double) | ||
57 | rand = randm Uniform | ||
58 | |||
59 | -- | Pseudorandom matrix with normal elements | ||
60 | randn :: Int -> Int -> IO (Matrix Double) | ||
61 | randn = randm Gaussian | ||
53 | 62 | ||
54 | -- | Real identity matrix. | 63 | -- | Real identity matrix. |
55 | eye :: Int -> Matrix Double | 64 | eye :: Int -> Matrix Double |