Hi,
I’m getting sometimes the same predictions result of my node model for different parameter vectors despite that the neural network return different outputs for the different parameter vectors. Can somebody tell me what I’ve done wrong?
test nn output
nn_output1= nn_model(vcat(u0[1], u0[2], vec(ex[Int(round(10.0 * 0.1)), :])) , p_ini)
nn_output2 = nn_model(vcat(u0[1], u0[2], vec(ex[Int(round(10.0 * 0.1)), :])) , p_test)
# node output
y_model1 = predict_neuralode_rk4(p_ini)
y_model2 = predict_neuralode_rk4(p_test)
p_ini == p_test => false
nn_output1==nn_output2 => false
y_model1 == y_model2 => true
Complete code:
using DifferentialEquations, DiffEqFlux
# excitation and response data
ex = rand(Float32, 38, 4)
y = rand(Float32, 2, 38)
# Initial condition
u0 = [y[1,1], y[2,1]]
idxs = [size(ex, 1)]
sim_start = 1
sim_length = idxs[1]
tspan = (Float32(sim_start*0.1), Float32(sim_length*0.1))
tsteps = range(tspan[1], tspan[2], length = sim_length-sim_start+1)
nn_model = FastChain(FastDense(6,8, sigmoid), FastDense(8, 2))
p_ini = initial_params(nn_model)
nn_model = FastChain(FastDense(6,8, sigmoid), FastDense(8, 2))
p_test = initial_params(nn_model)
# test parameters
p_test==p_ini
# test nn output
nn_output1= nn_model(vcat(u0[1], u0[2], vec(ex[Int(round(10.0 * 0.1)), :])) , p_ini)
nn_output2 = nn_model(vcat(u0[1], u0[2], vec(ex[Int(round(10.0 * 0.1)), :])) , p_test)
nn_output1==nn_output2
## uode
dudt(u, p, t) = nn_model(vcat(u[1], u[2], vec(ex[Int(round(10.0 * t)), :])) , p)
# define ode prob
global prob = ODEProblem(dudt, u0, tspan, nothing)
# prediction function
predict_neuralode_rk4(p) = Array(solve(remake(prob,p=p), RK4(), dt = 0.01, saveat=tsteps, adaptive= false))
y_model1 = predict_neuralode_rk4(p_ini)
y_model2 = predict_neuralode_rk4(p_test)
p_ini == p_test
y_model1 == y_model2