# Modified the neural network to capture nonlinear system

**URL:** <https://discourse.julialang.org/t/modified-the-neural-network-to-capture-nonlinear-system/101789>\
**Category:** General Usage\
**Tags:** question, neural-network, nonlinearsolve\
**Created:** [July 19, 2023, 4:09pm UTC](https://discourse.julialang.org/t/modified-the-neural-network-to-capture-nonlinear-system/101789 "2023-07-19T16:09:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)\
**Post date:** [July 19, 2023, 4:09pm UTC](https://discourse.julialang.org/t/modified-the-neural-network-to-capture-nonlinear-system/101789/1 "2023-07-19T16:09:27Z")

</div>

I tried to use NeuralPDE to solve ODE problem and my code is below:

```julia
domains = [t ∈ Interval(0.0,25.0)]

chain =[Lux.Chain(Dense(1,10,Lux.tanh),Dense(10,20,Lux.tanh),Dense(20,10,Lux.tanh),Dense(10,1)) for _ in 1:12]

dvs = [delta1(t),delta2(t),delta3(t),omega1(t),omega2(t),omega3(t),TM1(t),TM2(t),TM3(t),Psv1(t),Psv2(t),Psv3(t)]

@named pde_system = PDESystem(eqs,bcs,domains,[t],dvs)

strategy = NeuralPDE.GridTraining(0.01)
discretization = PhysicsInformedNN(chain, strategy, additional_loss = NeuralPDE.GradientScaleAdaptiveLoss(20), adaptive_loss = NeuralPDE.GradientScaleAdaptiveLoss(20))
sym_prob = NeuralPDE.symbolic_discretize(pde_system, discretization)

pde_loss_functions = sym_prob.loss_functions.pde_loss_functions
bc_loss_functions = sym_prob.loss_functions.bc_loss_functions

callback = function (p, l)
    println("loss: ", l)
    return false
end
loss_functions = [pde_loss_functions;bc_loss_functions]

function loss_function(θ,p)
    sum(map(l->l(θ) ,loss_functions))
end

f_ = OptimizationFunction(loss_function, Optimization.AutoZygote())
prob = Optimization.OptimizationProblem(f_, sym_prob.flat_init_params);
phi = sym_prob.phi;

```

I got the result for the phase angle from the NeuralPDE and the classical method as follows:  
NeuralPDE  
 ![phase angle](https://global.discourse-cdn.com/julialang/original/3X/2/f/2f13c2262e057ceb95a83eab9faec863fb17277f.png)  
Classical method  
 ![phase](https://global.discourse-cdn.com/julialang/original/3X/4/c/4cc2a1ea566433637a7eae047c46275efe949e92.jpeg)

When I compared the result from NeuralPDE with the results from the classical method I think it was good for the first 5 seconds. But the NeuralPDE can not capture the problem after 5 seconds, although I have set the time domains is 25 seconds. (I also try to set the domains longer but got the same results).  
Please help me with how could I modify the NeuralPDE to expand the network to hold time domains.  
Thank you all.

---

<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 19, 2023, 6:19pm UTC](https://discourse.julialang.org/t/modified-the-neural-network-to-capture-nonlinear-system/101789/2 "2023-07-19T18:19:15Z")

</div>

Can you open an issue? This would be a good test case for something like adaptive reweighing.

---

<div class="post-metadata">

**Author:** ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)\
**Post date:** [July 19, 2023, 6:36pm UTC](https://discourse.julialang.org/t/modified-the-neural-network-to-capture-nonlinear-system/101789/3 "2023-07-19T18:36:46Z")

</div>

I am sorry, I do not know what you mean. You asked me that have I solved it or do you want me to open the issue? (make as having solution)

---

<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 20, 2023, 6:34pm UTC](https://discourse.julialang.org/t/modified-the-neural-network-to-capture-nonlinear-system/101789/4 "2023-07-20T18:34:29Z")

</div>

I want you to open an issue on NeuralPDE.jl so someone can take a deeper look.

---

<div class="post-metadata">

**Author:** ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)\
**Post date:** [July 20, 2023, 7:07pm UTC](https://discourse.julialang.org/t/modified-the-neural-network-to-capture-nonlinear-system/101789/5 "2023-07-20T19:07:52Z")

</div>

I have created a new issue on NeuralPDE.jl GitHub.
