From d558f5165e7e7f4daffadae1197e53618727971d Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Thu, 8 May 2014 08:56:43 +0200 Subject: moved Random --- packages/hmatrix/hmatrix.cabal | 2 +- packages/hmatrix/src/Data/Packed/Random.hs | 57 ------------------------------ packages/hmatrix/src/Numeric/Container.hs | 2 +- packages/hmatrix/src/Numeric/Random.hs | 57 ++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 59 deletions(-) delete mode 100644 packages/hmatrix/src/Data/Packed/Random.hs create mode 100644 packages/hmatrix/src/Numeric/Random.hs (limited to 'packages') diff --git a/packages/hmatrix/hmatrix.cabal b/packages/hmatrix/hmatrix.cabal index b029dc9..afd678f 100644 --- a/packages/hmatrix/hmatrix.cabal +++ b/packages/hmatrix/hmatrix.cabal @@ -115,7 +115,7 @@ library Data.Packed.Internal.Signatures, Data.Packed.Internal.Vector, Data.Packed.Internal.Matrix, - Data.Packed.Random, + Numeric.Random, Numeric.GSL.Internal, Numeric.GSL.Vector, Numeric.Conversion, 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 @@ ------------------------------------------------------------------------------ --- | --- Module : Data.Packed.Vector --- Copyright : (c) Alberto Ruiz 2009 --- License : GPL --- --- Maintainer : Alberto Ruiz --- Stability : provisional --- --- Random vectors and matrices. --- ------------------------------------------------------------------------------ - -module Data.Packed.Random ( - Seed, - RandDist(..), - randomVector, - gaussianSample, - uniformSample -) where - -import Numeric.GSL.Vector -import Data.Packed -import Numeric.ContainerBoot -import Numeric.LinearAlgebra.Algorithms - - -type Seed = Int - --- | Obtains a matrix whose rows are pseudorandom samples from a multivariate --- Gaussian distribution. -gaussianSample :: Seed - -> Int -- ^ number of rows - -> Vector Double -- ^ mean vector - -> Matrix Double -- ^ covariance matrix - -> Matrix Double -- ^ result -gaussianSample seed n med cov = m where - c = dim med - meds = konst' 1 n `outer` med - rs = reshape c $ randomVector seed Gaussian (c * n) - m = rs `mXm` cholSH cov `add` meds - --- | Obtains a matrix whose rows are pseudorandom samples from a multivariate --- uniform distribution. -uniformSample :: Seed - -> Int -- ^ number of rows - -> [(Double,Double)] -- ^ ranges for each column - -> Matrix Double -- ^ result -uniformSample seed n rgs = m where - (as,bs) = unzip rgs - a = fromList as - cs = zipWith subtract as bs - d = dim a - dat = toRows $ reshape n $ randomVector seed Uniform (n*d) - am = konst' 1 n `outer` a - m = fromColumns (zipWith scale cs dat) `add` am - diff --git a/packages/hmatrix/src/Numeric/Container.hs b/packages/hmatrix/src/Numeric/Container.hs index 7e46147..ff649b7 100644 --- a/packages/hmatrix/src/Numeric/Container.hs +++ b/packages/hmatrix/src/Numeric/Container.hs @@ -71,7 +71,7 @@ import Numeric.Chain import Numeric.IO import Data.Complex import Numeric.LinearAlgebra.Algorithms(Field,linearSolveSVD) -import Data.Packed.Random +import Numeric.Random ------------------------------------------------------------------ diff --git a/packages/hmatrix/src/Numeric/Random.hs b/packages/hmatrix/src/Numeric/Random.hs new file mode 100644 index 0000000..936c777 --- /dev/null +++ b/packages/hmatrix/src/Numeric/Random.hs @@ -0,0 +1,57 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Numeric.Random +-- Copyright : (c) Alberto Ruiz 2009-14 +-- License : GPL +-- +-- Maintainer : Alberto Ruiz +-- Stability : provisional +-- +-- Random vectors and matrices. +-- +----------------------------------------------------------------------------- + +module Numeric.Random ( + Seed, + RandDist(..), + randomVector, + gaussianSample, + uniformSample +) where + +import Numeric.GSL.Vector +import Data.Packed +import Numeric.ContainerBoot +import Numeric.LinearAlgebra.Algorithms + + +type Seed = Int + +-- | Obtains a matrix whose rows are pseudorandom samples from a multivariate +-- Gaussian distribution. +gaussianSample :: Seed + -> Int -- ^ number of rows + -> Vector Double -- ^ mean vector + -> Matrix Double -- ^ covariance matrix + -> Matrix Double -- ^ result +gaussianSample seed n med cov = m where + c = dim med + meds = konst' 1 n `outer` med + rs = reshape c $ randomVector seed Gaussian (c * n) + m = rs `mXm` cholSH cov `add` meds + +-- | Obtains a matrix whose rows are pseudorandom samples from a multivariate +-- uniform distribution. +uniformSample :: Seed + -> Int -- ^ number of rows + -> [(Double,Double)] -- ^ ranges for each column + -> Matrix Double -- ^ result +uniformSample seed n rgs = m where + (as,bs) = unzip rgs + a = fromList as + cs = zipWith subtract as bs + d = dim a + dat = toRows $ reshape n $ randomVector seed Uniform (n*d) + am = konst' 1 n `outer` a + m = fromColumns (zipWith scale cs dat) `add` am + -- cgit v1.2.3