# Understanding few lines from NeuralPDE.jl PDE example (phi solution)

**URL:** <https://discourse.julialang.org/t/understanding-few-lines-from-neuralpde-jl-pde-example-phi-solution/101499>\
**Category:** Machine Learning\
**Created:** [July 11, 2023, 10:45pm UTC](https://discourse.julialang.org/t/understanding-few-lines-from-neuralpde-jl-pde-example-phi-solution/101499 "2023-07-11T22:45:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)\
**Post date:** [July 11, 2023, 10:45pm UTC](https://discourse.julialang.org/t/understanding-few-lines-from-neuralpde-jl-pde-example-phi-solution/101499/1 "2023-07-11T22:45:10Z")

</div>

Hi all,  
first time I’m trying to use PINNs with Julia, as I’m reading the docs there are some parts that I’m missing.  
In this [example](https://neuralpde.sciml.ai/stable/tutorials/pdesystem/) :

I see that the lines used for the predictions are:

```julia
phi = discretization.phi
u_predict = reshape([first(phi([x,y],res.u)) for x in xs for y in ys],(length(xs),length(ys)))

```

However, in this [example](https://neuralpde.sciml.ai/stable/examples/linear_parabolic/), the predictions are calculated like this:

```julia
phi = discretization.phi
depvars = [:u,:w]
minimizers_ = [res.u.depvar[depvars[i]] for i in 1:length(chain)]
u_predict = [[phi[i]([t,x], minimizers_[i])[1] for t in ts for x in xs] for i in 1:2]

```

Can someone explain to me the difference between the two `u_predict` lines? I’m not sure I’m following just by reading the docs.  
My other question is about the `phi` object, what does it contain exactly? Is it the trained network?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 14, 2023, 1:02pm UTC](https://discourse.julialang.org/t/understanding-few-lines-from-neuralpde-jl-pde-example-phi-solution/101499/2 "2023-07-14T13:02:54Z")

</div>

> [@PeX](#):
>
> Can someone explain to me the difference between the two `u_predict` lines? I’m not sure I’m following just by reading the docs.

It’s a difference between whether it’s a system of equations (array of neural networks) or a single equation (thus it’s just a neural network directly).

> [@PeX](#):
>
> My other question is about the `phi` object, what does it contain exactly? Is it the trained network?

It’s the neural network you passed but munged to directly represent the PDE solution. So `phi[i]([t,x])` is equal to `u[i](t,x)` when trained for a multi-dimensional system, and for a single dimensional system it’s just `phi(t,x)`.

---

<div class="post-metadata">

**Author:** ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)\
**Post date:** [July 16, 2023, 10:05pm UTC](https://discourse.julialang.org/t/understanding-few-lines-from-neuralpde-jl-pde-example-phi-solution/101499/3 "2023-07-16T22:05:20Z")

</div>

Thank you so much!  
Can you please share why `[1]` or `first` is used when calling `phi[i]([t,x], minimizers_[i])[1]`? What does the first index represent?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 16, 2023, 11:58pm UTC](https://discourse.julialang.org/t/understanding-few-lines-from-neuralpde-jl-pde-example-phi-solution/101499/4 "2023-07-16T23:58:24Z")

</div>

The first NN
