-
Notifications
You must be signed in to change notification settings - Fork 12
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
Model fitting API #24
Comments
Some optimization/model fitting tools: Other refs on model fitting:
|
It is probably possible to use also gradient-based optimization algorithms. Perhaps we could use Autograd to compute gradients of the dynamical system (but then without code generation), and then use gradient descent or some other optimization procedure with derivatives. If there are n variables and p parameters, then one must simulate n*p variables. To calculate dE/dp, where E is an error criterion and p is a parameter, we need to be able to calculate dVm/dp. We get this by differentiating the membrane equation with respect to p, and then integrating. We see that we actually need to calculate dXi/dp for every state variable i. We use autograd to calculate the RHS. The main question is whether this can be easily vectorize. |
I think the biggest challenge here is to find a good balance between reusing existing libraries and at the same time make good use of Brian's code generation facilities (e.g. in your branch, the error is calculated within Brian code instead of externally). About gradient-based methods: I don't see a use case for Autograd here, if I am not mistaken its strength lies in being able to do derivatives of (almost) arbitrary Python/numpy code, i.e. code involving loops, if statements, and so on. In our case, we only have equations and can do everything symbolically with sympy I think? Plenty of things to discuss with @alTeska who will work on this in the coming months 😄 |
You're right about the differentiation, I think! It would be awesome to be able to used gradient-based optimization methods. |
I have extended the list of possible optimization/model fitting tools listed them on the new Project Board if you'd like to have a look. As it comes to gradient-based optimization they have been reported to be used for local optimization, used to refine the results, so if possible we should include them in the module. |
Should this all perhaps go in a separate package (e.g. https://github.com/brian-team/brian2modelfitting) rather than being added to brian2tools? |
This would definitely be an option, especially if it the package gets very complex/powerful. On the other hand, I think it would help for the discoverability if there is a single package But changing from one to the other should be pretty easy later on, we just have to take a final decision before we make a release. |
One thing I was just thinking about for the API is the possibility to deal with recordings done in different conditions (e.g. drugs). I see two ways of dealing with this:
Syntax requires some thought! |
We have some model fitting code in the model fitting branch. It uses differential evolution to fit traces. But what we could do is a general API, which would work with any optimization function. The user simply defines the criterion to be calculated, and passes the optimization function to use. This could work for any gradient-free algorithm.
What we need to add is a callback for initializing the models, and maybe a few other things.
Then we might be able to use gradient-based algorithms by using automatic differentiation tools such as Autograd. To calculate dE/dp, where E is an error criterion and p is a parameter, we need to be able to calculate dVm/dp. We get this by differentiating the membrane equation with respect to p, and then integrating. We see that we actually need to calculate dXi/dp for every state variable i. We use autograd to calculate the RHS. The main question is whether this can be easily vectorized across neurons.
The text was updated successfully, but these errors were encountered: