diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-05-08 08:48:12 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-05-08 08:48:12 +0200 |
commit | 1925c123d7d8184a1d2ddc0a413e0fd2776e1083 (patch) | |
tree | fad79f909d9c3be53d68e6ebd67202650536d387 /packages/hmatrix/examples/fitting.hs | |
parent | eb3f702d065a4a967bb754977233e6eec408fd1f (diff) |
empty hmatrix-base
Diffstat (limited to 'packages/hmatrix/examples/fitting.hs')
-rw-r--r-- | packages/hmatrix/examples/fitting.hs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/hmatrix/examples/fitting.hs b/packages/hmatrix/examples/fitting.hs new file mode 100644 index 0000000..a8f6b1c --- /dev/null +++ b/packages/hmatrix/examples/fitting.hs | |||
@@ -0,0 +1,24 @@ | |||
1 | -- nonlinear least-squares fitting | ||
2 | |||
3 | import Numeric.GSL.Fitting | ||
4 | import Numeric.LinearAlgebra | ||
5 | |||
6 | xs = map return [0 .. 39] | ||
7 | sigma = 0.1 | ||
8 | ys = map return $ toList $ fromList (map (head . expModel [5,0.1,1]) xs) | ||
9 | + scalar sigma * (randomVector 0 Gaussian 40) | ||
10 | |||
11 | dat :: [([Double],([Double],Double))] | ||
12 | |||
13 | dat = zip xs (zip ys (repeat sigma)) | ||
14 | |||
15 | expModel [a,lambda,b] [t] = [a * exp (-lambda * t) + b] | ||
16 | |||
17 | expModelDer [a,lambda,b] [t] = [[exp (-lambda * t), -t * a * exp(-lambda*t) , 1]] | ||
18 | |||
19 | (sol,path) = fitModelScaled 1E-4 1E-4 20 (expModel, expModelDer) dat [1,0,0] | ||
20 | |||
21 | main = do | ||
22 | print dat | ||
23 | print path | ||
24 | print sol | ||