0

i'm facing a major problem fitting a function to my data. To explain the task, here's a graph of data with an early fit version:

seems like one needs at least 10 reputations to post a picture so heres a link to the picture... ---> Picture in here <---

The green -- line is the fitted function in the area where it was fitted and the red -- line the same function extrapolated to see where it would go. The last bit at x>0 is irrelevant for the fit and can be ignored. Important are only the S-curve and the two slopes on either side of it.

I'm using python and curve_fit to fit the functions. What i want to do now is fit a function which looks like this:

f(x) = s*g(x) + t*(1-h(x))

with:

g(x) = (m1*x + n1) / (1-10^(a1*x - b1))
h(x) = (m2*x + n2) / (1-10^(-a2*x - b2))

But since this function has a total of 10 variables it is very unstable. Right now i'm fitting it very ordinarily with curve_fit:

def function(x, a1, a2, b1, b1, m1, m2, n1, n2, s, t):
    g = (m1*x + n1) / (1-10^(a1*x - b1))
    h = (m2*x + n2) / (1-10^(-a2*x - b2))
    f = s*g + t*(1-h)
return f 
...
popt, pcov = curve_fit(function, xdata, ydata, maxfev=100000)

Now my actual question: Is it possible to fit those functions seperatly? for example:

1: fit left slope. m1*x + n1
2: fit right slope. m2*x + n2
3: fit g(x) according to the pre-fitted slopes
4: fit h(x) according to the pre-fitted slopes
5: fit f(x) 

Typing this, i just thought of some kind of recursion for this but i dont know how to pass the pre-fixed parameters of one step to the next and keep the fixed such that curve_fit only has to fit very few variables each time.

I would be very grateful for any kind of help on this problem. Maybe someone even knows a completely different approach on this or anything i could do better.

Tobrabo
  • 5
  • 4
  • But now when you return your `f(x)` finally, isn't it giving you the final fitted curve according to the equations `g(x)` and `h(x)` combined?? you can also try looking at [**this answer**](http://stackoverflow.com/questions/27153048/implementing-a-broken-power-law-as-a-fitting-function-in-origin/27158226#27158226), if this is what you want. – Srivatsan Dec 07 '14 at 12:53
  • It does return the proper function, but the fit is a little bit unstable with its 8 or 10 parameters... so i though I could tell curve_fit somehow to fix a few parameters and only fit, let's say three at a time. – Tobrabo Dec 11 '14 at 12:34

0 Answers0