From b015999218c7e46e0566f01d2bbdf42436b87950 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Mon, 12 Mar 2012 10:34:11 +0100 Subject: randn --- examples/Real.hs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'examples') 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( row, col, (#),(&), (//), blocks, - rand + rand, randn ) where -import Numeric.LinearAlgebra hiding ((<>), (<|>), (<->), (<\>), (.*), (*/)) +import Numeric.LinearAlgebra hiding ((<>), (<\>)) import System.Random(randomIO) infixl 7 <> @@ -44,12 +44,21 @@ infixl 7 \> m \> v = flatten (m <\> reshape 1 v) -- | Pseudorandom matrix with uniform elements between 0 and 1. -rand :: Int -- ^ rows +randm :: RandDist + -> Int -- ^ rows -> Int -- ^ columns -> IO (Matrix Double) -rand r c = do +randm d r c = do seed <- randomIO - return (reshape c $ randomVector seed Uniform (r*c)) + return (reshape c $ randomVector seed d (r*c)) + +-- | Pseudorandom matrix with uniform elements between 0 and 1. +rand :: Int -> Int -> IO (Matrix Double) +rand = randm Uniform + +-- | Pseudorandom matrix with normal elements +randn :: Int -> Int -> IO (Matrix Double) +randn = randm Gaussian -- | Real identity matrix. eye :: Int -> Matrix Double -- cgit v1.2.3