Hello everyone! I am new to Julia and currently working on a project that involves using neural networks to describe geodesics around a black hole. I am encountering an error ‘type Array has no field layer_1,’ and I am unsure how to resolve it. I would appreciate your help to solve the problem. Please find part of my code below.
The neural network architecture
NN_chiphi = 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],
Dense(9, 32, tanh),
Dense(32, 2))
NN_chiphi_params, st_chiphi = Lux.setup(Xoshiro(), NN_chiphi)
params_chiphi = ComponentArray{Float64}(NN_chiphi_params)
nn_model_chiphi = StatefulLuxLayer(NN_chiphi, st_chiphi)
NN_pe = 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]],
Dense(9, 32, tanh),
Dense(32, 2))
NN_pe_params, st_pe = Lux.setup(Xoshiro(), NN_pe)
params_pe = ComponentArray{Float64}(NN_pe_params)
nn_model_pe = StatefulLuxLayer(NN_pe, st_pe)
NN_params = vcat(params_chiphi, params_pe)
NN_paramsf = ComponentArray{Float64}(NN_pe_params)
l1 = length(params_chiphi)
The system of differential equations
function AbstractNROrbitModel(u, model_params, t; NN_chiphi=nothing, params_chiphi=nothing, NN_pe=nothing, params_pe=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, params_chiphi)
end
if isnothing(NN_pe)
nn_pe = [0,0]
else
nn_pe = NN_pe(u, params_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
AbstractNROrbitModel (generic function with 1 method)
function ODE_model(u, NN_paramsf, t)
NN_params1 = NN_paramsf[1:l1]
NN_params2 = NN_paramsf[l1+1:end]
du = AbstractNROrbitModel(u, model_params, t, NN_chiphi=nn_model_chiphi, params_chiphi=NN_params1,
NN_pe=nn_model_pe, params_pe=NN_params2)
return du
end
ODE_model (generic function with 1 method)
prob_nn = ODEProblem(ODE_model, u0, tspan, NN_paramsf)
soln_nn = Array(solve(prob_nn, RK4(), u0 = u0, p = NN_paramsf, saveat = tsteps, dt = dt, adaptive=false))
type Array has no field layer_1
If you required more information or the files, let me know.
Best regards