Hi
I am recreating the drone example from https://github.com/ReactiveBayes/RxInferExamples.jl/blob/main/drone/drone_simulation.ipynb. It occured to me, that the plot/animation is based on the models posteriors. Does this actually match reality?
begin
traj = [collect(get_state(start))]
#simulate drone based on actions
for i in 1:40
action = mean(results.posteriors[:u][i])
new_state = state_transition(traj[i], action, drone, env, dt)
push!(traj, new_state)
end
@gif for k in 1:length(traj)-1
# plot target
p = scatter([target[1]], [target[2]], label = "target"; color = :red)
#plot drone
plot_drone!(p, drone, State(traj[k]...))
xlims!(-2.5, 1.5)
ylims!(-1.5, 1.5)
end
end
Uh oh, that’s unexpected. Does anyone have any idea what’s going on? Since the model has full visibility of the state, my understanding is that its prediction should match reality pretty closely.
My analysis
First, a side note: it seems to me that the line Ď„ = (Fl - Fr) * r
in the function state_transition
should have been Ď„ = (Fr - Fl) * r
to match the sign convention of sin
and cos
. This doesn’t affect the results as it simply swaps the labels of left and right engine, I just want to remove it as a source of confusion.
Looking into the posteriors of the angle and angular velocity, it seems the model approximates the angular velocity pretty well:
plot((d -> d[end]).(traj), label = "Actual")
plot!((d -> mean(d)[end]).(results.posteriors[:s]), label = "Posterior")
And the resulting integral (which should be the angle of the drone) looks very similar
plot(cumsum((d -> d[end]).(traj)), label = "Actual")
plot!(cumsum((d -> mean(d)[end]).(results.posteriors[:s])), label = "Posterior")
However, the models prediction of the angle is wildly off:
plot(((d -> d[end-1]).(traj)), label = "Actual")
plot!(((d -> mean(d)[end-1]).(results.posteriors[:s])), label = "Posteriors")
Note, that the integral of the posterior of the angular velocity is far away from the posterior of the drone angle.
It seems to underestimate the size of the peak of the angular velocity. Since angular velocity depends linearly on the forces but the drone angle depends non-linearly on the forces, this leads me to wonder if some (linear?) approximation somewhere is messing things up.
Any thoughts are most welcome.