Hello,
I´m trying to fit a dynamic system (a hammerstein system, implemented below) with an exogenous input via DiffEqFlux, but actually I don´t know how to put the input excitation into the n-ode-problem. I first tried to follow the example:
https://diffeqflux.sciml.ai/dev/examples/neural_ode_sciml/
Example 3: Solving Nonhomogeneous Equations using Parameterized Functions,
but I wasn´t able to transfer it to my application. I posted below my attempt. Maybe someone could tell me what I´m doing wrong?
# intialization
using DifferentialEquations, Flux, Optim, DiffEqFlux, DiffEqSensitivity, Plots
# excitation of the system
no_samples = 100
sample_period = 0.1
tsteps = collect(sample_period:sample_period:(no_samples-1)*sample_period)
tspan = (Float32(tsteps[1]), Float32(tsteps[end]))
ex = t->sin(t)
u = ex.(tsteps)
# system
f(x) = (atan(8.0 * x - 4.0) + atan(4.0)) / (2.0 * atan(4.0))
function hammerstein_system(u::Array{Float64})
y= zeros(size(u))
for k in 2:length(u)
y[k] = 0.2 * f(u[k-1]) + 0.8 * y[k-1]
end
return y
end
# system output
y = hammerstein_system(ex.(tsteps))
# model setup
nn_model = FastChain(FastDense(1,50, sigmoid), FastDense(50, 1))
#intial parameter of the model
p_model = initial_params(nn_model)
function predict_neuralode(p)
Array(prob_neuralode(u0, p))
end
function dudt(du, u, p, t)
du[1] = nn_model(ex(t))[1]
end
prob_neuralode = NeuralODE(dudt, tspan, Tsit5(), saveat = tsteps)
prob_neuralode(0.0, p_model)