summaryrefslogtreecommitdiff
path: root/packages/tests/src/Numeric/LinearAlgebra
diff options
context:
space:
mode:
Diffstat (limited to 'packages/tests/src/Numeric/LinearAlgebra')
-rw-r--r--packages/tests/src/Numeric/LinearAlgebra/Tests.hs107
1 files changed, 107 insertions, 0 deletions
diff --git a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs
index 043ebf3..55a5f74 100644
--- a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs
+++ b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs
@@ -131,6 +131,111 @@ mbCholTest = utest "mbCholTest" (ok1 && ok2) where
131 ok1 = mbChol (trustSym m1) == Nothing 131 ok1 = mbChol (trustSym m1) == Nothing
132 ok2 = mbChol (trustSym m2) == Just (chol $ trustSym m2) 132 ok2 = mbChol (trustSym m2) == Just (chol $ trustSym m2)
133 133
134-----------------------------------------------------
135
136triTest = utest "triTest" ok1 where
137
138 a :: Matrix R
139 a = (4><4)
140 [
141 4.30, 0.00, 0.00, 0.00,
142 -3.96, -4.87, 0.00, 0.00,
143 0.40, 0.31, -8.02, 0.00,
144 -0.27, 0.07, -5.95, 0.12
145 ]
146
147 w :: Matrix R
148 w = (4><2)
149 [
150 -12.90, -21.50,
151 16.75, 14.93,
152 -17.55, 6.33,
153 -11.04, 8.09
154 ]
155
156 v :: Matrix R
157 v = triSolve Lower a w
158
159 e :: Matrix R
160 e = (4><2)
161 [
162 -3.0000, -5.0000,
163 -1.0000, 1.0000,
164 2.0000, -1.0000,
165 1.0000, 6.0000
166 ]
167
168 ok1 = (maximum $ map abs $ concat $ toLists $ e - v) <= 1e-14
169
170-----------------------------------------------------
171
172triDiagTest = utest "triDiagTest" (ok1 && ok2) where
173
174 dL, d, dU :: Vector Double
175 dL = fromList [3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0]
176 d = fromList [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
177 dU = fromList [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]
178
179 b :: Matrix R
180 b = (9><3)
181 [
182 1.0, 1.0, 1.0,
183 1.0, -1.0, 2.0,
184 1.0, 1.0, 3.0,
185 1.0, -1.0, 4.0,
186 1.0, 1.0, 5.0,
187 1.0, -1.0, 6.0,
188 1.0, 1.0, 7.0,
189 1.0, -1.0, 8.0,
190 1.0, 1.0, 9.0
191 ]
192
193 y :: Matrix R
194 y = (9><9)
195 [
196 1.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
197 3.0, 1.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
198 0.0, 3.0, 1.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0,
199 0.0, 0.0, 3.0, 1.0, 4.0, 0.0, 0.0, 0.0, 0.0,
200 0.0, 0.0, 0.0, 3.0, 1.0, 4.0, 0.0, 0.0, 0.0,
201 0.0, 0.0, 0.0, 0.0, 3.0, 1.0, 4.0, 0.0, 0.0,
202 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 1.0, 4.0, 0.0,
203 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 1.0, 4.0,
204 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 1.0
205 ]
206
207 x :: Matrix R
208 x = triDiagSolve dL d dU b
209
210 z :: Matrix C
211 z = (4><4)
212 [
213 1.0 :+ 1.0, 4.0 :+ 4.0, 0.0 :+ 0.0, 0.0 :+ 0.0,
214 3.0 :+ 3.0, 1.0 :+ 1.0, 4.0 :+ 4.0, 0.0 :+ 0.0,
215 0.0 :+ 0.0, 3.0 :+ 3.0, 1.0 :+ 1.0, 4.0 :+ 4.0,
216 0.0 :+ 0.0, 0.0 :+ 0.0, 3.0 :+ 3.0, 1.0 :+ 1.0
217 ]
218
219 zDL, zD, zDu :: Vector C
220 zDL = fromList [3.0 :+ 3.0, 3.0 :+ 3.0, 3.0 :+ 3.0]
221 zD = fromList [1.0 :+ 1.0, 1.0 :+ 1.0, 1.0 :+ 1.0, 1.0 :+ 1.0]
222 zDu = fromList [4.0 :+ 4.0, 4.0 :+ 4.0, 4.0 :+ 4.0]
223
224 zB :: Matrix C
225 zB = (4><3)
226 [
227 1.0 :+ 1.0, 1.0 :+ 1.0, 1.0 :+ (-1.0),
228 1.0 :+ 1.0, (-1.0) :+ (-1.0), 1.0 :+ (-1.0),
229 1.0 :+ 1.0, 1.0 :+ 1.0, 1.0 :+ (-1.0),
230 1.0 :+ 1.0, (-1.0) :+ (-1.0), 1.0 :+ (-1.0)
231 ]
232
233 u :: Matrix C
234 u = triDiagSolve zDL zD zDu zB
235
236 ok1 = (maximum $ map abs $ concat $ toLists $ b - (y <> x)) <= 1e-15
237 ok2 = (maximum $ map magnitude $ concat $ toLists $ zB - (z <> u)) <= 1e-15
238
134--------------------------------------------------------------------- 239---------------------------------------------------------------------
135 240
136randomTestGaussian = (unSym c) :~3~: unSym (snd (meanCov dat)) 241randomTestGaussian = (unSym c) :~3~: unSym (snd (meanCov dat))
@@ -715,6 +820,8 @@ runTests n = do
715 && rank ((2><3)[1,0,0,1,7*peps,0::Double]) == 2 820 && rank ((2><3)[1,0,0,1,7*peps,0::Double]) == 2
716 , utest "block" $ fromBlocks [[ident 3,0],[0,ident 4]] == (ident 7 :: CM) 821 , utest "block" $ fromBlocks [[ident 3,0],[0,ident 4]] == (ident 7 :: CM)
717 , mbCholTest 822 , mbCholTest
823 , triTest
824 , triDiagTest
718 , utest "offset" offsetTest 825 , utest "offset" offsetTest
719 , normsVTest 826 , normsVTest
720 , normsMTest 827 , normsMTest