diff options
Diffstat (limited to 'packages/hmatrix')
-rw-r--r-- | packages/hmatrix/hmatrix.cabal | 15 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/Container.hs | 23 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/GSL/Fitting.hs | 2 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/GSL/IO.hs (renamed from packages/hmatrix/src/Numeric/LinearAlgebra/IO.hs) | 6 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs | 38 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/GSL/Random.hs (renamed from packages/hmatrix/src/Numeric/LinearAlgebra/Random.hs) | 10 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/GSL/Vector.hs (renamed from packages/hmatrix/src/Numeric/LinearAlgebra/GSL.hs) | 43 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/LinearAlgebra.hs | 20 |
8 files changed, 56 insertions, 101 deletions
diff --git a/packages/hmatrix/hmatrix.cabal b/packages/hmatrix/hmatrix.cabal index a61c64f..83a2188 100644 --- a/packages/hmatrix/hmatrix.cabal +++ b/packages/hmatrix/hmatrix.cabal | |||
@@ -1,5 +1,5 @@ | |||
1 | Name: hmatrix | 1 | Name: hmatrix-gsl |
2 | Version: 0.16.0.1 | 2 | Version: 0.16.0.0 |
3 | License: GPL | 3 | License: GPL |
4 | License-file: LICENSE | 4 | License-file: LICENSE |
5 | Author: Alberto Ruiz | 5 | Author: Alberto Ruiz |
@@ -73,7 +73,7 @@ flag debugnan | |||
73 | 73 | ||
74 | library | 74 | library |
75 | 75 | ||
76 | Build-Depends: base, hmatrix-base, array, vector, | 76 | Build-Depends: base, hmatrix, array, vector, |
77 | process, random | 77 | process, random |
78 | 78 | ||
79 | 79 | ||
@@ -90,13 +90,12 @@ library | |||
90 | Numeric.GSL.Fitting, | 90 | Numeric.GSL.Fitting, |
91 | Numeric.GSL.ODE, | 91 | Numeric.GSL.ODE, |
92 | Numeric.GSL, | 92 | Numeric.GSL, |
93 | Numeric.LinearAlgebra, | 93 | Numeric.GSL.LinearAlgebra, |
94 | Numeric.Container, | ||
95 | Graphics.Plot | 94 | Graphics.Plot |
96 | other-modules: Numeric.GSL.Internal, | 95 | other-modules: Numeric.GSL.Internal, |
97 | Numeric.GSL.LinearAlgebra, | 96 | Numeric.GSL.Vector, |
98 | Numeric.LinearAlgebra.IO, | 97 | Numeric.GSL.IO, |
99 | Numeric.LinearAlgebra.Random | 98 | Numeric.GSL.Random |
100 | 99 | ||
101 | 100 | ||
102 | C-sources: src/Numeric/GSL/gsl-aux.c | 101 | C-sources: src/Numeric/GSL/gsl-aux.c |
diff --git a/packages/hmatrix/src/Numeric/Container.hs b/packages/hmatrix/src/Numeric/Container.hs deleted file mode 100644 index 2b61d90..0000000 --- a/packages/hmatrix/src/Numeric/Container.hs +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | {- | | ||
3 | Module : Numeric.Container | ||
4 | Copyright : (c) Alberto Ruiz 2006-14 | ||
5 | License : GPL | ||
6 | Maintainer : Alberto Ruiz | ||
7 | Stability : provisional | ||
8 | |||
9 | -} | ||
10 | ----------------------------------------------------------------------------- | ||
11 | |||
12 | module Numeric.Container ( | ||
13 | module Data.Packed.Numeric, | ||
14 | module Numeric.LinearAlgebra.IO, | ||
15 | module Numeric.LinearAlgebra.Random, | ||
16 | meanCov | ||
17 | ) where | ||
18 | |||
19 | import Data.Packed.Numeric hiding (saveMatrix, loadMatrix) | ||
20 | import Numeric.LinearAlgebra.IO | ||
21 | import Numeric.LinearAlgebra.Random hiding (Seed) | ||
22 | import Numeric.LinearAlgebra.Util(meanCov) | ||
23 | |||
diff --git a/packages/hmatrix/src/Numeric/GSL/Fitting.hs b/packages/hmatrix/src/Numeric/GSL/Fitting.hs index 0a92373..93fb281 100644 --- a/packages/hmatrix/src/Numeric/GSL/Fitting.hs +++ b/packages/hmatrix/src/Numeric/GSL/Fitting.hs | |||
@@ -116,7 +116,7 @@ err (model,deriv) dat vsol = zip sol errs where | |||
116 | dof = length dat - (rows cov) | 116 | dof = length dat - (rows cov) |
117 | chi = norm2 (fromList $ cost (resMs model) dat sol) | 117 | chi = norm2 (fromList $ cost (resMs model) dat sol) |
118 | js = fromLists $ jacobian (resDs deriv) dat sol | 118 | js = fromLists $ jacobian (resDs deriv) dat sol |
119 | cov = inv $ trans js <> js | 119 | cov = inv $ trans js <.> js |
120 | errs = toList $ scalar c * sqrt (takeDiag cov) | 120 | errs = toList $ scalar c * sqrt (takeDiag cov) |
121 | 121 | ||
122 | 122 | ||
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra/IO.hs b/packages/hmatrix/src/Numeric/GSL/IO.hs index d2278ee..0d6031a 100644 --- a/packages/hmatrix/src/Numeric/LinearAlgebra/IO.hs +++ b/packages/hmatrix/src/Numeric/GSL/IO.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- | | 2 | -- | |
3 | -- Module : Numeric.LinearAlgebra.IO | 3 | -- Module : Numeric.GSL.IO |
4 | -- Copyright : (c) Alberto Ruiz 2007-14 | 4 | -- Copyright : (c) Alberto Ruiz 2007-14 |
5 | -- License : GPL | 5 | -- License : GPL |
6 | -- Maintainer : Alberto Ruiz | 6 | -- Maintainer : Alberto Ruiz |
@@ -8,14 +8,14 @@ | |||
8 | -- | 8 | -- |
9 | ----------------------------------------------------------------------------- | 9 | ----------------------------------------------------------------------------- |
10 | 10 | ||
11 | module Numeric.LinearAlgebra.IO ( | 11 | module Numeric.GSL.IO ( |
12 | saveMatrix, | 12 | saveMatrix, |
13 | fwriteVector, freadVector, fprintfVector, fscanfVector, | 13 | fwriteVector, freadVector, fprintfVector, fscanfVector, |
14 | fileDimensions, loadMatrix, fromFile | 14 | fileDimensions, loadMatrix, fromFile |
15 | ) where | 15 | ) where |
16 | 16 | ||
17 | import Data.Packed | 17 | import Data.Packed |
18 | import Numeric.GSL.LinearAlgebra | 18 | import Numeric.GSL.Vector |
19 | import System.Process(readProcess) | 19 | import System.Process(readProcess) |
20 | 20 | ||
21 | 21 | ||
diff --git a/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs b/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs index 8bd0cc2..17e2258 100644 --- a/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs +++ b/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs | |||
@@ -9,13 +9,13 @@ | |||
9 | ----------------------------------------------------------------------------- | 9 | ----------------------------------------------------------------------------- |
10 | 10 | ||
11 | module Numeric.GSL.LinearAlgebra ( | 11 | module Numeric.GSL.LinearAlgebra ( |
12 | randomVector, | 12 | RandDist(..), randomVector, |
13 | saveMatrix, | 13 | saveMatrix, |
14 | fwriteVector, freadVector, fprintfVector, fscanfVector | 14 | fwriteVector, freadVector, fprintfVector, fscanfVector, |
15 | fileDimensions, loadMatrix, fromFile | ||
15 | ) where | 16 | ) where |
16 | 17 | ||
17 | import Data.Packed | 18 | import Data.Packed |
18 | import Numeric.LinearAlgebra.Base(RandDist(..)) | ||
19 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) | 19 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) |
20 | 20 | ||
21 | import Foreign.Marshal.Alloc(free) | 21 | import Foreign.Marshal.Alloc(free) |
@@ -23,11 +23,16 @@ import Foreign.Ptr(Ptr) | |||
23 | import Foreign.C.Types | 23 | import Foreign.C.Types |
24 | import Foreign.C.String(newCString) | 24 | import Foreign.C.String(newCString) |
25 | import System.IO.Unsafe(unsafePerformIO) | 25 | import System.IO.Unsafe(unsafePerformIO) |
26 | import System.Process(readProcess) | ||
26 | 27 | ||
27 | fromei x = fromIntegral (fromEnum x) :: CInt | 28 | fromei x = fromIntegral (fromEnum x) :: CInt |
28 | 29 | ||
29 | ----------------------------------------------------------------------- | 30 | ----------------------------------------------------------------------- |
30 | 31 | ||
32 | data RandDist = Uniform -- ^ uniform distribution in [0,1) | ||
33 | | Gaussian -- ^ normal distribution with mean zero and standard deviation one | ||
34 | deriving Enum | ||
35 | |||
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 | -- | Obtains a vector of pseudorandom elements from the the mt19937 generator in GSL, with a given seed. Use randomIO to get a random seed. |
32 | randomVector :: Int -- ^ seed | 37 | randomVector :: Int -- ^ seed |
33 | -> RandDist -- ^ distribution | 38 | -> RandDist -- ^ distribution |
@@ -35,10 +40,10 @@ randomVector :: Int -- ^ seed | |||
35 | -> Vector Double | 40 | -> Vector Double |
36 | randomVector seed dist n = unsafePerformIO $ do | 41 | randomVector seed dist n = unsafePerformIO $ do |
37 | r <- createVector n | 42 | r <- createVector n |
38 | app1 (c_random_vector_GSL (fi seed) ((fi.fromEnum) dist)) vec r "randomVectorGSL" | 43 | app1 (c_random_vector (fi seed) ((fi.fromEnum) dist)) vec r "randomVector" |
39 | return r | 44 | return r |
40 | 45 | ||
41 | foreign import ccall unsafe "random_vector_GSL" c_random_vector_GSL :: CInt -> CInt -> TV | 46 | foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> TV |
42 | 47 | ||
43 | -------------------------------------------------------------------------------- | 48 | -------------------------------------------------------------------------------- |
44 | 49 | ||
@@ -105,3 +110,26 @@ type PD = Ptr Double -- | |||
105 | type TV = CInt -> PD -> IO CInt -- | 110 | type TV = CInt -> PD -> IO CInt -- |
106 | type TM = CInt -> CInt -> PD -> IO CInt -- | 111 | type TM = CInt -> CInt -> PD -> IO CInt -- |
107 | 112 | ||
113 | -------------------------------------------------------------------------------- | ||
114 | |||
115 | {- | obtains the number of rows and columns in an ASCII data file | ||
116 | (provisionally using unix's wc). | ||
117 | -} | ||
118 | fileDimensions :: FilePath -> IO (Int,Int) | ||
119 | fileDimensions fname = do | ||
120 | wcres <- readProcess "wc" ["-w",fname] "" | ||
121 | contents <- readFile fname | ||
122 | let tot = read . head . words $ wcres | ||
123 | c = length . head . dropWhile null . map words . lines $ contents | ||
124 | if tot > 0 | ||
125 | then return (tot `div` c, c) | ||
126 | else return (0,0) | ||
127 | |||
128 | -- | Loads a matrix from an ASCII file formatted as a 2D table. | ||
129 | loadMatrix :: FilePath -> IO (Matrix Double) | ||
130 | loadMatrix file = fromFile file =<< fileDimensions file | ||
131 | |||
132 | -- | Loads a matrix from an ASCII file (the number of rows and columns must be known in advance). | ||
133 | fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) | ||
134 | fromFile filename (r,c) = reshape c `fmap` fscanfVector filename (r*c) | ||
135 | |||
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra/Random.hs b/packages/hmatrix/src/Numeric/GSL/Random.hs index fa125a0..2872b17 100644 --- a/packages/hmatrix/src/Numeric/LinearAlgebra/Random.hs +++ b/packages/hmatrix/src/Numeric/GSL/Random.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- | | 2 | -- | |
3 | -- Module : Numeric.LinearAlgebra.Random | 3 | -- Module : Numeric.GSL.Random |
4 | -- Copyright : (c) Alberto Ruiz 2009-14 | 4 | -- Copyright : (c) Alberto Ruiz 2009-14 |
5 | -- License : GPL | 5 | -- License : GPL |
6 | -- | 6 | -- |
@@ -11,7 +11,7 @@ | |||
11 | -- | 11 | -- |
12 | ----------------------------------------------------------------------------- | 12 | ----------------------------------------------------------------------------- |
13 | 13 | ||
14 | module Numeric.LinearAlgebra.Random ( | 14 | module Numeric.GSL.Random ( |
15 | Seed, | 15 | Seed, |
16 | RandDist(..), | 16 | RandDist(..), |
17 | randomVector, | 17 | randomVector, |
@@ -20,9 +20,9 @@ module Numeric.LinearAlgebra.Random ( | |||
20 | rand, randn | 20 | rand, randn |
21 | ) where | 21 | ) where |
22 | 22 | ||
23 | import Numeric.GSL.LinearAlgebra | 23 | import Numeric.GSL.Vector |
24 | import Data.Packed.Numeric | 24 | import Numeric.Container |
25 | import Numeric.LinearAlgebra.Base(Seed,RandDist(..),cholSH) | 25 | import Numeric.LinearAlgebra(Seed,RandDist(..),cholSH) |
26 | import System.Random(randomIO) | 26 | import System.Random(randomIO) |
27 | 27 | ||
28 | 28 | ||
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra/GSL.hs b/packages/hmatrix/src/Numeric/GSL/Vector.hs index 1fde621..af79f32 100644 --- a/packages/hmatrix/src/Numeric/LinearAlgebra/GSL.hs +++ b/packages/hmatrix/src/Numeric/GSL/Vector.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- | | 2 | -- | |
3 | -- Module : Numeric.LinearAlgebra.GSL | 3 | -- Module : Numeric.GSL.Vector |
4 | -- Copyright : (c) Alberto Ruiz 2007-14 | 4 | -- Copyright : (c) Alberto Ruiz 2007-14 |
5 | -- License : GPL | 5 | -- License : GPL |
6 | -- Maintainer : Alberto Ruiz | 6 | -- Maintainer : Alberto Ruiz |
@@ -8,32 +8,26 @@ | |||
8 | -- | 8 | -- |
9 | ----------------------------------------------------------------------------- | 9 | ----------------------------------------------------------------------------- |
10 | 10 | ||
11 | module Numeric.LinearAlgebra.GSL ( | 11 | module Numeric.GSL.Vector ( |
12 | RandDist(..), randomVector, | 12 | randomVector, |
13 | saveMatrix, | 13 | saveMatrix, |
14 | fwriteVector, freadVector, fprintfVector, fscanfVector, | 14 | fwriteVector, freadVector, fprintfVector, fscanfVector |
15 | fileDimensions, loadMatrix, fromFile | ||
16 | ) where | 15 | ) where |
17 | 16 | ||
18 | import Data.Packed | 17 | import Data.Packed |
18 | import Numeric.LinearAlgebra(RandDist(..)) | ||
19 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) | 19 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) |
20 | 20 | ||
21 | import Data.Complex | ||
22 | import Foreign.Marshal.Alloc(free) | 21 | import Foreign.Marshal.Alloc(free) |
23 | import Foreign.Ptr(Ptr) | 22 | import Foreign.Ptr(Ptr) |
24 | import Foreign.C.Types | 23 | import Foreign.C.Types |
25 | import Foreign.C.String(newCString) | 24 | import Foreign.C.String(newCString) |
26 | import System.IO.Unsafe(unsafePerformIO) | 25 | import System.IO.Unsafe(unsafePerformIO) |
27 | import System.Process(readProcess) | ||
28 | 26 | ||
29 | fromei x = fromIntegral (fromEnum x) :: CInt | 27 | fromei x = fromIntegral (fromEnum x) :: CInt |
30 | 28 | ||
31 | ----------------------------------------------------------------------- | 29 | ----------------------------------------------------------------------- |
32 | 30 | ||
33 | data RandDist = Uniform -- ^ uniform distribution in [0,1) | ||
34 | | Gaussian -- ^ normal distribution with mean zero and standard deviation one | ||
35 | deriving Enum | ||
36 | |||
37 | -- | 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. |
38 | randomVector :: Int -- ^ seed | 32 | randomVector :: Int -- ^ seed |
39 | -> RandDist -- ^ distribution | 33 | -> RandDist -- ^ distribution |
@@ -41,10 +35,10 @@ randomVector :: Int -- ^ seed | |||
41 | -> Vector Double | 35 | -> Vector Double |
42 | randomVector seed dist n = unsafePerformIO $ do | 36 | randomVector seed dist n = unsafePerformIO $ do |
43 | r <- createVector n | 37 | r <- createVector n |
44 | 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" |
45 | return r | 39 | return r |
46 | 40 | ||
47 | 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 |
48 | 42 | ||
49 | -------------------------------------------------------------------------------- | 43 | -------------------------------------------------------------------------------- |
50 | 44 | ||
@@ -111,26 +105,3 @@ type PD = Ptr Double -- | |||
111 | type TV = CInt -> PD -> IO CInt -- | 105 | type TV = CInt -> PD -> IO CInt -- |
112 | type TM = CInt -> CInt -> PD -> IO CInt -- | 106 | type TM = CInt -> CInt -> PD -> IO CInt -- |
113 | 107 | ||
114 | -------------------------------------------------------------------------------- | ||
115 | |||
116 | {- | obtains the number of rows and columns in an ASCII data file | ||
117 | (provisionally using unix's wc). | ||
118 | -} | ||
119 | fileDimensions :: FilePath -> IO (Int,Int) | ||
120 | fileDimensions fname = do | ||
121 | wcres <- readProcess "wc" ["-w",fname] "" | ||
122 | contents <- readFile fname | ||
123 | let tot = read . head . words $ wcres | ||
124 | c = length . head . dropWhile null . map words . lines $ contents | ||
125 | if tot > 0 | ||
126 | then return (tot `div` c, c) | ||
127 | else return (0,0) | ||
128 | |||
129 | -- | Loads a matrix from an ASCII file formatted as a 2D table. | ||
130 | loadMatrix :: FilePath -> IO (Matrix Double) | ||
131 | loadMatrix file = fromFile file =<< fileDimensions file | ||
132 | |||
133 | -- | Loads a matrix from an ASCII file (the number of rows and columns must be known in advance). | ||
134 | fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) | ||
135 | fromFile filename (r,c) = reshape c `fmap` fscanfVector filename (r*c) | ||
136 | |||
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra.hs b/packages/hmatrix/src/Numeric/LinearAlgebra.hs deleted file mode 100644 index 71ed808..0000000 --- a/packages/hmatrix/src/Numeric/LinearAlgebra.hs +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | {- | | ||
3 | Module : Numeric.LinearAlgebra | ||
4 | Copyright : (c) Alberto Ruiz 2006-14 | ||
5 | License : GPL | ||
6 | Maintainer : Alberto Ruiz | ||
7 | Stability : provisional | ||
8 | |||
9 | -} | ||
10 | ----------------------------------------------------------------------------- | ||
11 | |||
12 | module Numeric.LinearAlgebra ( | ||
13 | module Numeric.Container, | ||
14 | module Numeric.LinearAlgebra.Algorithms, | ||
15 | ) where | ||
16 | |||
17 | import Numeric.Container | ||
18 | import Numeric.LinearAlgebra.Algorithms | ||
19 | import Numeric.LinearAlgebra.Util() | ||
20 | |||