Chris, thank you so much for taking the time to answer my question. There has been an improvement, and I followed your suggestion, but now I have the problem MethodError: no method matching +(::Int64, ::Vector{Float64}). For element-wise addition, use broadcasting with dot syntax: scalar .+ array.
This is the current state of the code (with your suggestion)
## Define neural network chi and phi
NN_chiphi = Lux.Chain((x) -> [cos(x[1]),1/abs(x[3]),1/sqrt(abs(x[3])),sqrt(abs(x[3])),x[3],sqrt(abs(x[3]))^3,x[3]^2,x[4],x[4]^2],
Lux.Dense(9, 32, tanh),
Lux.Dense(32, 2))
p_chiphi, st_chiphi = Lux.setup(rng, NN_chiphi)
NN_chiphi_params = ComponentArray{Float64}(p_chiphi)
## Define neural network p and e
NN_pe = Lux.Chain((x) -> [1/sqrt(abs(x[3]))^3,1/abs(x[3]),1/sqrt(abs(x[3])),sqrt(abs(x[3])),x[3],sqrt(abs(x[3]))^3,x[3]^2,x[4],x[4]^2,x[3]*x[4]],
Lux.Dense(10,32, tanh),
Lux.Dense(32,2))
p_pe, st_pe = Lux.setup(rng, NN_pe)
NN_pe_params = ComponentArray{Float64}(p_pe)
# Neural Networks parameters
NN_params = ComponentArray(NN_params1 = NN_chiphi_params, NN_params2 = NN_pe_params)
# The PINN model
function AbstractNROrbitModel(u, model_params, t; NN_chiphi=nothing, NN_chiphi_params=nothing,NN_pe=nothing, NN_pe_params=nothing)
χ, ϕ, p, e = u
q = model_params[1]
M = 1.0
if p <= 0
println("p = ", p)
end
if isnothing(NN_chiphi)
nn_chiphi = [1, 1]
else
nn_chiphi = 1 .+ NN_chiphi(u, NN_chiphi_params, st_chiphi)
end
if isnothing(NN_pe)
nn_pe = [0, 0]
else
nn_pe = NN_pe(u, NN_pe_params, st_pe)
end
numer = (1 + e * cos(χ))^2
denom = M * (abs(p)^(3 / 2))
χ̇ = (numer / denom) * nn_chiphi[1]
ϕ̇ = (numer / denom) * nn_chiphi[2]
ṗ = nn_pe[1]
ė = nn_pe[2]
return [χ̇, ϕ̇, ṗ, ė]
end
function ODE_model(u, NN_params, t)
NN_params1 = NN_params.NN_params1
NN_params2 = NN_params.NN_params2
du = AbstractNROrbitModel(u, model_params, t, NN_chiphi=NN_chiphi, NN_chiphi_params=NN_params1, NN_pe=NN_pe, NN_pe_params=NN_params2)
return du
end
prob_nn = ODEProblem(ODE_model, u0, tspan, NN_params)
soln_nn = Array(solve(prob_nn, RK4(), u0 = u0, p = NN_params, saveat = tsteps, dt = dt, adaptive=false))
MethodError: no method matching +(::Int64, ::Vector{Float64})
For element-wise addition, use broadcasting with dot syntax: scalar .+ array
If you need more information or my file, please let me know. I truly appreciate your help with the problem.
Kind regards
Jose