-
Notifications
You must be signed in to change notification settings - Fork 216
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
Implement "exponential euler" integration for conditionally linear equations #14
Comments
I started implementing this state updater in the exponential_euler branch. Similar to the current exact integrator for linear equations it is using sympy and generates abstract code for calculating the coefficients. This needs more testing, though -- it runs fine and gives "reasonably-looking" results but there are significant differences to Brian1's results so something is not quite right. Oh and we should consider including something like the |
That's worrying - I hope the Brian 1 implementation is right! |
For very simple examples, both give the same results. For the complete COBAHH model the results differ a bit (and small differences can lead to a spike in one or the other) -- I'll still have to downsize the model to something simpler to get a better idea of where the difference lies. The differences are not big enough for real fundamental differences so it's possible that it's all about rounding errors that are progagated differently: In Brian 1, the A and B values are precalculated and extracted from the equations using the x=1 or x=0 trick, whereas in my current implementation for Brian2, everything is done symbollically. I'll try to test a stiff equation with a known analytical solution, next. Or do you have any other idea how to test this? |
Just to recap what we said at the meeting: if it's an accumulation of small numerical differences, then we should see it by e.g. driving a HH model with a subthreshold frozen noise current - the differences should gradually increase starting from 0, not suddenly diverge right from the beginning. |
Ok, I'm getting closer. A big chunk of the difference is actually not coming from rounding errors but from a more fundamental sympy issue. The HH equations contained expressions like |
Just to recap our meeting: the resolution to this problem should probably be to use sympy rewriting on Equations and turn all integers into floats, and not to use rewriting on other abstract code because the user may be expecting integer arithmetic. We could go all Python 3 and insist that integer division should use the // operator. |
Arg, had a major head slap moment here... After spending hours to find the remaining numerical difference between Brian 1 and Brian 2, trying to replace all constants by literal values, all literal values by constants, changing sympy simplifications, etc. I realized that the issue has nothing to do with the exponential Euler state updater at all, but can be also seen with Euler or RK integration... Integration timesteps were almost always identical, except for some rare cases (and then trajectories started to diverge, of course). After way too much time it turned out that this had nothing to do with the integration at all, but only with my ad-hoc implementation of a But the good news: The integration is consistent with Brian 1, I tested the HH model and for a subthreshold current with frozen noise, differences are on the order of 10e-13 mV (I did not check but I think this is close to machine precision), this sounds very reasonable (same for Euler and RK integration). If I let the neuron spike, numerical differences directly at the action potential go up to ~10e-10 mV, perfectly reasonable I think (Euler and RK were not stable with the same dt). The differences are also positive and negative, i.e. there is no constant bias. In most simulations, I don't think one should see any difference. I'll clean up things and then create a pull request. Let's deal with the integer issue separately in issue #51 . |
Good catch! I've run into this problem more than once I have to admit. For the implementation/syntax of |
Integrate with the system described in #11
The text was updated successfully, but these errors were encountered: