[SciPy-User] Curve fitting questions

Gökhan Sever gokhansever@gmail....
Tue Oct 19 12:50:50 CDT 2010

```Hello,

I am doing a few simple tests to see if I could estimate parameters
from a function fitting using less number of inputs. Three inputs
version works very well. The original version has 5 input points but
the difference between 3 and 5 inputs estimations are very small in
this case. I am wondering if two inputs case would be improved and if
anything could be done to estimate somewhat reasonable parameters
(with or without initial parameters provided) using 1 input only.

The code is as follows:

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

def my_ck(x, a, b):
return a*x**b

ccn_ss1 = [0.27, 0.34, 0.57]
ccn_conc1 = np.array([383.51237409766452, 424.82669523141652,
511.48197391304342])

# works fine with defaults
tfit1, pcov1 = curve_fit(my_ck, ccn_ss1, ccn_conc1)

ccn_ss1 = [0.27, 0.34]
ccn_conc1 = np.array([383.51237409766452, 424.82669523141652])

# between two consecutive iterates is at most 0.000000
# tfit1, pcov1 = curve_fit(my_ck, ccn_ss1, ccn_conc1)

# Trying with the original estimates, ftol should be set to a big
number otherwise this one fails as well.
# Is there any different optimize function which will auto-discover the
# initial parameters instead of supplying them explicitly?
tfit2, pcov2 = curve_fit(my_ck, ccn_ss1, ccn_conc1, p0=tfit1, ftol=1)

ccn_ss1 = 0.27
ccn_conc1 = 383.51237409766452
# One data point estimation fails with IndexError: index out of range for array
tfit3, pcov3 = curve_fit(my_ck, ccn_ss1, ccn_conc1, p0=tfit1, ftol=1)

Thanks.

--
Gökhan
```