diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-04-10 09:59:43 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-04-10 09:59:43 +0200 |
commit | fde36f1224d4b87a32019bd9519d0aba4315792b (patch) | |
tree | 77f76e91ffdad43f4050e97e9fd8f9eab62b2a77 /packages | |
parent | 4dc1ef825642ef4ecf86095c08b933cffe59f855 (diff) |
conj trans in right singular vectors fo complex matrices, adapt pinvTol and nullspaceSVD
Diffstat (limited to 'packages')
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Algorithms.hs | 13 | ||||
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/LAPACK.hs | 6 |
2 files changed, 12 insertions, 7 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs b/packages/base/src/Numeric/LinearAlgebra/Algorithms.hs index a113d48..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'. |
diff --git a/packages/base/src/Numeric/LinearAlgebra/LAPACK.hs b/packages/base/src/Numeric/LinearAlgebra/LAPACK.hs index e088fdc..d96e14f 100644 --- a/packages/base/src/Numeric/LinearAlgebra/LAPACK.hs +++ b/packages/base/src/Numeric/LinearAlgebra/LAPACK.hs | |||
@@ -115,7 +115,7 @@ svdAux f st x = unsafePerformIO $ do | |||
115 | s <- createVector (min r c) | 115 | s <- createVector (min r c) |
116 | v <- createMatrix ColumnMajor c c | 116 | v <- createMatrix ColumnMajor c c |
117 | app4 f mat x mat u vec s mat v st | 117 | app4 f mat x mat u vec s mat v st |
118 | return (u,s,trans v) | 118 | return (u,s,v) |
119 | where r = rows x | 119 | where r = rows x |
120 | c = cols x | 120 | c = cols x |
121 | 121 | ||
@@ -141,7 +141,7 @@ thinSVDAux f st x = unsafePerformIO $ do | |||
141 | s <- createVector q | 141 | s <- createVector q |
142 | v <- createMatrix ColumnMajor q c | 142 | v <- createMatrix ColumnMajor q c |
143 | app4 f mat x mat u vec s mat v st | 143 | app4 f mat x mat u vec s mat v st |
144 | return (u,s,trans v) | 144 | return (u,s,v) |
145 | where r = rows x | 145 | where r = rows x |
146 | c = cols x | 146 | c = cols x |
147 | q = min r c | 147 | q = min r c |
@@ -185,7 +185,7 @@ rightSVAux f st x = unsafePerformIO $ do | |||
185 | s <- createVector q | 185 | s <- createVector q |
186 | v <- createMatrix ColumnMajor c c | 186 | v <- createMatrix ColumnMajor c c |
187 | app3 g mat x vec s mat v st | 187 | app3 g mat x vec s mat v st |
188 | return (s,trans v) | 188 | return (s,v) |
189 | where r = rows x | 189 | where r = rows x |
190 | c = cols x | 190 | c = cols x |
191 | q = min r c | 191 | q = min r c |