NeuralPDE.jl icon indicating copy to clipboard operation
NeuralPDE.jl copied to clipboard

Embedding arrays into NeuralPDE differential equations

Open francescocalisto opened this issue 3 years ago • 8 comments

There is currently no way to use an array-derived quantity in a NeuralPDE differential equation.

This is an example:

dx = 0.05
dy = 0.05
xwidth   = 10.0    
ywidth   = 10.0
xs = -xwidth*0.5: dx : xwidth*0.5
ys = -ywidth*0.5: dy : ywidth*0.5
xGradMatrix = rand(length(xs),length(ys))  #rand for explainatory purpose
yGradMatrix = rand(length(xs),length(ys))
getDxz(x,y) = xGradMatrix[convert(Int64,x/dx), convert(Int64,y/dy)]
getDyz(x,y) = yGradMatrix[convert(Int64,x/dx), convert(Int64,y/dy)]
S = x^2 * getDxz(x,y) + 3.2 * getDyz(x,y)
eq = Dt(u(t,x,y,θ)) + S*gn ~ 0  

This doesn’t work at the moment. What one should be able to do is to get values from xGradMatrix and yGradMatrix as a function of the position.

francescocalisto avatar Nov 17 '20 09:11 francescocalisto

@KirillZubov do you know of any updates on this issue? I was just trying to understand what the underlying problem was with including intermediate expressions in one of the system equations?

00krishna avatar Aug 04 '21 17:08 00krishna

so as we generate data inside, that means that every iteration it new set of data of random, quasi-random number, adaptive quadrature's adaptively selects the set and the size of the set may be different on a new iteration https://neuralpde.sciml.ai/dev/solvers/pinns/#Training-strategy and we can't just input data in general, it should be respected to variables - x,y

not work:

data = rand(2,10)
eq = u(x,y) ~ data

it can be work like some interpolation, but probably it bad idea

function data(x,y)
     size_ = size(vcat(x,y) )   
     generate_own_data(size_)
end
@register  data(x,y)
eq = u(x,y) ~ data(x,y)

so if you have a function with respect to variable f(x,y), so just use it if it isn't Symbolic, so use @register f(x,y)

probably the best way to insert data is additional_loss. there is the example with parameter estimation I try to add all this in docs in the next update that will soon

KirillZubov avatar Aug 05 '21 15:08 KirillZubov

probably I think it is a bad idea to inject data in a high level of eq. to use the additional loss is best. And probably the issue can be close

mention @ChrisRackauckas

KirillZubov avatar Aug 05 '21 15:08 KirillZubov

Yeah, is the data actually part of the model or the training process? Those are two different things, and I think this issue is just from confusing the two. For this kind of thing, instead it would be better to directly solve the stochastic PDE, which isn't something we can do right now but is better than solving for a specific random number sequence.

ChrisRackauckas avatar Aug 05 '21 15:08 ChrisRackauckas

it will be cool to have an example with ground-truth data, like interpolating some operator in pde from real-world data. but the big question is how to connect it together math + data, inside neuralpde some effective way.

KirillZubov avatar Aug 05 '21 15:08 KirillZubov

You just define an appropriate additional loss term.

ChrisRackauckas avatar Aug 05 '21 15:08 ChrisRackauckas

I am trying to understand how I can help with this, @ChrisRackauckas @KirillZubov ? In the case of this particular problem, the case is wildfire spread. So there is a 2 dimensional array where each pixel represents the fuel available to the fire. So since this is a level set problem, the boundary will evolve probably in proportion to the curvature at each mesh point and the fuel available at each mesh point.

I see 2 problems here:

  1. How to estimation the parameters of the level set equation from some front propagation data plus the fuel array?
  2. How to simulate the propagation of the front given some parameter values and the fuel data array?

For solving the stochastic PDE is that something that we can approach with a MOL discretization and then evolve the time domain with an SDE solver? Or is that like the naive path and it leads to disaster and ruin.

Problem 1: estimation The parameter estimation tutorial shows how given a system of equations and some data, how to optimize the parameters by minimizing loss. So we would update the additional loss function to include both the actual front propagation points and the predicted propagation point, AND the fuel data array. So we would need to include the set of propagation points and the fuel values at each point in the vector comprehension.

Problem 2: simulation BUT, here is the bigger question. So what if I have no ground truth front propagation points and I just have the fuel data. So given a set of parameters, I want to simulate the solution to this equation forward in time. So now I would have to find a way to give the fuel data array to the ODE or SDE solver right. That seems to be the missing thing. Is there a way to propagate the front using the parameter estimation routine? Seems like something like the fuel array I could pass as an initial condition to the solver, and then the solver should know what to do with it. This seems to be where @KirillZubov was going with using the @register macro.

So it seems like problem 1 we can deal with through parameter estimation, but problem 2 is still a question.

00krishna avatar Aug 06 '21 05:08 00krishna

If it's not just a loss term, then turn the data into a function using an interpolation and register the interpolation.

ChrisRackauckas avatar Aug 06 '21 09:08 ChrisRackauckas