summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-12-12 12:39:23 +0000
committerAlberto Ruiz <aruiz@um.es>2009-12-12 12:39:23 +0000
commited8f45f7316569bfeacdd2848017d93c5cfdd261 (patch)
tree1ba3a66170514a56be756772e744b7ce5ff5a30c /lib/Numeric/LinearAlgebra
parentc1464d95f0eb03c0fbb728f5cc49c6548b23ef10 (diff)
ranksv and tests
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs23
-rw-r--r--lib/Numeric/LinearAlgebra/Tests.hs5
2 files changed, 18 insertions, 10 deletions
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index f749cc1..954b214 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -63,7 +63,7 @@ module Numeric.LinearAlgebra.Algorithms (
63 haussholder, 63 haussholder,
64 unpackQR, unpackHess, 64 unpackQR, unpackHess,
65 pinvTol, 65 pinvTol,
66 rankSVD, 66 rankSVD, ranksv,
67 nullspaceSVD 67 nullspaceSVD
68) where 68) where
69 69
@@ -262,15 +262,18 @@ rankSVD :: Element t
262 -> Matrix t -- ^ input matrix m 262 -> Matrix t -- ^ input matrix m
263 -> (Matrix t, Vector Double, Matrix t) -- ^ 'svd' of m 263 -> (Matrix t, Vector Double, Matrix t) -- ^ 'svd' of m
264 -> Int -- ^ rank of m 264 -> Int -- ^ rank of m
265rankSVD teps m (_,s,_) = k where 265rankSVD teps m (_,s,_) = ranksv teps (max (rows m) (cols m)) (toList s)
266 sl@(g:_) = toList s 266
267 r = rows m 267-- | Numeric rank of a matrix from its singular values.
268 c = cols m 268ranksv :: Double -- ^ numeric zero (e.g. 1*'eps')
269 tol = fromIntegral (max r c) * g * teps 269 -> Int -- ^ maximum dimension of the matrix
270 s' = fromList . filter (>tol) $ sl 270 -> [Double] -- ^ singular values
271 k = if g > teps 271 -> Int -- ^ rank of m
272 then dim s' 272ranksv teps maxdim s = k where
273 else 0 273 g = maximum s
274 tol = fromIntegral maxdim * g * teps
275 s' = filter (>tol) s
276 k = if g > teps then length s' else 0
274 277
275-- | The machine precision of a Double: @eps = 2.22044604925031e-16@ (the value used by GNU-Octave). 278-- | The machine precision of a Double: @eps = 2.22044604925031e-16@ (the value used by GNU-Octave).
276eps :: Double 279eps :: Double
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs
index 4495396..bf29ee9 100644
--- a/lib/Numeric/LinearAlgebra/Tests.hs
+++ b/lib/Numeric/LinearAlgebra/Tests.hs
@@ -243,6 +243,11 @@ runTests n = do
243 , rootFindingTest 243 , rootFindingTest
244 , utest "randomGaussian" randomTestGaussian 244 , utest "randomGaussian" randomTestGaussian
245 , utest "randomUniform" randomTestUniform 245 , utest "randomUniform" randomTestUniform
246 , utest "buildVector/Matrix" $
247 comp (10 |> [0::Double ..]) == buildVector 10 fromIntegral
248 && ident 5 == buildMatrix 5 5 (\(r,c) -> if r==c then 1::Double else 0)
249 , utest "rank" $ rank ((2><3)[1,0,0,1,6*eps,0]) == 1
250 && rank ((2><3)[1,0,0,1,7*eps,0]) == 2
246 ] 251 ]
247 return () 252 return ()
248 253