Skip to content

Commit 82fbd4c

Browse files
committed
debug: UnscentedKalmanFilter undesired variable overwrite
1 parent 5d1d633 commit 82fbd4c

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/estimator/kalman.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -682,11 +682,10 @@ function correct_estimate!(estim::UnscentedKalmanFilter, y0m, d0)
682682
nx̂ = estim.nx̂
683683
γ, m̂, Ŝ = estim.γ, estim.m̂, estim.
684684
# in-place operations to reduce allocations:
685-
sqrtP̂ = LowerTriangular(estim.buffer.P̂)
686-
P̂_temp = Hermitian(estim.buffer.Q̂, :L)
685+
P̂_temp = Hermitian(estim.buffer.P̂, :L)
687686
P̂_temp .=
688-
P̂_chol = cholesky!(P̂_temp) # also modifies P̂_temp
689-
sqrtP̂ .= P̂_chol.L
687+
P̂_chol = cholesky!(P̂_temp) # also modifies P̂_temp
688+
sqrtP̂ = P̂_chol.L
690689
γ_sqrtP̂ = lmul!(γ, sqrtP̂)
691690
X̂0, Ŷ0m = estim.X̂0, estim.Ŷ0m
692691
X̂0 .= x̂0
@@ -779,11 +778,10 @@ function update_estimate!(estim::UnscentedKalmanFilter, y0m, d0, u0)
779778
γ, m̂, Ŝ = estim.γ, estim.m̂, estim.
780779
x̂0next, û0 = estim.buffer.x̂, estim.buffer.
781780
# in-place operations to reduce allocations:
782-
sqrtP̂corr = LowerTriangular(estim.buffer.P̂)
783-
P̂corr_temp = Hermitian(estim.buffer.Q̂, :L)
781+
P̂corr_temp = Hermitian(estim.buffer.P̂, :L)
784782
P̂corr_temp .= P̂corr
785-
P̂corr_chol = cholesky!(P̂corr_temp) # also modifies P̂corr_temp
786-
sqrtP̂corr .= P̂corr_chol.L
783+
P̂corr_chol = cholesky!(P̂corr_temp) # also modifies P̂corr_temp
784+
sqrtP̂corr = P̂corr_chol.L
787785
γ_sqrtP̂corr = lmul!(γ, sqrtP̂corr)
788786
X̂0corr .= x̂0corr
789787
X̂0corr[:, 2:nx̂+1] .+= γ_sqrtP̂corr
@@ -794,17 +792,16 @@ function update_estimate!(estim::UnscentedKalmanFilter, y0m, d0, u0)
794792
@views f̂!(X̂0next[:, j], û0, estim, estim.model, x̂0corr, u0, d0)
795793
end
796794
x̂0next .= mul!(x̂0corr, X̂0next, m̂)
797-
X̄0next = X̂0next
795+
X̄0next = estim.X̄0
798796
X̄0next .= X̂0next .- x̂0next
799-
P̂next = P̂corr
800797
Ŝ_X̄0nextᵀ = estim.X̂0'
801798
mul!(Ŝ_X̄0nextᵀ, Ŝ, X̄0next')
802799
P̂next = estim.buffer.
803800
mul!(P̂next, X̄0next, Ŝ_X̄0nextᵀ)
804801
P̂next .+=
805802
x̂0next .+= estim.f̂op .- estim.x̂op
806803
estim.x̂0 .= x̂0next
807-
estim.P̂ .= P̂next
804+
estim.P̂ .= Hermitian(P̂next, :L)
808805
return nothing
809806
end
810807

0 commit comments

Comments
 (0)