Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Non-linear curve fitting?
-
Hey there, so I see that Pythonista has no access to SciPy which was the only way I knew how to do a non-linear curve fit in python. Do any of you know any way around this limitation? I'd really like to use my iPad for data analysis but this is holding me back.
-
polyfit in the numpy module does fitting to a polynomial. There are other more specialized methods also in the numpy module.
-
I'm aware of the polynomial fit, but I was hoping for something where I can specify some fit function like say a*e^(-x^2/b) where a and b are fit parameters. I can only find methods to do this with scipy. Do you know a method to do this on Pythonista?
-
https://en.m.wikipedia.org/wiki/Levenberg–Marquardt_algorithm
You have to manually compute the derivative wrt your free parameters at each x data point to form the jacobian matrix. For a simple example such as your function, you can analytically derive the jacobian (use sympy or pencil and paper).
-
lol i was about to write the same post...! Except i would rather compute the jacobian directly with a small increment.
-
that is another option, and is certainly the better general solution for dealing with user defined functions.... , but since most of the cost is going to be computation of the jacobian, an analytic solution will be much faster. I tend to deal with very large problems, but for typical curve fitting it is probably adequate.