diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/base/hmatrix-base.cabal | 2 | ||||
-rw-r--r-- | packages/base/src/Numeric/Container.hs (renamed from packages/hmatrix/src/Numeric/Container.hs) | 35 | ||||
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Algorithms.hs (renamed from packages/hmatrix/src/Numeric/LinearAlgebra/Algorithms.hs) | 2 | ||||
-rw-r--r-- | packages/hmatrix/hmatrix.cabal | 4 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/HMatrix/Data.hs | 1 | ||||
-rw-r--r-- | packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs | 24 |
6 files changed, 28 insertions, 40 deletions
diff --git a/packages/base/hmatrix-base.cabal b/packages/base/hmatrix-base.cabal index 8eeb97e..9a84b7e 100644 --- a/packages/base/hmatrix-base.cabal +++ b/packages/base/hmatrix-base.cabal | |||
@@ -37,10 +37,12 @@ library | |||
37 | Data.Packed.Development, | 37 | Data.Packed.Development, |
38 | Numeric.Conversion | 38 | Numeric.Conversion |
39 | Numeric.LinearAlgebra.LAPACK | 39 | Numeric.LinearAlgebra.LAPACK |
40 | Numeric.LinearAlgebra.Algorithms | ||
40 | Data.Packed.Numeric | 41 | Data.Packed.Numeric |
41 | Numeric.Vectorized | 42 | Numeric.Vectorized |
42 | Numeric.Vector | 43 | Numeric.Vector |
43 | Numeric.Matrix | 44 | Numeric.Matrix |
45 | Numeric.Container | ||
44 | 46 | ||
45 | other-modules: Data.Packed.Internal, | 47 | other-modules: Data.Packed.Internal, |
46 | Data.Packed.Internal.Common, | 48 | Data.Packed.Internal.Common, |
diff --git a/packages/hmatrix/src/Numeric/Container.hs b/packages/base/src/Numeric/Container.hs index e7f23d4..b7d3b80 100644 --- a/packages/hmatrix/src/Numeric/Container.hs +++ b/packages/base/src/Numeric/Container.hs | |||
@@ -42,12 +42,6 @@ module Numeric.Container ( | |||
42 | optimiseMult, | 42 | optimiseMult, |
43 | mXm,mXv,vXm,LSDiv(..), | 43 | mXm,mXv,vXm,LSDiv(..), |
44 | outer, kronecker, | 44 | outer, kronecker, |
45 | -- * Random numbers | ||
46 | RandDist(..), | ||
47 | randomVector, | ||
48 | gaussianSample, | ||
49 | uniformSample, | ||
50 | meanCov, | ||
51 | -- * Element conversion | 45 | -- * Element conversion |
52 | Convert(..), | 46 | Convert(..), |
53 | Complexable(), | 47 | Complexable(), |
@@ -56,20 +50,13 @@ module Numeric.Container ( | |||
56 | RealOf, ComplexOf, SingleOf, DoubleOf, | 50 | RealOf, ComplexOf, SingleOf, DoubleOf, |
57 | 51 | ||
58 | IndexOf, | 52 | IndexOf, |
59 | module Data.Complex, | 53 | module Data.Complex |
60 | -- * IO | ||
61 | dispf, disps, dispcf, vecdisp, latexFormat, format, | ||
62 | loadMatrix, saveMatrix, fromFile, fileDimensions, | ||
63 | readMatrix, | ||
64 | fscanfVector, fprintfVector, freadVector, fwriteVector, | ||
65 | ) where | 54 | ) where |
66 | 55 | ||
67 | import Data.Packed hiding (stepD, stepF, condD, condF, conjugateC, conjugateQ) | 56 | import Data.Packed hiding (stepD, stepF, condD, condF, conjugateC, conjugateQ) |
68 | import Data.Packed.Numeric | 57 | import Data.Packed.Numeric |
69 | import Numeric.IO | ||
70 | import Data.Complex | 58 | import Data.Complex |
71 | import Numeric.LinearAlgebra.Algorithms(Field,linearSolveSVD) | 59 | import Numeric.LinearAlgebra.Algorithms(Field,linearSolveSVD) |
72 | import Numeric.Random | ||
73 | import Data.Monoid(Monoid(mconcat)) | 60 | import Data.Monoid(Monoid(mconcat)) |
74 | 61 | ||
75 | ------------------------------------------------------------------ | 62 | ------------------------------------------------------------------ |
@@ -235,26 +222,6 @@ instance Container Matrix e => Build (Int,Int) (e -> e -> e) Matrix e | |||
235 | 222 | ||
236 | -------------------------------------------------------------------------------- | 223 | -------------------------------------------------------------------------------- |
237 | 224 | ||
238 | {- | Compute mean vector and covariance matrix of the rows of a matrix. | ||
239 | |||
240 | >>> meanCov $ gaussianSample 666 1000 (fromList[4,5]) (diagl[2,3]) | ||
241 | (fromList [4.010341078059521,5.0197204699640405], | ||
242 | (2><2) | ||
243 | [ 1.9862461923890056, -1.0127225830525157e-2 | ||
244 | , -1.0127225830525157e-2, 3.0373954915729318 ]) | ||
245 | |||
246 | -} | ||
247 | meanCov :: Matrix Double -> (Vector Double, Matrix Double) | ||
248 | meanCov x = (med,cov) where | ||
249 | r = rows x | ||
250 | k = 1 / fromIntegral r | ||
251 | med = konst k r `vXm` x | ||
252 | meds = konst 1 r `outer` med | ||
253 | xc = x `sub` meds | ||
254 | cov = scale (recip (fromIntegral (r-1))) (trans xc `mXm` xc) | ||
255 | |||
256 | -------------------------------------------------------------------------------- | ||
257 | |||
258 | {- | alternative operator for '(\<.\>)' | 225 | {- | alternative operator for '(\<.\>)' |
259 | 226 | ||
260 | x25c7, white diamond | 227 | x25c7, white diamond |
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra/Algorithms.hs b/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs index b4d0c5b..6f40683 100644 --- a/packages/hmatrix/src/Numeric/LinearAlgebra/Algorithms.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs | |||
@@ -21,8 +21,6 @@ imported from "Numeric.LinearAlgebra.LAPACK". | |||
21 | 21 | ||
22 | -} | 22 | -} |
23 | ----------------------------------------------------------------------------- | 23 | ----------------------------------------------------------------------------- |
24 | {-# OPTIONS_HADDOCK hide #-} | ||
25 | |||
26 | 24 | ||
27 | module Numeric.LinearAlgebra.Algorithms ( | 25 | module Numeric.LinearAlgebra.Algorithms ( |
28 | -- * Supported types | 26 | -- * Supported types |
diff --git a/packages/hmatrix/hmatrix.cabal b/packages/hmatrix/hmatrix.cabal index 369c412..9719c96 100644 --- a/packages/hmatrix/hmatrix.cabal +++ b/packages/hmatrix/hmatrix.cabal | |||
@@ -18,7 +18,7 @@ cabal-version: >=1.8 | |||
18 | 18 | ||
19 | build-type: Simple | 19 | build-type: Simple |
20 | 20 | ||
21 | extra-source-files: Config.hs THANKS.md INSTALL.md CHANGELOG | 21 | extra-source-files: THANKS.md INSTALL.md CHANGELOG |
22 | 22 | ||
23 | extra-source-files: examples/deriv.hs | 23 | extra-source-files: examples/deriv.hs |
24 | examples/integrate.hs | 24 | examples/integrate.hs |
@@ -90,9 +90,7 @@ 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.Container, | ||
94 | Numeric.LinearAlgebra, | 93 | Numeric.LinearAlgebra, |
95 | Numeric.LinearAlgebra.Algorithms, | ||
96 | Numeric.LinearAlgebra.Util, | 94 | Numeric.LinearAlgebra.Util, |
97 | Graphics.Plot, | 95 | Graphics.Plot, |
98 | Numeric.HMatrix, | 96 | Numeric.HMatrix, |
diff --git a/packages/hmatrix/src/Numeric/HMatrix/Data.hs b/packages/hmatrix/src/Numeric/HMatrix/Data.hs index 568dc05..5d7ce4f 100644 --- a/packages/hmatrix/src/Numeric/HMatrix/Data.hs +++ b/packages/hmatrix/src/Numeric/HMatrix/Data.hs | |||
@@ -64,6 +64,7 @@ module Numeric.HMatrix.Data( | |||
64 | import Data.Packed.Vector | 64 | import Data.Packed.Vector |
65 | import Data.Packed.Matrix | 65 | import Data.Packed.Matrix |
66 | import Numeric.Container | 66 | import Numeric.Container |
67 | import Numeric.IO | ||
67 | import Numeric.LinearAlgebra.Util | 68 | import Numeric.LinearAlgebra.Util |
68 | import Data.Complex | 69 | import Data.Complex |
69 | 70 | ||
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs b/packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs index fb2d54c..e4f21b0 100644 --- a/packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs +++ b/packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs | |||
@@ -27,6 +27,7 @@ module Numeric.LinearAlgebra.Util( | |||
27 | unitary, | 27 | unitary, |
28 | mt, | 28 | mt, |
29 | pairwiseD2, | 29 | pairwiseD2, |
30 | meanCov, | ||
30 | rowOuters, | 31 | rowOuters, |
31 | null1, | 32 | null1, |
32 | null1sym, | 33 | null1sym, |
@@ -55,6 +56,7 @@ module Numeric.LinearAlgebra.Util( | |||
55 | ) where | 56 | ) where |
56 | 57 | ||
57 | import Numeric.Container | 58 | import Numeric.Container |
59 | import Numeric.IO | ||
58 | import Numeric.LinearAlgebra.Algorithms hiding (i) | 60 | import Numeric.LinearAlgebra.Algorithms hiding (i) |
59 | import Numeric.Matrix() | 61 | import Numeric.Matrix() |
60 | import Numeric.Vector() | 62 | import Numeric.Vector() |
@@ -196,7 +198,27 @@ size m = (rows m, cols m) | |||
196 | mt :: Matrix Double -> Matrix Double | 198 | mt :: Matrix Double -> Matrix Double |
197 | mt = trans . inv | 199 | mt = trans . inv |
198 | 200 | ||
199 | ---------------------------------------------------------------------- | 201 | -------------------------------------------------------------------------------- |
202 | |||
203 | {- | Compute mean vector and covariance matrix of the rows of a matrix. | ||
204 | |||
205 | >>> meanCov $ gaussianSample 666 1000 (fromList[4,5]) (diagl[2,3]) | ||
206 | (fromList [4.010341078059521,5.0197204699640405], | ||
207 | (2><2) | ||
208 | [ 1.9862461923890056, -1.0127225830525157e-2 | ||
209 | , -1.0127225830525157e-2, 3.0373954915729318 ]) | ||
210 | |||
211 | -} | ||
212 | meanCov :: Matrix Double -> (Vector Double, Matrix Double) | ||
213 | meanCov x = (med,cov) where | ||
214 | r = rows x | ||
215 | k = 1 / fromIntegral r | ||
216 | med = konst k r `vXm` x | ||
217 | meds = konst 1 r `outer` med | ||
218 | xc = x `sub` meds | ||
219 | cov = scale (recip (fromIntegral (r-1))) (trans xc `mXm` xc) | ||
220 | |||
221 | -------------------------------------------------------------------------------- | ||
200 | 222 | ||
201 | -- | Matrix of pairwise squared distances of row vectors | 223 | -- | Matrix of pairwise squared distances of row vectors |
202 | -- (using the matrix product trick in blog.smola.org) | 224 | -- (using the matrix product trick in blog.smola.org) |