diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-06-07 11:44:13 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-06-07 11:44:13 +0200 |
commit | 907d69558f8819a44b552e820750f99340f1f107 (patch) | |
tree | f825b16bf85ae4496b0eaca94ed239f2845c466d /packages/base/src/Numeric/HMatrix.hs | |
parent | 2e07762524d0d08fbc2e565529d480dc7fa479b5 (diff) |
documentation
Diffstat (limited to 'packages/base/src/Numeric/HMatrix.hs')
-rw-r--r-- | packages/base/src/Numeric/HMatrix.hs | 83 |
1 files changed, 58 insertions, 25 deletions
diff --git a/packages/base/src/Numeric/HMatrix.hs b/packages/base/src/Numeric/HMatrix.hs index 9d34658..ec96bfc 100644 --- a/packages/base/src/Numeric/HMatrix.hs +++ b/packages/base/src/Numeric/HMatrix.hs | |||
@@ -17,10 +17,10 @@ module Numeric.HMatrix ( | |||
17 | -- | | 17 | -- | |
18 | -- The standard numeric classes are defined elementwise: | 18 | -- The standard numeric classes are defined elementwise: |
19 | -- | 19 | -- |
20 | -- >>> fromList [1,2,3] * fromList [3,0,-2 :: Double] | 20 | -- >>> vect [1,2,3] * vect [3,0,-2] |
21 | -- fromList [3.0,0.0,-6.0] | 21 | -- fromList [3.0,0.0,-6.0] |
22 | -- | 22 | -- |
23 | -- >>> (3><3) [1..9] * ident 3 :: Matrix Double | 23 | -- >>> mat 3 [1..9] * ident 3 |
24 | -- (3><3) | 24 | -- (3><3) |
25 | -- [ 1.0, 0.0, 0.0 | 25 | -- [ 1.0, 0.0, 0.0 |
26 | -- , 0.0, 5.0, 0.0 | 26 | -- , 0.0, 5.0, 0.0 |
@@ -36,6 +36,12 @@ module Numeric.HMatrix ( | |||
36 | -- , 5.0, 7.0, 5.0 | 36 | -- , 5.0, 7.0, 5.0 |
37 | -- , 5.0, 5.0, 7.0 ] | 37 | -- , 5.0, 5.0, 7.0 ] |
38 | -- | 38 | -- |
39 | -- >>> mat 3 [1..9] + mat 1 [10,20,30] | ||
40 | -- (3><3) | ||
41 | -- [ 11.0, 12.0, 13.0 | ||
42 | -- , 24.0, 25.0, 26.0 | ||
43 | -- , 37.0, 38.0, 39.0 ] | ||
44 | -- | ||
39 | 45 | ||
40 | -- * Products | 46 | -- * Products |
41 | -- ** dot | 47 | -- ** dot |
@@ -48,11 +54,12 @@ module Numeric.HMatrix ( | |||
48 | -- single-element matrices (created from numeric literals or using 'scalar') | 54 | -- single-element matrices (created from numeric literals or using 'scalar') |
49 | -- are used for scaling. | 55 | -- are used for scaling. |
50 | -- | 56 | -- |
51 | -- >>> let m = (2><3)[1..] :: Matrix Double | 57 | -- >>> import Data.Monoid as M |
52 | -- >>> m <> 2 <> diagl[0.5,1,0] | 58 | -- >>> let m = mat 3 [1..6] |
59 | -- >>> m M.<> 2 M.<> diagl[0.5,1,0] | ||
53 | -- (2><3) | 60 | -- (2><3) |
54 | -- [ 1.0, 4.0, 0.0 | 61 | -- [ 1.0, 4.0, 0.0 |
55 | -- , 4.0, 10.0, 0.0 ] | 62 | -- , 4.0, 10.0, 0.0 ] |
56 | -- | 63 | -- |
57 | -- 'mconcat' uses 'optimiseMult' to get the optimal association order. | 64 | -- 'mconcat' uses 'optimiseMult' to get the optimal association order. |
58 | 65 | ||
@@ -76,10 +83,18 @@ module Numeric.HMatrix ( | |||
76 | inv, pinv, pinvTol, | 83 | inv, pinv, pinvTol, |
77 | 84 | ||
78 | -- * Determinant and rank | 85 | -- * Determinant and rank |
79 | rcond, rank, ranksv, | 86 | rcond, rank, |
80 | det, invlndet, | 87 | det, invlndet, |
81 | 88 | ||
82 | -- * Singular value decomposition | 89 | -- * Norms |
90 | Normed(..), | ||
91 | norm_Frob, norm_nuclear, | ||
92 | |||
93 | -- * Nullspace and range | ||
94 | orth, | ||
95 | nullspace, null1, null1sym, | ||
96 | |||
97 | -- * SVD | ||
83 | svd, | 98 | svd, |
84 | fullSVD, | 99 | fullSVD, |
85 | thinSVD, | 100 | thinSVD, |
@@ -112,18 +127,6 @@ module Numeric.HMatrix ( | |||
112 | sqrtm, | 127 | sqrtm, |
113 | matFunc, | 128 | matFunc, |
114 | 129 | ||
115 | -- * Nullspace | ||
116 | nullspacePrec, | ||
117 | nullVector, | ||
118 | nullspaceSVD, | ||
119 | null1, null1sym, | ||
120 | |||
121 | orth, | ||
122 | |||
123 | -- * Norms | ||
124 | Normed(..), | ||
125 | norm_Frob, norm_nuclear, | ||
126 | |||
127 | -- * Correlation and convolution | 130 | -- * Correlation and convolution |
128 | corr, conv, corrMin, corr2, conv2, | 131 | corr, conv, corrMin, corr2, conv2, |
129 | 132 | ||
@@ -132,7 +135,8 @@ module Numeric.HMatrix ( | |||
132 | Seed, RandDist(..), randomVector, rand, randn, gaussianSample, uniformSample, | 135 | Seed, RandDist(..), randomVector, rand, randn, gaussianSample, uniformSample, |
133 | 136 | ||
134 | -- * Misc | 137 | -- * Misc |
135 | meanCov, peps, relativeError, haussholder, optimiseMult, udot, | 138 | meanCov, peps, relativeError, haussholder, optimiseMult, udot, nullspaceSVD, orthSVD, ranksv, |
139 | ℝ,ℂ,iC, | ||
136 | -- * Auxiliary classes | 140 | -- * Auxiliary classes |
137 | Element, Container, Product, Numeric, LSDiv, | 141 | Element, Container, Product, Numeric, LSDiv, |
138 | Complexable, RealElement, | 142 | Complexable, RealElement, |
@@ -142,8 +146,7 @@ module Numeric.HMatrix ( | |||
142 | -- Normed, | 146 | -- Normed, |
143 | Transposable, | 147 | Transposable, |
144 | CGState(..), | 148 | CGState(..), |
145 | Testable(..), | 149 | Testable(..) |
146 | ℕ,ℤ,ℝ,ℂ, i_C | ||
147 | ) where | 150 | ) where |
148 | 151 | ||
149 | import Numeric.LinearAlgebra.Data | 152 | import Numeric.LinearAlgebra.Data |
@@ -151,14 +154,38 @@ import Numeric.LinearAlgebra.Data | |||
151 | import Numeric.Matrix() | 154 | import Numeric.Matrix() |
152 | import Numeric.Vector() | 155 | import Numeric.Vector() |
153 | import Data.Packed.Numeric hiding ((<>)) | 156 | import Data.Packed.Numeric hiding ((<>)) |
154 | import Numeric.LinearAlgebra.Algorithms hiding (linearSolve,Normed) | 157 | import Numeric.LinearAlgebra.Algorithms hiding (linearSolve,Normed,orth) |
155 | import qualified Numeric.LinearAlgebra.Algorithms as A | 158 | import qualified Numeric.LinearAlgebra.Algorithms as A |
156 | import Numeric.LinearAlgebra.Util | 159 | import Numeric.LinearAlgebra.Util |
157 | import Numeric.LinearAlgebra.Random | 160 | import Numeric.LinearAlgebra.Random |
158 | import Numeric.Sparse((!#>)) | 161 | import Numeric.Sparse((!#>)) |
159 | import Numeric.LinearAlgebra.Util.CG | 162 | import Numeric.LinearAlgebra.Util.CG |
160 | 163 | ||
161 | -- | matrix product | 164 | {- | dense matrix product |
165 | |||
166 | >>> let a = (3><5) [1..] | ||
167 | >>> a | ||
168 | (3><5) | ||
169 | [ 1.0, 2.0, 3.0, 4.0, 5.0 | ||
170 | , 6.0, 7.0, 8.0, 9.0, 10.0 | ||
171 | , 11.0, 12.0, 13.0, 14.0, 15.0 ] | ||
172 | |||
173 | >>> let b = (5><2) [1,3, 0,2, -1,5, 7,7, 6,0] | ||
174 | >>> b | ||
175 | (5><2) | ||
176 | [ 1.0, 3.0 | ||
177 | , 0.0, 2.0 | ||
178 | , -1.0, 5.0 | ||
179 | , 7.0, 7.0 | ||
180 | , 6.0, 0.0 ] | ||
181 | |||
182 | >>> a <> b | ||
183 | (3><2) | ||
184 | [ 56.0, 50.0 | ||
185 | , 121.0, 135.0 | ||
186 | , 186.0, 220.0 ] | ||
187 | |||
188 | -} | ||
162 | (<>) :: Numeric t => Matrix t -> Matrix t -> Matrix t | 189 | (<>) :: Numeric t => Matrix t -> Matrix t -> Matrix t |
163 | (<>) = mXm | 190 | (<>) = mXm |
164 | infixr 8 <> | 191 | infixr 8 <> |
@@ -166,3 +193,9 @@ infixr 8 <> | |||
166 | -- | Solve a linear system (for square coefficient matrix and several right-hand sides) using the LU decomposition, returning Nothing for a singular system. For underconstrained or overconstrained systems use 'linearSolveLS' or 'linearSolveSVD'. | 193 | -- | Solve a linear system (for square coefficient matrix and several right-hand sides) using the LU decomposition, returning Nothing for a singular system. For underconstrained or overconstrained systems use 'linearSolveLS' or 'linearSolveSVD'. |
167 | linearSolve m b = A.mbLinearSolve m b | 194 | linearSolve m b = A.mbLinearSolve m b |
168 | 195 | ||
196 | -- | return an orthonormal basis of the null space of a matrix. See also 'nullspaceSVD'. | ||
197 | nullspace m = nullspaceSVD (Left (1*eps)) m (rightSV m) | ||
198 | |||
199 | -- | return an orthonormal basis of the range space of a matrix. See also 'orthSVD'. | ||
200 | orth m = orthSVD (Left (1*eps)) m (leftSV m) | ||
201 | |||