Fitting a system of ODEs to data
Hi everyone, I have a system of coupled multivariate ODEs which I would like to fit to experimental data. If I am reading the SciPy documentation correctly, there exist built in functions to handle systems of multivariate nonlinear functions (Broyden's and Anderson's methods), but not systems of ODEs. After reading up on some general methods, it looks like it would be a real bear to write an implementation myself. I posed this issue to an expert Python programmer with whom I am acquainted, and he suggested using Mathematica to address my problem. I have essentially no experience with Mathematica, though, so before biting that particular bullet I thought I'd check with the larger community to see if there is Python/SciPy solution. Thanks very much for any suggestions! Colin _________________________________________________________________ With Windows Live, you can organize, edit, and share your photos. http://www.windowslive.com/Desktop/PhotoGallery
On Thu, Sep 10, 2009 at 10:19 AM, C. Campbell <lujitsu@hotmail.com> wrote:
I have a system of coupled multivariate ODEs which I would like to fit to experimental data. If I am reading the SciPy documentation correctly, there exist built in functions to handle systems of multivariate nonlinear functions (Broyden's and Anderson's methods), but not systems of ODEs. After reading up on some general methods, it looks like it would be a real bear to write an implementation myself.
It depends on how you want to set up your optimization problem, but the existing minimization codes in scipy are reasonably good at doing just this. I think the idea that you are missing is that you would need to write an objective function for these solvers that computes an ODE orbit and compares it with your data, according to whatever metric you prefer. A common technique does not require multivariate methods when data from multiple dimensions in concatenated into a single vector for something like a least squares fit method. A search on google for "ODE fitting scipy" immediately shows tutorials and other resources for doing such things. -Rob
On Thu, Sep 10, 2009 at 09:19, C. Campbell<lujitsu@hotmail.com> wrote:
Hi everyone,
I have a system of coupled multivariate ODEs which I would like to fit to experimental data. If I am reading the SciPy documentation correctly, there exist built in functions to handle systems of multivariate nonlinear functions (Broyden's and Anderson's methods), but not systems of ODEs. After reading up on some general methods, it looks like it would be a real bear to write an implementation myself.
I posed this issue to an expert Python programmer with whom I am acquainted, and he suggested using Mathematica to address my problem. I have essentially no experience with Mathematica, though, so before biting that particular bullet I thought I'd check with the larger community to see if there is Python/SciPy solution.
I answered a similar question over on StackOverflow: http://stackoverflow.com/questions/1164198/fitting-parameters-of-odes-while-... -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Thanks, both of you. I actually had tried something similar to what you both suggested, but it didn't seem like the function was converging to a solution, so I (incorrectly!) assumed the problem must be with the ODE nature of my system. I'll try to optimize my code and let the program run longer, now that I know that it is the correct approach. Thanks again; I really appreciate the rapid and helpful responses! Colin
From: robert.kern@gmail.com Date: Thu, 10 Sep 2009 10:48:34 -0500 To: lujan@clancore.net; scipy-user@scipy.org Subject: Re: [SciPy-User] Fitting a system of ODEs to data
On Thu, Sep 10, 2009 at 09:19, C. Campbell<lujitsu@hotmail.com> wrote:
Hi everyone,
I have a system of coupled multivariate ODEs which I would like to fit to experimental data. If I am reading the SciPy documentation correctly, there exist built in functions to handle systems of multivariate nonlinear functions (Broyden's and Anderson's methods), but not systems of ODEs. After reading up on some general methods, it looks like it would be a real bear to write an implementation myself.
I posed this issue to an expert Python programmer with whom I am acquainted, and he suggested using Mathematica to address my problem. I have essentially no experience with Mathematica, though, so before biting that particular bullet I thought I'd check with the larger community to see if there is Python/SciPy solution.
I answered a similar question over on StackOverflow:
http://stackoverflow.com/questions/1164198/fitting-parameters-of-odes-while-...
-- Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
_________________________________________________________________ Get back to school stuff for them and cashback for you. http://www.bing.com/cashback?form=MSHYCB&publ=WLHMTAG&crea=TEXT_MSHYCB_BackToSchool_Cashback_BTSCashback_1x1
On Thu, Sep 10, 2009 at 12:08, C. Campbell<lujitsu@hotmail.com> wrote:
Thanks, both of you. I actually had tried something similar to what you both suggested, but it didn't seem like the function was converging to a solution, so I (incorrectly!) assumed the problem must be with the ODE nature of my system.
It might be, sort of. You will probably have to have a good guess of the parameters. The functions generated by many ODEs tend to be less suitable for fitting than other functions of interest. You may encounter many local optima. It would be worthwhile to do a bit of brute force searching through your parameter space to get a good starting point or use a global optimizer. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
encountering many local optima may as well be an artifact of inaccurate derivative approximations (gradient, hessian). A long valley with steep walls often converges only to the bottom of the valley but due to the inaccurate gradient it can't find a descent direction anymore. The get the derivative information you can do the following: define the variational ODE, i.e. if your ODE is d/dt x = f(t,x,p) x(0) = x0(p) Then the variational ODE is d/dt x = f(t,x,p) d/dt x_p = f_x(t,x,p) x_p + f_p(t,xp) x(0) = x0(p) x_p(0) = x0_p(p) where x_p := d/dp x The evaluation can then be done by the standard scipy ode solvers. Input for scipy.optimize.leastsq is the vector of measurements y = [y(t_1), y(t_2), ...., ] taken at the measurement times ts = [t_1, t_2, ....]. You can also now define a function Dfun that returns the Jacobian y_p. This should work much better than the version without derivative information. There is also an adjoint ODE solver in Python that would be preferable if the number of parameters is large, but I can't recall the name of the package right now.... Sebastian On Thu, Sep 10, 2009 at 7:13 PM, Robert Kern <robert.kern@gmail.com> wrote:
On Thu, Sep 10, 2009 at 12:08, C. Campbell<lujitsu@hotmail.com> wrote:
Thanks, both of you. I actually had tried something similar to what you both suggested, but it didn't seem like the function was converging to a solution, so I (incorrectly!) assumed the problem must be with the ODE nature of my system.
It might be, sort of. You will probably have to have a good guess of the parameters. The functions generated by many ODEs tend to be less suitable for fitting than other functions of interest. You may encounter many local optima. It would be worthwhile to do a bit of brute force searching through your parameter space to get a good starting point or use a global optimizer.
-- Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
If you have access to Matlab, you could try the PottersWheel ODE modeling and fitting toolbox available at www.potterswheel.de. Greetings, Thomas -- View this message in context: http://old.nabble.com/Fitting-a-system-of-ODEs-to-data-tp25384199p31451555.h... Sent from the Scipy-User mailing list archive at Nabble.com.
participants (5)
-
C. Campbell
-
Rob Clewley
-
Robert Kern
-
Sebastian Walter
-
Thomas Maiwald