# ODE Parameter Estimation with Priors

**URL:** <https://discourse.julialang.org/t/ode-parameter-estimation-with-priors/135691>\
**Category:** Modelling & Simulations\
**Tags:** diffeq, optimization, differentialequation\
**Created:** [February 16, 2026, 8:26pm UTC](https://discourse.julialang.org/t/ode-parameter-estimation-with-priors/135691 "2026-02-16T20:26:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![donkeysaddle](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@donkeysaddle](https://discourse.julialang.org/u/donkeysaddle)\
**Post date:** [February 16, 2026, 8:26pm UTC](https://discourse.julialang.org/t/ode-parameter-estimation-with-priors/135691/1 "2026-02-16T20:26:09Z")

</div>

I have never done parameter estimation with priors(bayesian inference) before and I am a little unsure if I am going about it the right way. I created a simple example, but will ultimately be doing it for a more complicated system of ODEs. Was hoping I might get some advice/pointers for how I might improve this, or some reassurance that what I am doing is okay, before I dive into the deep end!

Should I be using DiffEqBayes.jl? Or perhaps I should just build my own loss and include the priors in that?

Anyways, Here’s the code:

> using OrdinaryDiffEq, DiffEqParamEstim  
> using Optimization, OptimizationOptimJL  
> using Distributions  
> using Plots
> 
> #Define ODE Problem  
> tspan = (0.0,10.0)  
> f!(du,u,p,t) = (du[1] = -p[1]\*u[1])  
> prob = ODEProblem(f!, [1.0], tspan, [0.4])  
> tdata = 0.0:0.1:10.0
> 
> #Generate dataset from with k=0.4, u0=1.0
> 
> k\_true = 0.4  
> u0\_true = 1.0  
> prob\_true = ODEProblem(f!, [u0\_true], tspan, [k\_true])  
> sol\_true = solve(prob\_true, Tsit5(); saveat=tdata, reltol=1e-10, abstol=1e-10)  
> y\_true = Array(sol\_true)[1,:]
> 
> #Define loss and priors and then optimize  
> loss = L2Loss(tdata, y\_true)  
> priors = [Gamma(1., .1)] # prior on p[1] (positive)
> 
> obj = build\_loss\_objective(prob, Tsit5(), loss; priors=priors, saveat=tdata)
> 
> adtype = Optimization.AutoForwardDiff();  
> optf = Optimization.OptimizationFunction((x, \_) → obj(x), adtype);  
> optprob = Optimization.OptimizationProblem(optf, [0.2]);
> 
> res = Optimization.solve(optprob, OptimizationOptimJL.LBFGS());
> 
> #Get estimate and then plot against data  
> prob\_fit = remake(prob; p = res.u)
> 
> sol\_fit = solve(  
> prob\_fit,  
> Tsit5();  
> saveat = tdata,  
> abstol = 1e-9,  
> reltol = 1e-9  
> );
> 
> yhat = Array(sol\_fit)[1, :]
> 
> plot(tdata, y\_true, label = “data”);  
> plot!(tdata, yhat, label = “MAP fit”)

Thanks,

DS

---

<div class="post-metadata">

**Author:** ![nshpritz](https://avatars.discourse-cdn.com/v4/letter/n/e99b99/32.png) [@nshpritz](https://discourse.julialang.org/u/nshpritz)\
**Post date:** [February 17, 2026, 3:23pm UTC](https://discourse.julialang.org/t/ode-parameter-estimation-with-priors/135691/2 "2026-02-17T15:23:55Z")

</div>

I can try to recode your example using Turing, but I am not quite sure I understand exactly what you are trying to do. In any event, Turing.jl is a set of packages that includes a probabalistic programming language (PPL) and Markov Chain Monte Carlo machinery which together can be used to specify and compute Bayesian models. The link is to an example using Turing.jl to compute a solution to a Lokta-Volterra problem in the presence of noisy data. I think this is what you are trying to do above, but again, I got lost. [https://turinglang.org/docs/tutorials/bayesian-differential-equations/](https://turinglang.org/docs/tutorials/bayesian-differential-equations/)

---

<div class="post-metadata">

**Author:** ![donkeysaddle](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@donkeysaddle](https://discourse.julialang.org/u/donkeysaddle)\
**Post date:** [February 17, 2026, 5:54pm UTC](https://discourse.julialang.org/t/ode-parameter-estimation-with-priors/135691/3 "2026-02-17T17:54:42Z")

</div>

Hi @nshpritz thanks for taking the time to respond. This looks like a promising lead. Might be exactly what I am looking for. I am trying to tune the parameters of my model to create a “generic model” which can then be adapted to specific instances, or observations, with the help of priors (informed by the “generic model”).

Thanks again! Appreciate it!
