File: fitting.hs

package info (click to toggle)
haskell-hmatrix 0.15.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 608 kB
  • ctags: 302
  • sloc: haskell: 4,909; ansic: 2,688; makefile: 3
file content (24 lines) | stat: -rw-r--r-- 611 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- nonlinear least-squares fitting

import Numeric.GSL.Fitting
import Numeric.LinearAlgebra

xs = map return [0 .. 39]
sigma = 0.1
ys = map return $ toList $ fromList (map (head . expModel [5,0.1,1]) xs)
            + scalar sigma * (randomVector 0 Gaussian 40)

dat :: [([Double],([Double],Double))]

dat = zip xs (zip ys (repeat sigma))

expModel [a,lambda,b] [t] = [a * exp (-lambda * t) + b]

expModelDer [a,lambda,b] [t] = [[exp (-lambda * t), -t * a * exp(-lambda*t) , 1]]

(sol,path) = fitModelScaled 1E-4 1E-4 20 (expModel, expModelDer) dat [1,0,0]

main = do
    print dat
    print path
    print sol