New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Increasing divergence and oscillation between steps #60
Comments
The distance between consecutive states isn't bounded as it depends on the learned f. What Also, a diverging ODE isn't really a problem unless you want to integrate to t=infinity. Sometimes the learned ODE learns to expand (e.g. if transforming something bounded in [0,1] to something in a much larger range of values).
Hmm.. have you verified this? This would suggest that the steps (0, T) are not being useful, since a constant trajectory would've sufficed to transform x(0) to x(T). It's possible that a part of the state behaves this way in order to transform another part of the state, which is perfectly valid. But this shouldn't occur for the entire state, especially if you've used zero initialization for the ODE function.
I don't think this pair-wise difference is very interpretable, as the solutions could just be oscillating around the same value. It would be more meaningful to always compare to the same solution (e.g. with tolerances set to 1e-10). This way you should see that the solutions are getting closer and closer to the 1e-10 estimate when decreasing tolerance. |
Hmm, correct me if I'm wrong, but these plots look like you're logging the states where f is evaluated, rather than using the odeint API to query the intermediate states? You want to be doing the latter, not the former, when analyzing states along the trajectory. One thing to note that the RK45 solver evaluates f at intermediate probes that are not along the actual trajectory, and these probes come in bursts of 5 in this loop (https://github.com/rtqichen/torchdiffeq/blob/master/torchdiffeq/_impl/rk_common.py#L49). Every 6 evaluates contains the The initial step size selection evaluates f twice (https://github.com/rtqichen/torchdiffeq/blob/master/torchdiffeq/_impl/misc.py#L84), so the RK45 algorithm always performs Instead of logging the states when f is evaluated, can you use the odeint API to query what the intermediate states are? These states will be along the actual estimated trajectory. |
Yes! With the exception of the last state, the states are the inputs to f, including the initial value.
Is it possible to interact with the odeint API to query states along the estimated trajectory instead of the states evaluated at the integration time, in my case 0 and 1? By the way, thank you for your help. It is extremely valuable! |
Yes, do No worries! Happy to help. |
I wrote a few mistakes in my earlier answer. The number of evaluations should be 2 + 6*steps. The last evaluation is the last state. I've corrected these mistakes in the previous reply. Apologies if I've confused you. To clarify which evaluations during the solver are actually on the estimated path:
The evaluations indicated by The first two are for selecting the initial step size. This solver actually only takes 2 "steps", but evaluated 6 times per step. |
No sweat at all, the explanation is very clear now. |
The input (This follows the same API as scipy.integrate.odeint https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.odeint.html which was used in our earliest experiments.) At some point I should update the README to contain this information, but I've been lazy.. If you want to understand the finer details of how ODEs can be solved, "Solving Ordinary Differential Equations I Nonstiff Problems" by Hairer et al. is pretty good and describes the details of RK. The method |
Great, that makes everything very clear! |
That would be very useful! (But please don't feel obligated to.) |
@rtqichen Just a heads up that I'll soon send a PR with a FAQ addressing common issues and questions related to Neural ODEs, using your answer whenever possible. |
Hey Ricky (@rtqichen) , I just realized there's a typo in this example: The count jumps from 10 to 12... |
Hey @rtqichen!
While doing experiments on a model, I found out that the L2 norm of the distance between subsequent states is increasing with the relative tolerance set to 0 and different values of the absolute tolerance.
I understand that that distance is proportionally upper bounded by
atol + rtol * norm(state)
but I would not expect it to grow because to me it suggests the solution is diverging or oscillating. For example, some state at step T is more similar to a state at step 0 than a state in step (0, T).Any thoughts? I'm using the adaptive solver with RK45.
Here are some plots including the infinity norm of the state, the L2 norm of the distance between subsequent states and the respective error threshold.
Absolute tolerance 1e-5, Relative tolerance 0
Absolute tolerance 1e-9, Relative tolerance 0
Absolute tolerance 1e-10, Relative tolerance 0
The text was updated successfully, but these errors were encountered: