diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-04-06 18:24:16 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-04-06 18:24:16 +0000 |
commit | 2e48ffd1a395817288b8271299eebd0e483407af (patch) | |
tree | aa5c17b536bdc09773f12f2878d2af6c4e25962e /lib/Numeric/LinearAlgebra/Tests.hs | |
parent | d3f5ec99d5839206dfb2bba7df5a98d250a2c60e (diff) |
some changes in GSL.Fitting
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Tests.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests.hs | 12 |
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 | ||
146 | fittingTest = utest "levmar" ok | 146 | fittingTest = 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 | ||