Skip to content

Commit

Permalink
test UKF with non-array u
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Sep 26, 2024
1 parent 0607fa5 commit 4316f5a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ukf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ Rfun(x, u, p, t) -> R
For maximum performance, provide statically sized matrices from StaticArrays.jl
`ny, nu` indicate the number of outputs and inputs.
# Custom type of `u`
The input `u` may be of any type, e.g., a named tuple or a custom struct.
The `u` provided in the input data is passed directly to the dynamics and measurement functions,
so as long as the type is compatible with the dynamics it will work out.
The one exception where this will not work is when calling `simulate`, which assumes that `u` is an array.
"""
function UnscentedKalmanFilter(dynamics,measurement,R1,R2,d0=MvNormal(Matrix(R1)); p = SciMLBase.NullParameters(), nu::Int, ny::Int)
xs = sigmapoints(mean(d0), cov(d0))
Expand Down
9 changes: 9 additions & 0 deletions test/test_ukf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ xT,RT,ll = smooth(resukf, ukf, u, y)
# plot!(reduce(hcat, resukf.xt)', lab="Filter")
# plot!(reduce(hcat, xT)', lab="Smoothed")

## Custom type for u
dynamics(x,u::NamedTuple,p,t) = A*x .+ B*[u.a; u.b]
unt = reinterpret(@NamedTuple{a::Float64, b::Float64}, u)
resukfnt = forward_trajectory(ukf, unt, y)
@test resukf.xt resukfnt.xt
xTnt,RTnt,llnt = smooth(resukfnt, ukf, unt, y)
@test xT xTnt
@test RT RTnt
@test ll llnt

## DAE UKF =====================================================================
"A pendulum in DAE form"
Expand Down

0 comments on commit 4316f5a

Please sign in to comment.