Dear all, I am beginner in this topic and trying to solve simple y’=y (analytical solution: exp(t)) with y0=0 by modifying code on Neural Ordinary Differential Equations · DiffEqFlux.jl (sciml.ai), my code until now:
begin
# NeuralODE
u01 = Float32[2.; 0.]
n_samples = 16
tspan1 = (0.0f0, 1.0f0)
function trueODEfunc(du, u, p, t)
true_A = [-0.1 2.0; -2.0 -0.1]
du .= ((exp(t))'true_A)'
end
t = range(tspan1[1], tspan1[2], length=n_samples)
prob = DiffEqFlux.ODEProblem(trueODEfunc, u01, tspan1)
ode_data = Array(solve(prob, Tsit5(), saveat=t))
model = Chain(
x -> exp(t),
Dense(2, 50, tanh),
Dense(50, 2),
)
n_ode = NeuralODE(model, tspan1, Tsit5(), saveat=t, reltol=1e-7, abstol=1e-9)
ps1 = Flux.params(n_ode)
loss_n_ode() = sum(abs2, ode_data .- n_ode(u01))
data = Iterators.repeated((), 25) # epochs
Flux.train!(loss_n_ode, ps1, data, ADAM(0.1))
pred = n_ode(u01)
traces = [
scatter(x=t, y=ode_data[1, :], name="u_1", mode="lines+markers"),
scatter(x=t, y=ode_data[2, :], name="u_2", mode="lines+markers"),
scatter(x=t, y=pred[1, :], name="u_1 pred", mode="lines+markers"),
scatter(x=t, y=pred[2, :], name="u_2 pred", mode="lines+markers"),
]
plt = plot(traces)
end
of course it throws error but am unable to understand the setup, does anybody has idea how to start to structure the code correctly? thank you in advance