How to return the maximum/minimum/mean value of the trajectory x(t) solved by ODE solver?
Hi Tianqi, do you know How to return the maximum/minimum/mean value of the trajectory x(t) solved by ODE solver?
Hmm. Mean should be easy because you just need to integrate over x(t) (i.e. store in as a part of the state), assuming what you want is something like 1/T int_0^T x(t) dt.
Max/min are probably as hard as optimizing a non-convex problem (in 1d).
We don't support this at the moment (because it requires a lot of memory), but perhaps returning a dense output instead of x(t) evaluated at user-input t values could be a good idea. Then you can use another optimization method on this dense output to find the max/min.
Oh, how about this. Let x(t) follow dx(t)/dt = f(t, x(t)).
Let m(t) be the minimum of x(t) in the interval 0 to t. Then m(t) should have the ODE
dm(t)/dt = (x(t) < m(t)) * f(t, m(t))
So whenever x(t) < m(t), m(t) will be perturbed by an infinitesimal amount f. I'm not sure if our solvers can actually solve this properly though.
Just chipping into say that a few other (mutually independent) approaches for min/max also come to mind:
- Define an event that detects when (
dx(t)/dt=)f(t, x(t)) = 0. Plus some extra handling to restart the ODE, include the start/end of the ODE as possible extrema etc. - Once they're in, use callbacks (#134) and track a running min/max of the numerically computed state.
- Keep a running min/max of the input
xthe vector field is evaluated at, with some extra checking to see if steps have been accepted/rejected (based on whethertupdates), so that you don't trackxs from rejected steps.
I think any of the above should work.
Hmm. Mean should be easy because you just need to integrate over x(t) (i.e. store in as a part of the state), assuming what you want is something like
1/T int_0^T x(t) dt.Max/min are probably as hard as optimizing a non-convex problem (in 1d).
We don't support this at the moment (because it requires a lot of memory), but perhaps returning a dense output instead of x(t) evaluated at user-input t values could be a good idea. Then you can use another optimization method on this dense output to find the max/min.
That's what have thought about and it definitely may cost a lot of memory. Thanks for the help -_-.
Just chipping into say that a few other (mutually independent) approaches for min/max also come to mind:
- Define an event that detects when (
dx(t)/dt=)f(t, x(t)) = 0. Plus some extra handling to restart the ODE, include the start/end of the ODE as possible extrema etc.- Once they're in, use callbacks (#134) and track a running min/max of the numerically computed state.
- Keep a running min/max of the input
xthe vector field is evaluated at, with some extra checking to see if steps have been accepted/rejected (based on whethertupdates), so that you don't trackxs from rejected steps.I think any of the above should work.
Oh, it should be an efficient way to do. I'll try in the following days. Thanks (●’◡’●).