DiffEqFlux “boundary” value problem

After reading through a handful of DiffEqFlux examples, I’m really interested in how I might be able to apply it to a research question of mine measuring wind and temperature over glaciers. I have to solve this as a boundary value problem.

For sake of example and to be consistent with the existing documentation of the LV problem, pretend I have a system of differential equations for x(t) and y(t) representing rabbit and wolf populations. I model them as:
x’(t) = a x + U_1(x,y,t)
y’(t) = -d y + U_2(x,y,t)

Where the UODE is solved using measured wolf and rabbit population data. In all the examples I have seen, these data are collected at the same time.

However, unlike in the examples, say I can only measure rabbit populations every 3 years and wolf populations every 2 years (except at year 0), so I have data at:
x(t=0,t=3,t=6,t=9,…) and y(t=2,t=4,t=6,t=8,…).
Or, what if I could only measure the rabbit populations but was never able to measure the wolf population?

The Universal Differential Equations for Scientific Machine Learning paper says that universal boundary value problems are solvable with this method, but I haven’t seen an example of it and my attempts to implement this have only been met with errors. Does anyone have any insight on how to do this or if it is even possible?

You can set the timepoints to be collected with the saveat keyword. Probably you could accumulate the error of the corresponding variable in your cost function just by ignoring the other variable per timepoint as required.

If you have tried this and have errors, why not post the code? People might be able to identify the problem.

More generally, DiffEqFlux doesn’t have or need any particular treatment for boundary value problems. All it cares about is minimizing a loss function that you define, with respect to some parameters that you define. If you have only periodic samples of wolf and rabbit populations, are you using that data in your loss function? A good example is parameter estimation of Lotka-Volterra, where the loss function is shown here:

function loss(p)
  sol = solve(prob, Tsit5(), p=p, saveat = tsteps)
  loss = sum(abs2, sol.-1) # <-- probably want to replace this
  return loss, sol
end

You can see that it’s solving the ODE and minimizing the squared deviation of the solution from unity, as it’s trying to find the parameters that yield a constant unity solution. Sounds like your loss could instead be the squared deviations of the respective rabbits from your rabbit data. You can access the state at a specific time point t=3 with sol(3). If you only want one element, you can extract that as an array element, e.g. sol(3)[1]. And add up separate loss components for each population. Or maybe only samples of rabbits data. I could be misinterpreting what you want to do, so helpful if you can post what you tried.

2 Likes

Indeed @apo383 is right, and I posted on StackOverflow the same thing:

https://stackoverflow.com/questions/68291864/julia-differential-algebraic-equation-as-a-boundary-value-problem/68330824#68330824

A boundary value problem is just an inverse problem, typically with respect to the initial condition. But if you want to do parameter estimation at the same time, just optimize both. DiffEqFlux will just differentiate and optimize both, which is shown in like 10 of the tutorials. So just put the boundary values you want into the loss function and it will do it.

1 Like