Today I was asked whether it was possible to solve in Julia differential equations involving numbers with uncertainties. Of course the answer is yes. What I find really amazing about Julia is that the two packages don’t know anything about each other, yet they can work together without any effort. Here is an short example based on this tutorial: Jupyter Notebook Viewer
The only think I found weird was that the extrema of the time interval had to be Measurement objects, otherwise solve would complain (because it can’t convert Measurement type to Float64). Why it’s that? I can see why u0 should have the same type as that returned by f, but not why also the time should match the same type.
Adaptive timestepping. When using adaptive timestepping (the default), the times that the solver is internally doing have an uncertainty as well since its steps are determined by the ODE system itself, so it needs to keep track of the uncertainty in time.
Did you reproduce the example above at least? I’m asking because the the interface of DiiferentialEquations.jl has changed (inverted some of the parameters).That might be it but I haven’t done that with MTK.
If that is the case, checkout the docs for the correct syntax and don’t forget that initial values and tspan should include uncertainty.
Actually, I hadn’t tried the example. I get the same error, so assume that this does not work anymore.
Pity. It would be neat and impressive to be able to carry the uncertainty and propagate it through. Although I cannot imagine how it is going to work on a non-linear equation …
I hadn’t seen the tutorial you reference here, but the one in the original post works if the function definition is adjusted to reflect the changes in DifferentialEquations.jl - as in the DiffEq tutorials you mentioned.
So it does work with directly defined ODEs.
My original question was, if it is supposed or expected to work with MTK models that have a symbolic component. If not, then we can close the case. If yes, then we can start digging into it.
It would work if you create an ODEProblem from ModelingToolkit with a u0 that is a Measurement. I am not sure about the other potential use case of tracing through Measurements generated code.
I have recreated my model from scratch (since all the default values were Float64, I needed to replace all of them with defaults of type Measurement{Float64}) and now the error messages are a bit clearer and fit for discussion
When calling structural_simplify(rc_model) I get:
“”"
sys
TypeError: in Measurement, in T, expected T<:AbstractFloat, got Type{Real}
The Julia code for a simple model is here. I’ll need to triple check that I haven’t overlooked a Float64 initialisation in there, but couldn’t find any.
I was trying to have all the parameters having uncertainty, rather than u0.
We want to know
how important the uncertainties are on parameter estimates that come from clinical measurements
how close we need to get with our parameter estimate in order to get a pressure response that is within physiological parameters (i.e. not dangerous to a patient)
At the moment I define the uncertainties on the parameter set and run an ensemble analysis, i.e. a few thousand to ten thousand runs on the whole model** and had hoped to use this as an alternative approach.
** this is now, due to a 200x speed-up over the original MATLAB code, not as much of a problem as it used to be and can be done in about 10-20 seconds, but still, getting that down further could allow real-time predictions