source: corel/fit_parab.py @ 2

Last change on this file since 2 was 2, checked in by meynadie, 16 years ago
File size: 1.1 KB
Line 
1# Interface pour optimize. Source : http://www.scipy.org/Cookbook/FittingData
2
3from scipy import optimize
4from numpy import *
5
6class Parameter:
7        def __init__(self, value):
8                self.value = value
9
10        def set(self, value):
11                self.value = value
12
13        def __call__(self):
14                return self.value
15
16def fit(function, parameters, y, x = None):
17        def f(params):
18                i = 0
19                for p in parameters:
20                        p.set(params[i])
21                        i += 1
22                return y - function(x)
23
24        if x is None: x = arange(y.shape[0])
25        p = [param() for param in parameters]
26        optimize.leastsq(f, p)
27
28## On fitte deux paraboles 2D en ce point (bloc 2*(npfit)+1**2)
29#npfit = 2
30
31# Changer le first guess si npfit change...
32#a = Parameter(-6.25E-5)
33#b = Parameter(2.5E-4)
34#c = Parameter(0.9995)
35
36#def f(x): return a()*x**2 + b()*x + c()
37
38#fit(f, [a,b,c], cor_prod[x_max-npfit:x_max+npfit+1,y_max])
39#x_par = -1*b()/(2*a())
40
41#fit(f, [a,b,c], cor_prod[x_max,y_max-npfit:y_max+npfit+1])
42#y_par = -1*b()/(2*a())
43
44#
45
Note: See TracBrowser for help on using the repository browser.