Hi,
I have a differential equation, for example the differential equation for a pendulum, like in this example from DiffEqBayes. I would like to estimate the parameters.
However I only know a part of the solution, for example I only measured the position but not the speed of the pendulum.
I tried to use save_idxs=1 which only outputs the first index of the solution and thus also only takes that into account (see Differential Equation Parameter Estimation Using Only A Subset of Variables). However I get an DimensionMismatch: inconsistent array dimensions error that doesnt even show me the size of the arrays or what is supposed to be inconsistent. I also tried to use save_idxs=1:2 (position and speed) and it works again.
How can I use DiffEqBayes to estimate the parameters in this case?
function pendulum(du, u, p, t)
ω, L = p
x, y = u
du[1] = y
du[2] = -ω * y - (9.8 / L) * sin(x)
end
u0 = [1.0, 0.1]
tspan = (0.0, 10.0)
prob1 = ODEProblem(pendulum, u0, tspan, [1.0, 2.5])
t = collect(range(1, stop = 10, length = 10))
randomized = VectorOfArray([(sol(t[i]) + 0.01randn(2)) for i in 1:length(t)])
data = convert(Array, randomized)
priors = [
truncated(Normal(0.1, 1.0), lower = 0.0),
truncated(Normal(3.0, 1.0), lower = 0.0),
]
bayesian_result = turing_inference(prob1, Tsit5(), t, data, priors; num_samples = 10_000,
syms = [:omega, :L])
vs the same with randomized = VectorOfArray([(sol(t[i]) + 0.01randn()) for i in 1:length(t)])
and prob1 = ODEProblem(pendulum, u0, tspan, [1.0, 2.5], save_idxs=1)
You need to use it with both the problem and the turing solution: bayesian_result_turing = turing_inference(prob1, Tsit5(), t, data, priors, save_idxs = [1])