diff options
Diffstat (limited to 'packages/hmatrix/src/Numeric')
-rw-r--r-- | packages/hmatrix/src/Numeric/Container.hs | 2 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs | 61 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/GSL/gsl-aux.c | 4 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/LinearAlgebra/Random.hs | 4 |
4 files changed, 9 insertions, 62 deletions
diff --git a/packages/hmatrix/src/Numeric/Container.hs b/packages/hmatrix/src/Numeric/Container.hs index b6e797b..2b61d90 100644 --- a/packages/hmatrix/src/Numeric/Container.hs +++ b/packages/hmatrix/src/Numeric/Container.hs | |||
@@ -16,7 +16,7 @@ module Numeric.Container ( | |||
16 | meanCov | 16 | meanCov |
17 | ) where | 17 | ) where |
18 | 18 | ||
19 | import Data.Packed.Numeric | 19 | import Data.Packed.Numeric hiding (saveMatrix, loadMatrix) |
20 | import Numeric.LinearAlgebra.IO | 20 | import Numeric.LinearAlgebra.IO |
21 | import Numeric.LinearAlgebra.Random hiding (Seed) | 21 | import Numeric.LinearAlgebra.Random hiding (Seed) |
22 | import Numeric.LinearAlgebra.Util(meanCov) | 22 | import Numeric.LinearAlgebra.Util(meanCov) |
diff --git a/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs b/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs index 43e46c5..8bd0cc2 100644 --- a/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs +++ b/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs | |||
@@ -9,15 +9,15 @@ | |||
9 | ----------------------------------------------------------------------------- | 9 | ----------------------------------------------------------------------------- |
10 | 10 | ||
11 | module Numeric.GSL.LinearAlgebra ( | 11 | module Numeric.GSL.LinearAlgebra ( |
12 | RandDist(..), randomVector, | 12 | randomVector, |
13 | saveMatrix, | 13 | saveMatrix, |
14 | fwriteVector, freadVector, fprintfVector, fscanfVector | 14 | fwriteVector, freadVector, fprintfVector, fscanfVector |
15 | ) where | 15 | ) where |
16 | 16 | ||
17 | import Data.Packed | 17 | import Data.Packed |
18 | import Numeric.LinearAlgebra.Base(RandDist(..)) | ||
18 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) | 19 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) |
19 | 20 | ||
20 | import Data.Complex | ||
21 | import Foreign.Marshal.Alloc(free) | 21 | import Foreign.Marshal.Alloc(free) |
22 | import Foreign.Ptr(Ptr) | 22 | import Foreign.Ptr(Ptr) |
23 | import Foreign.C.Types | 23 | import Foreign.C.Types |
@@ -28,10 +28,6 @@ fromei x = fromIntegral (fromEnum x) :: CInt | |||
28 | 28 | ||
29 | ----------------------------------------------------------------------- | 29 | ----------------------------------------------------------------------- |
30 | 30 | ||
31 | data RandDist = Uniform -- ^ uniform distribution in [0,1) | ||
32 | | Gaussian -- ^ normal distribution with mean zero and standard deviation one | ||
33 | deriving Enum | ||
34 | |||
35 | -- | Obtains a vector of pseudorandom elements from the the mt19937 generator in GSL, with a given seed. Use randomIO to get a random seed. | 31 | -- | Obtains a vector of pseudorandom elements from the the mt19937 generator in GSL, with a given seed. Use randomIO to get a random seed. |
36 | randomVector :: Int -- ^ seed | 32 | randomVector :: Int -- ^ seed |
37 | -> RandDist -- ^ distribution | 33 | -> RandDist -- ^ distribution |
@@ -39,10 +35,10 @@ randomVector :: Int -- ^ seed | |||
39 | -> Vector Double | 35 | -> Vector Double |
40 | randomVector seed dist n = unsafePerformIO $ do | 36 | randomVector seed dist n = unsafePerformIO $ do |
41 | r <- createVector n | 37 | r <- createVector n |
42 | app1 (c_random_vector (fi seed) ((fi.fromEnum) dist)) vec r "randomVector" | 38 | app1 (c_random_vector_GSL (fi seed) ((fi.fromEnum) dist)) vec r "randomVectorGSL" |
43 | return r | 39 | return r |
44 | 40 | ||
45 | foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> TV | 41 | foreign import ccall unsafe "random_vector_GSL" c_random_vector_GSL :: CInt -> CInt -> TV |
46 | 42 | ||
47 | -------------------------------------------------------------------------------- | 43 | -------------------------------------------------------------------------------- |
48 | 44 | ||
@@ -105,56 +101,7 @@ fwriteVector filename v = do | |||
105 | 101 | ||
106 | foreign import ccall unsafe "vector_fwrite" gsl_vector_fwrite :: Ptr CChar -> TV | 102 | foreign import ccall unsafe "vector_fwrite" gsl_vector_fwrite :: Ptr CChar -> TV |
107 | 103 | ||
108 | type PF = Ptr Float -- | ||
109 | type PD = Ptr Double -- | 104 | type PD = Ptr Double -- |
110 | type PQ = Ptr (Complex Float) -- | ||
111 | type PC = Ptr (Complex Double) -- | ||
112 | type TF = CInt -> PF -> IO CInt -- | ||
113 | type TFF = CInt -> PF -> TF -- | ||
114 | type TFV = CInt -> PF -> TV -- | ||
115 | type TVF = CInt -> PD -> TF -- | ||
116 | type TFFF = CInt -> PF -> TFF -- | ||
117 | type TV = CInt -> PD -> IO CInt -- | 105 | type TV = CInt -> PD -> IO CInt -- |
118 | type TVV = CInt -> PD -> TV -- | ||
119 | type TVVV = CInt -> PD -> TVV -- | ||
120 | type TFM = CInt -> CInt -> PF -> IO CInt -- | ||
121 | type TFMFM = CInt -> CInt -> PF -> TFM -- | ||
122 | type TFMFMFM = CInt -> CInt -> PF -> TFMFM -- | ||
123 | type TM = CInt -> CInt -> PD -> IO CInt -- | 106 | type TM = CInt -> CInt -> PD -> IO CInt -- |
124 | type TMM = CInt -> CInt -> PD -> TM -- | ||
125 | type TVMM = CInt -> PD -> TMM -- | ||
126 | type TMVMM = CInt -> CInt -> PD -> TVMM -- | ||
127 | type TMMM = CInt -> CInt -> PD -> TMM -- | ||
128 | type TVM = CInt -> PD -> TM -- | ||
129 | type TVVM = CInt -> PD -> TVM -- | ||
130 | type TMV = CInt -> CInt -> PD -> TV -- | ||
131 | type TMMV = CInt -> CInt -> PD -> TMV -- | ||
132 | type TMVM = CInt -> CInt -> PD -> TVM -- | ||
133 | type TMMVM = CInt -> CInt -> PD -> TMVM -- | ||
134 | type TCM = CInt -> CInt -> PC -> IO CInt -- | ||
135 | type TCVCM = CInt -> PC -> TCM -- | ||
136 | type TCMCVCM = CInt -> CInt -> PC -> TCVCM -- | ||
137 | type TMCMCVCM = CInt -> CInt -> PD -> TCMCVCM -- | ||
138 | type TCMCMCVCM = CInt -> CInt -> PC -> TCMCVCM -- | ||
139 | type TCMCM = CInt -> CInt -> PC -> TCM -- | ||
140 | type TVCM = CInt -> PD -> TCM -- | ||
141 | type TCMVCM = CInt -> CInt -> PC -> TVCM -- | ||
142 | type TCMCMVCM = CInt -> CInt -> PC -> TCMVCM -- | ||
143 | type TCMCMCM = CInt -> CInt -> PC -> TCMCM -- | ||
144 | type TCV = CInt -> PC -> IO CInt -- | ||
145 | type TCVCV = CInt -> PC -> TCV -- | ||
146 | type TCVCVCV = CInt -> PC -> TCVCV -- | ||
147 | type TCVV = CInt -> PC -> TV -- | ||
148 | type TQV = CInt -> PQ -> IO CInt -- | ||
149 | type TQVQV = CInt -> PQ -> TQV -- | ||
150 | type TQVQVQV = CInt -> PQ -> TQVQV -- | ||
151 | type TQVF = CInt -> PQ -> TF -- | ||
152 | type TQM = CInt -> CInt -> PQ -> IO CInt -- | ||
153 | type TQMQM = CInt -> CInt -> PQ -> TQM -- | ||
154 | type TQMQMQM = CInt -> CInt -> PQ -> TQMQM -- | ||
155 | type TCMCV = CInt -> CInt -> PC -> TCV -- | ||
156 | type TVCV = CInt -> PD -> TCV -- | ||
157 | type TCVM = CInt -> PC -> TM -- | ||
158 | type TMCVM = CInt -> CInt -> PD -> TCVM -- | ||
159 | type TMMCVM = CInt -> CInt -> PD -> TMCVM -- | ||
160 | 107 | ||
diff --git a/packages/hmatrix/src/Numeric/GSL/gsl-aux.c b/packages/hmatrix/src/Numeric/GSL/gsl-aux.c index 5da94ca..ffc5c20 100644 --- a/packages/hmatrix/src/Numeric/GSL/gsl-aux.c +++ b/packages/hmatrix/src/Numeric/GSL/gsl-aux.c | |||
@@ -924,8 +924,8 @@ int nlfit(int method, int f(int, double*, int, double*), | |||
924 | 924 | ||
925 | #define RAN(C,F) case C: { for(k=0;k<rn;k++) { rp[k]= F(gen); }; OK } | 925 | #define RAN(C,F) case C: { for(k=0;k<rn;k++) { rp[k]= F(gen); }; OK } |
926 | 926 | ||
927 | int random_vector(int seed, int code, RVEC(r)) { | 927 | int random_vector_GSL(int seed, int code, RVEC(r)) { |
928 | DEBUGMSG("random_vector") | 928 | DEBUGMSG("random_vector_GSL") |
929 | static gsl_rng * gen = NULL; | 929 | static gsl_rng * gen = NULL; |
930 | if (!gen) { gen = gsl_rng_alloc (gsl_rng_mt19937);} | 930 | if (!gen) { gen = gsl_rng_alloc (gsl_rng_mt19937);} |
931 | gsl_rng_set (gen, seed); | 931 | gsl_rng_set (gen, seed); |
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra/Random.hs b/packages/hmatrix/src/Numeric/LinearAlgebra/Random.hs index 0a82d3f..fa125a0 100644 --- a/packages/hmatrix/src/Numeric/LinearAlgebra/Random.hs +++ b/packages/hmatrix/src/Numeric/LinearAlgebra/Random.hs | |||
@@ -22,11 +22,11 @@ module Numeric.LinearAlgebra.Random ( | |||
22 | 22 | ||
23 | import Numeric.GSL.LinearAlgebra | 23 | import Numeric.GSL.LinearAlgebra |
24 | import Data.Packed.Numeric | 24 | import Data.Packed.Numeric |
25 | import Numeric.LinearAlgebra.Algorithms | 25 | import Numeric.LinearAlgebra.Base(Seed,RandDist(..),cholSH) |
26 | import System.Random(randomIO) | 26 | import System.Random(randomIO) |
27 | 27 | ||
28 | 28 | ||
29 | type Seed = Int | 29 | |
30 | 30 | ||
31 | -- | Obtains a matrix whose rows are pseudorandom samples from a multivariate | 31 | -- | Obtains a matrix whose rows are pseudorandom samples from a multivariate |
32 | -- Gaussian distribution. | 32 | -- Gaussian distribution. |