summaryrefslogtreecommitdiff
path: root/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Numeric/LinearAlgebra/Algorithms.hs')
-rw-r--r--packages/base/src/Numeric/LinearAlgebra/Algorithms.hs26
1 files changed, 22 insertions, 4 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs b/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs
index 7e36978..fd9177c 100644
--- a/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs
+++ b/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs
@@ -64,6 +64,7 @@ module Numeric.LinearAlgebra.Algorithms (
64 nullspacePrec, 64 nullspacePrec,
65 nullVector, 65 nullVector,
66 nullspaceSVD, 66 nullspaceSVD,
67 orthSVD,
67 orth, 68 orth,
68-- * Norms 69-- * Norms
69 Normed(..), NormType(..), 70 Normed(..), NormType(..),
@@ -463,7 +464,7 @@ nullspaceSVD :: Field t
463 -- or Right \"theoretical\" matrix rank. 464 -- or Right \"theoretical\" matrix rank.
464 -> Matrix t -- ^ input matrix m 465 -> Matrix t -- ^ input matrix m
465 -> (Vector Double, Matrix t) -- ^ 'rightSV' of m 466 -> (Vector Double, Matrix t) -- ^ 'rightSV' of m
466 -> [Vector t] -- ^ list of unitary vectors spanning the nullspace 467 -> Matrix t -- ^ nullspace
467nullspaceSVD hint a (s,v) = vs where 468nullspaceSVD hint a (s,v) = vs where
468 tol = case hint of 469 tol = case hint of
469 Left t -> t 470 Left t -> t
@@ -471,7 +472,7 @@ nullspaceSVD hint a (s,v) = vs where
471 k = case hint of 472 k = case hint of
472 Right t -> t 473 Right t -> t
473 _ -> rankSVD tol a s 474 _ -> rankSVD tol a s
474 vs = drop k $ toRows $ ctrans v 475 vs = dropColumns k v
475 476
476 477
477-- | The nullspace of a matrix. See also 'nullspaceSVD'. 478-- | The nullspace of a matrix. See also 'nullspaceSVD'.
@@ -479,12 +480,29 @@ nullspacePrec :: Field t
479 => Double -- ^ relative tolerance in 'eps' units (e.g., use 3 to get 3*'eps') 480 => Double -- ^ relative tolerance in 'eps' units (e.g., use 3 to get 3*'eps')
480 -> Matrix t -- ^ input matrix 481 -> Matrix t -- ^ input matrix
481 -> [Vector t] -- ^ list of unitary vectors spanning the nullspace 482 -> [Vector t] -- ^ list of unitary vectors spanning the nullspace
482nullspacePrec t m = nullspaceSVD (Left (t*eps)) m (rightSV m) 483nullspacePrec t m = toColumns $ nullspaceSVD (Left (t*eps)) m (rightSV m)
483 484
484-- | The nullspace of a matrix, assumed to be one-dimensional, with machine precision. 485-- | The nullspace of a matrix, assumed to be one-dimensional, with machine precision.
485nullVector :: Field t => Matrix t -> Vector t 486nullVector :: Field t => Matrix t -> Vector t
486nullVector = last . nullspacePrec 1 487nullVector = last . nullspacePrec 1
487 488
489-- | The range space a matrix from its precomputed SVD decomposition.
490orthSVD :: Field t
491 => Either Double Int -- ^ Left \"numeric\" zero (eg. 1*'eps'),
492 -- or Right \"theoretical\" matrix rank.
493 -> Matrix t -- ^ input matrix m
494 -> (Matrix t, Vector Double) -- ^ 'leftSV' of m
495 -> Matrix t -- ^ orth
496orthSVD hint a (v,s) = vs where
497 tol = case hint of
498 Left t -> t
499 _ -> eps
500 k = case hint of
501 Right t -> t
502 _ -> rankSVD tol a s
503 vs = takeColumns k v
504
505
488orth :: Field t => Matrix t -> [Vector t] 506orth :: Field t => Matrix t -> [Vector t]
489-- ^ Return an orthonormal basis of the range space of a matrix 507-- ^ Return an orthonormal basis of the range space of a matrix
490orth m = take r $ toColumns u 508orth m = take r $ toColumns u
@@ -541,7 +559,7 @@ rcond :: Field t => Matrix t -> Double
541rcond m = last s / head s 559rcond m = last s / head s
542 where s = toList (singularValues m) 560 where s = toList (singularValues m)
543 561
544-- | Number of linearly independent rows or columns. 562-- | Number of linearly independent rows or columns. See also 'ranksv'
545rank :: Field t => Matrix t -> Int 563rank :: Field t => Matrix t -> Int
546rank m = rankSVD eps m (singularValues m) 564rank m = rankSVD eps m (singularValues m)
547 565