Hello all,
I have been playing around with Stan's ``integrate_ode'' functionality - really nice by the way! I was wondering - how easy would it be to do inference for a PDE model in Stan?
As an example, I have been trying to infer the diffusion parameter for a 1D diffusion equation:
du/dt = D d^2 u / dx^2
where u=u(x,t) measures a population density of some species, and D is the diffusion coefficient. Further, suppose that we know the initial conditions: u(0,t) = f(x), as well as (Dirichlet) boundary conditions: u(x,0) = 0, and u(x,L) = 0. Finally if we assume a normal sampling model about the mean u(x,t), then we have an inference problem.
Typically we would solve this equation by some sort of finite difference method, where we discretise in both x and t. However, if we have a decent integrator, then we should be able to just discretise in distance, and then use the time integrator for each grid point in x. If we use a centralised finite difference approximation for x, then this amounts to integrating:
d v(i,t) / dt = D [v(i+1,t) - 2 v(i,t) + v(i-1,t)] / 2h
where v(i,t) is the approximate solution at grid point i at time t, and h is the step size.
Ideally I was hoping we could use Stan's integrate_ode function for each of the grid points i, to calculate the mean v(i,t), and then use that to increment the log probability by: ~ normal(v(i,t), sigma). At the moment however, I am a little unclear as to how to do this.
My thoughts were that we could essentially do the following at each time step:
vector[T] yHat;
for(i in 1:N){
real y_hat_individual[T,1];
y_hat_individual <- integrate_ode()
}
However, I'm not sure how to write the derivative function (that takes three values of v, and returns a single derivative as per the above finite difference approximation.)
Does anyone have an idea as to how I would do this?
Best,
Ben