Open JohnGoertz opened 4 years ago
To copy my comment I made on this in #279 so we have the complete discussion in one place: Very interesting point! Since it's an ODEModel we can't get the analytical Jacobian, and finding it with numerical differentiation in every step is too expensive. Some minimizers however (BFGS springs to mind) approximate it as they go along. Those should be able to pick up on the underlying structure. (Very few minimizers are truly naive). For normal models you can work around this by introducing an intermediate variable, but I don't expect that will work here due to how this is implemented. Instead of passing just a Parameter as initial value, you kind of want to be able to pass an expression that evaluates to a single value.
My thinking here is that indeed you should just leverage the symbolical power here and define an extra expression in your model dict. However, that is not currently supported yet because ODEModels are a special snowflake.
However, there is a pretty good workaround available, I recommend that you have a look at this example and adopt it to your problem. This way you should be able to define an extra component which lives in log space.
Unfortunately I don't have time right now to get into the details but let me know if you're having problems then I'll write down what I mean in more detail.
Workaround aside, I still see a value in being able to provide expressions as initial values. (initial={t0: a+b}
, for example). The questions are: 1) how does odeint deal with an array as initial value? 2) do we want to restrict those expressions to not allow Variables?
Since 0.5.2 (and this merge) symfit can now estimate the initial values of ODEModels. However, there's no clear way to provide the scale of those initial values. For example, the following code fits a logistic curve to some data. Important information is the growth rate
r
and the initial signals1_0
. This works fine if I give a good guess for s1_0, but I know that the local minima in the model are evenly distributed in the "log" space of the initial values. If I brute force the residuals, I find the global minima occurs at r = 0.8 and log10(s1_0) = -7.5, but there are other local minima at log10(s1_0) ~ -5.5, -6.5, -8.5, -9.5 with r = 0.6, 0.7, 0.9, and 1.0, respectively.Is there a way around this? Perhaps sympy could be used more explicitly, setting s1_0 as a relation to an intermediate value that lives in log-space?
Here's the code for brute-forcing the residuals. Obviously, this is a very hard problem, particularly for a local minimizer...
And plotting the result: