summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Algorithms.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Algorithms.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs23
1 files changed, 13 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