I was trying to set up a sequential learning problem as follows:
using Flux, DiffEqFlux
using DifferentialEquations
using Random
ndata= 11;
tspan = (0.0f0, 1.0f0);
tdata = range(tspan[1], tspan[2], length = ndata);
a = Float32(2.);
u0 = Float32[1.]
function f!(du, u, p, t)
du .= -a * u;
end
ode_prob = ODEProblem(f!, u0, tspan)
n = 10^2;
Random.seed!(100)
u0data = randn(Float32, n);
function ic_func(prob, i, repeat)
remake(prob, u0=[u0data[i]])
end
ensemble_prob = EnsembleProblem(ode_prob, prob_func = ic_func)
ensemble_soln = solve(ensemble_prob, Tsit5(),trajectories = n,saveat=tdata);
ensemble_sum = EnsembleSummary(ensemble_soln);
ode_data = Array(ensemble_soln);
Random.seed!(200)
f_nn = FastChain(FastDense(1,20,tanh),FastDense(20,1));
p = initial_params(f_nn);
n_ode = NeuralODE(f_nn, tspan, Tsit5(), saveat = tdata);
train_data = zip(u0data, ode_data);
function predict(u0_)
Array(n_ode(u0_, p))
end
function loss(u_, u0_)
pred = predict(u0_)
sum(abs2, u_ .- pred)
end
opt=ADAM(0.05)
Flux.train!(loss, Flux.params(p), train_data, opt)
If I check this code, before training everything appears to work (i.e., the loss and predict functions execute without error). But trying to train it produces the error:
I was trying to set up a sequential learning problem as follows:
If I check this code, before training everything appears to work (i.e., the
loss
andpredict
functions execute without error). But trying to train it produces the error: