summaryrefslogtreecommitdiff
path: root/packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs
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 /packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs
parent5d15d765c0204854b587b03232b20336ddf91ced (diff)
container and algorithms moved to base
Diffstat (limited to 'packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs')
-rw-r--r--packages/hmatrix/src/Numeric/LinearAlgebra/Util.hs24
1 files changed, 23 insertions, 1 deletions
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)