diff options
Diffstat (limited to 'packages/base/src/Numeric/LinearAlgebra/Algorithms.hs')
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Algorithms.hs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs b/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs index 02ac6a0..0e085c1 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs | |||
@@ -228,7 +228,9 @@ fromList [35.18264833189422,1.4769076999800903,1.089145439970417e-15] | |||
228 | 228 | ||
229 | -} | 229 | -} |
230 | svd :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) | 230 | svd :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) |
231 | svd = {-# SCC "svd" #-} svd' | 231 | svd = {-# SCC "svd" #-} g . svd' |
232 | where | ||
233 | g (u,s,v) = (u,s,tr v) | ||
232 | 234 | ||
233 | {- | A version of 'svd' which returns only the @min (rows m) (cols m)@ singular vectors of @m@. | 235 | {- | A version of 'svd' which returns only the @min (rows m) (cols m)@ singular vectors of @m@. |
234 | 236 | ||
@@ -272,7 +274,10 @@ fromList [35.18264833189422,1.4769076999800903,1.089145439970417e-15] | |||
272 | 274 | ||
273 | -} | 275 | -} |
274 | thinSVD :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) | 276 | thinSVD :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) |
275 | thinSVD = {-# SCC "thinSVD" #-} thinSVD' | 277 | thinSVD = {-# SCC "thinSVD" #-} g . thinSVD' |
278 | where | ||
279 | g (u,s,v) = (u,s,tr v) | ||
280 | |||
276 | 281 | ||
277 | -- | Singular values only. | 282 | -- | Singular values only. |
278 | singularValues :: Field t => Matrix t -> Vector Double | 283 | singularValues :: Field t => Matrix t -> Vector Double |
@@ -587,7 +592,7 @@ m = (3><3) [ 1, 0, 0 | |||
587 | -} | 592 | -} |
588 | 593 | ||
589 | pinvTol :: Field t => Double -> Matrix t -> Matrix t | 594 | pinvTol :: Field t => Double -> Matrix t -> Matrix t |
590 | pinvTol t m = conj v' `mXm` diag s' `mXm` ctrans u' where | 595 | pinvTol t m = v' `mXm` diag s' `mXm` ctrans u' where |
591 | (u,s,v) = thinSVD m | 596 | (u,s,v) = thinSVD m |
592 | sl@(g:_) = toList s | 597 | sl@(g:_) = toList s |
593 | s' = real . fromList . map rec $ sl | 598 | s' = real . fromList . map rec $ sl |
@@ -649,7 +654,7 @@ nullspaceSVD hint a (s,v) = vs where | |||
649 | k = case hint of | 654 | k = case hint of |
650 | Right t -> t | 655 | Right t -> t |
651 | _ -> rankSVD tol a s | 656 | _ -> rankSVD tol a s |
652 | vs = conj (dropColumns k v) | 657 | vs = dropColumns k v |
653 | 658 | ||
654 | 659 | ||
655 | -- | The nullspace of a matrix. See also 'nullspaceSVD'. | 660 | -- | The nullspace of a matrix. See also 'nullspaceSVD'. |
@@ -935,10 +940,9 @@ relativeError' x y = dig (norm (x `sub` y) / norm x) | |||
935 | dig r = round $ -logBase 10 (realToFrac r :: Double) | 940 | dig r = round $ -logBase 10 (realToFrac r :: Double) |
936 | 941 | ||
937 | 942 | ||
938 | relativeError :: (Normed c t, Num (c t)) => NormType -> c t -> c t -> Double | 943 | relativeError :: Num a => (a -> Double) -> a -> a -> Double |
939 | relativeError t a b = realToFrac r | 944 | relativeError norm a b = r |
940 | where | 945 | where |
941 | norm = pnorm t | ||
942 | na = norm a | 946 | na = norm a |
943 | nb = norm b | 947 | nb = norm b |
944 | nab = norm (a-b) | 948 | nab = norm (a-b) |