summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Tests.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Tests.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Tests.hs12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs
index c9408a6..60c60e6 100644
--- a/lib/Numeric/LinearAlgebra/Tests.hs
+++ b/lib/Numeric/LinearAlgebra/Tests.hs
@@ -143,19 +143,23 @@ odeTest = utest "ode" (last (toLists sol) ~~ [-1.7588880332411019, 8.36434890871
143 143
144--------------------------------------------------------------------- 144---------------------------------------------------------------------
145 145
146fittingTest = utest "levmar" ok 146fittingTest = utest "levmar" (ok1 && ok2)
147 where 147 where
148 xs = map return [0 .. 39] 148 xs = map return [0 .. 39]
149 sigma = 0.1 149 sigma = 0.1
150 ys = map return $ toList $ fromList (map (head . expModel [5,0.1,1]) xs) 150 ys = map return $ toList $ fromList (map (head . expModel [5,0.1,1]) xs)
151 + scalar sigma * (randomVector 0 Gaussian 40) 151 + scalar sigma * (randomVector 0 Gaussian 40)
152 dat = zipWith3 (,,) xs ys (repeat sigma) 152 dats = zip xs (zip ys (repeat sigma))
153 dat = zip xs ys
153 154
154 expModel [a,lambda,b] [t] = [a * exp (-lambda * t) + b] 155 expModel [a,lambda,b] [t] = [a * exp (-lambda * t) + b]
155 expModelDer [a,lambda,_b] [t] = [[exp (-lambda * t), -t * a * exp(-lambda*t) , 1]] 156 expModelDer [a,lambda,_b] [t] = [[exp (-lambda * t), -t * a * exp(-lambda*t) , 1]]
156 157
157 sol = fst $ fitModel 1E-4 1E-4 20 (resM expModel, resD expModelDer) dat [1,0,0] 158 sols = fst $ fitModelScaled 1E-4 1E-4 20 (expModel, expModelDer) dats [1,0,0]
158 ok = and (zipWith f sol [5,0.1,1]) where f (x,d) r = abs (x-r)<2*d 159 sol = fst $ fitModel 1E-4 1E-4 20 (expModel, expModelDer) dat [1,0,0]
160
161 ok1 = and (zipWith f sols [5,0.1,1]) where f (x,d) r = abs (x-r)<2*d
162 ok2 = pnorm PNorm2 (fromList (map fst sols) - fromList sol) < 1E-5
159 163
160--------------------------------------------------------------------- 164---------------------------------------------------------------------
161 165