An error of `switching_positions.jl`
@bvdmitri @bertdv Thanks for your excellent work! I try to follow the [tutorial](https://reactivebayes.github.io/RxInfer.jl/stable/manuals/migration-guide-v2-v3/) to migrate `switching_positions.jl` to RxInfer v3.5.0. The code is as follows:
```Julia
using LinearAlgebra, RxInfer, Plots, PGFPlotsX
goals = hcat([
# agent 1: start at (0,0) with 0 velocity, end at (0, 50) with 0 velocity
[
[0, 0, 0, 0],
[0, 0, 50, 0]
],
# agent 2: start at (0,50) with 0 velocity, end at (0, 0) with 0 velocity
[
[0, 0, 50, 0],
[0, 0, 0, 0]
]
]...)
radius1 = 15
radius2 = 15
# node specification
struct Halfspace end
@node Halfspace Stochastic [out, a, σ2, γ]
# rule specification
@rule Halfspace(:out, Marginalisation) (q_a::PointMass, q_σ2::PointMass, q_γ::PointMass) = begin
return NormalMeanVariance(mean(q_a) + mean(q_γ) * mean(q_σ2), mean(q_σ2))
end
@rule Halfspace(:σ2, Marginalisation) (q_out::UnivariateNormalDistributionsFamily, q_a::PointMass, q_γ::PointMass, ) = begin
return PointMass( 1 / mean(q_γ) * sqrt(abs2(mean(q_out) - mean(q_a)) + var(q_out)))
end
function h(y1, y2; r1 = radius1, r2 = radius2)
return norm(y1 - y2) - r1 - r2
end;
@model function switching_model(goals, nr_steps, γ, ΔT)
# transition model
A = Matrix([1 ΔT 0 0; 0 1 0 0; 0 0 1 ΔT; 0 0 0 1])
B = Matrix([0 0; ΔT 0; 0 0; 0 ΔT])
C = Matrix([1 0 0 0; 0 0 1 0])
# observations
local y
# single agent models
for k in 1:2
# prior on state
x[k, 1] ~ MvNormalMeanCovariance(zeros(4), 1e2I)
for t in 1:nr_steps
# prior on controls
u[k,t] ~ MvNormalMeanCovariance(zeros(2), 1e-2I)
# state transition
x[k, t+1] ~ A * x[k,t] + B * u[k,t]
# observation model
y[k, t] ~ C * x[k, t+1]
end
# goal priors (indexing reverse due to definition)
goals[1,k] ~ MvNormalMeanCovariance(x[k, 1], 1e-5I)
goals[2,k] ~ MvNormalMeanCovariance(x[k, nr_steps + 1], 1e-5I)
end
# multi-agent models
for t = 1:nr_steps
# observation constraint
σ2[t] ~ GammaShapeRate(3/2, γ^2/2)
d[t] := h(y[1, t], y[2, t])
d[t] ~ Halfspace(0, σ2[t], γ)
end
end;
@constraints function switching_constraints()
q(d, σ2) = q(d)q(σ2)
end;
switching_meta = @meta begin
h() -> Linearization()
end;
@initialization function my_init()
q(σ2) = repeat([PointMass(1)], nr_steps)
q(u) = repeat([PointMass(0)], nr_steps)
μ(x) = MvNormalMeanCovariance(randn(4), 100I)
end
nr_iterations = 1000
nr_steps = 50
results = infer(
model = switching_model(nr_steps = nr_steps, γ = 1, ΔT = 1),
data = ( goals = goals, ),
constraints = switching_constraints(),
meta = switching_meta,
iterations = nr_iterations,
returnvars = KeepLast(),
initialization = my_init()
)
```
Then I got the error:
```Bash
`ProductOf` object cannot be used as a functional form in inference backend. Use form constraints to restrict the functional form of marginal posteriors.
```
Could you give me some suggestions to solve the problem? And are there any publications related to this repo ? Thanks a lot!
关闭于 2024-09-20 14 条评论