Discussion:
[Numpy-discussion] scipy curve_fit variable list of optimisation parameters
Siegfried Gonzi
2016-08-02 17:41:21 UTC
Permalink
Hi all

Does anyone know how to invoke curve_fit with a variable number of parameters, e.g. a1 to a10 without writing it out,

e.g.

def func2( x, a1,a2,a3,a4 ):

# Bessel function
tmp = scipy.special.j0( x[:,:] )

return np.dot( tmp[:,:] , np.array( [a1,a2,a3,a4] )


### yi = M measurements (.e.g M=20)
### x = M (=20) rows of N (=4) columns
popt = scipy.optimize.curve_fit( func2, x, yi )

I'd like to get *1 single vector* (in this case of size 4) of optimised A(i) values.

The function I am trying to minimise (.e.g F(r) is a vector of 20 model measurements): F(r) = SUM_i_to_N [ A(i) * bessel_function_J0(i * r) ]


Thanks,
Siegfried Gonzi
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
Evgeni Burovski
2016-08-02 21:50:42 UTC
Permalink
On Tue, Aug 2, 2016 at 6:41 PM, Siegfried Gonzi
Post by Siegfried Gonzi
Hi all
Does anyone know how to invoke curve_fit with a variable number of parameters, e.g. a1 to a10 without writing it out,
e.g.
# Bessel function
tmp = scipy.special.j0( x[:,:] )
return np.dot( tmp[:,:] , np.array( [a1,a2,a3,a4] )
### yi = M measurements (.e.g M=20)
### x = M (=20) rows of N (=4) columns
popt = scipy.optimize.curve_fit( func2, x, yi )
I'd like to get *1 single vector* (in this case of size 4) of optimised A(i) values.
The function I am trying to minimise (.e.g F(r) is a vector of 20 model measurements): F(r) = SUM_i_to_N [ A(i) * bessel_function_J0(i * r) ]
Thanks,
Siegfried Gonzi
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
You can use `leastsq` or `least_squares` directly: they both accept an
array of parameters.

BTW, since all of these functions are actually in scipy, you might
want to redirect this discussion to the scipy-user mailing list.

Cheers,

Evgeni

Loading...