From 99f6da88bd1dd4d69045252204dbde0174af403c Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Mon, 25 Nov 2024 13:01:01 +0100 Subject: [PATCH] more robust detection of inplace measurement for MeasurementOop --- Project.toml | 2 +- docs/src/neural_network.md | 8 ++++---- src/kalman.jl | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 6fd96fe..7f82ec5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LowLevelParticleFilters" uuid = "d9d29d28-c116-5dba-9239-57a5fe23875b" authors = ["baggepinnen "] -version = "3.10.0" +version = "3.10.1" [deps] DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" diff --git a/docs/src/neural_network.md b/docs/src/neural_network.md index 30229b6..a66a773 100644 --- a/docs/src/neural_network.md +++ b/docs/src/neural_network.md @@ -149,8 +149,8 @@ ukf = UnscentedKalmanFilter(dynamics, measurement, R1, R2, SimpleMvNormal(s0, 10 @time sole = forward_trajectory(ekf, data.u, data.x) @time solu = forward_trajectory(ukf, data.u, data.x) -plot(sole, plotx=false, plotxt=false, plotyh=true, plotyht=false, plotu=false, plote=true, name="EKF", layout=(nx, 1)) -plot!(solu, plotx=false, plotxt=false, plotyh=true, plotyht=false, plotu=false, plote=true, name="UKF", ploty=false, size=(1200, 1500)) +plot(sole, plotx=false, plotxt=false, plotyh=true, plotyht=false, plotu=false, plote=true, name="EKF", layout=(nx, 1), size=(1200, 1500)) +plot!(solu, plotx=false, plotxt=false, plotyh=true, plotyht=false, plotu=false, plote=true, name="UKF", ploty=false) DisplayAs.PNG(Plots.current()) # hide ``` @@ -180,12 +180,12 @@ Performing the estimation using the Extended Kalman Filter took ```julia using BenchmarkTools @btime forward_trajectory(ekf, data.u, data.x); - 46.034 ms (77872 allocations: 123.45 MiB) + # 46.034 ms (77872 allocations: 123.45 MiB) ``` and with the Unscented Kalman Filter ```julia @btime forward_trajectory(ukf, data.u, data.x); - 142.608 ms (2134370 allocations: 224.82 MiB) + # 142.608 ms (2134370 allocations: 224.82 MiB) ``` The EKF is a bit faster, which is to be expected. Both methods are very fast from a neural-network training perspective, but the performance will not scale favorably to very large network sizes. diff --git a/src/kalman.jl b/src/kalman.jl index 2037f9c..70a895e 100644 --- a/src/kalman.jl +++ b/src/kalman.jl @@ -122,7 +122,7 @@ end function (kfm::MeasurementOop)(x,u,p,t) kf = kfm.kf mfun = measurement(kf) - if has_ip(mfun) + if kf isa UnscentedKalmanFilter{<:Any,true} || kf isa ExtendedKalmanFilter{<:Any,true} y = zeros(kf.ny) mfun(y,x,u,p,t) return y