summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-05-16 12:36:52 +0200
committerAlberto Ruiz <aruiz@um.es>2014-05-16 12:36:52 +0200
commita2d99e7d0e83fcedf3a856cdb927309e28a8eddd (patch)
treec6192d21e4b59e5527aac5d25d8b8baefc2b3052
parent5d15d765c0204854b587b03232b20336ddf91ced (diff)
container and algorithms moved to base
-rw-r--r--packages/base/hmatrix-base.cabal2
-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.cabal4
-rw-r--r--packages/hmatrix/src/Numeric/HMatrix/Data.hs1
-rw-r--r--packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs24
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
67import Data.Packed hiding (stepD, stepF, condD, condF, conjugateC, conjugateQ) 56import Data.Packed hiding (stepD, stepF, condD, condF, conjugateC, conjugateQ)
68import Data.Packed.Numeric 57import Data.Packed.Numeric
69import Numeric.IO
70import Data.Complex 58import Data.Complex
71import Numeric.LinearAlgebra.Algorithms(Field,linearSolveSVD) 59import Numeric.LinearAlgebra.Algorithms(Field,linearSolveSVD)
72import Numeric.Random
73import Data.Monoid(Monoid(mconcat)) 60import 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-}
247meanCov :: Matrix Double -> (Vector Double, Matrix Double)
248meanCov 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
260x25c7, white diamond 227x25c7, 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
27module Numeric.LinearAlgebra.Algorithms ( 25module 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
19build-type: Simple 19build-type: Simple
20 20
21extra-source-files: Config.hs THANKS.md INSTALL.md CHANGELOG 21extra-source-files: THANKS.md INSTALL.md CHANGELOG
22 22
23extra-source-files: examples/deriv.hs 23extra-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(
64import Data.Packed.Vector 64import Data.Packed.Vector
65import Data.Packed.Matrix 65import Data.Packed.Matrix
66import Numeric.Container 66import Numeric.Container
67import Numeric.IO
67import Numeric.LinearAlgebra.Util 68import Numeric.LinearAlgebra.Util
68import Data.Complex 69import 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
57import Numeric.Container 58import Numeric.Container
59import Numeric.IO
58import Numeric.LinearAlgebra.Algorithms hiding (i) 60import Numeric.LinearAlgebra.Algorithms hiding (i)
59import Numeric.Matrix() 61import Numeric.Matrix()
60import Numeric.Vector() 62import Numeric.Vector()
@@ -196,7 +198,27 @@ size m = (rows m, cols m)
196mt :: Matrix Double -> Matrix Double 198mt :: Matrix Double -> Matrix Double
197mt = trans . inv 199mt = 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-}
212meanCov :: Matrix Double -> (Vector Double, Matrix Double)
213meanCov 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)