# Parameter Estimation with partial data

**URL:** <https://discourse.julialang.org/t/parameter-estimation-with-partial-data/123192>\
**Category:** Probabilistic Programming\
**Tags:** question\
**Created:** [November 28, 2024, 12:08am UTC](https://discourse.julialang.org/t/parameter-estimation-with-partial-data/123192 "2024-11-28T00:08:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fourier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fourier/32/38176_2.png) [@Fourier](https://discourse.julialang.org/u/Fourier)\
**Post date:** [November 28, 2024, 12:08am UTC](https://discourse.julialang.org/t/parameter-estimation-with-partial-data/123192/1 "2024-11-28T00:08:53Z")

</div>

Hi,  
I have a differential equation, for example the differential equation for a pendulum, like in [this example](https://docs.sciml.ai/DiffEqBayes/stable/examples/pendulum/) 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](https://discourse.julialang.org/t/differential-equation-parameter-estimation-using-only-a-subset-of-variables/23423)). 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?

---

<div class="post-metadata">

**Author:** ![Fourier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fourier/32/38176_2.png) [@Fourier](https://discourse.julialang.org/u/Fourier)\
**Post date:** [November 28, 2024, 12:17am UTC](https://discourse.julialang.org/t/parameter-estimation-with-partial-data/123192/2 "2024-11-28T00:17:20Z")

</div>

Minimal Working Example:

```julia
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)`

---

<div class="post-metadata">

**Author:** ![Fourier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fourier/32/38176_2.png) [@Fourier](https://discourse.julialang.org/u/Fourier)\
**Post date:** [November 28, 2024, 8:35am UTC](https://discourse.julialang.org/t/parameter-estimation-with-partial-data/123192/3 "2024-11-28T08:35:35Z")

</div>

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])`
