|
96 | 96 | updatestate!(skalmanfilter2, [10, 50], [51, 32])
|
97 | 97 | end
|
98 | 98 | @test skalmanfilter2() ≈ [51, 32] atol=1e-3
|
| 99 | + linmodel3 = LinModel{Float32}(0.5*ones(1,1), ones(1,1), ones(1,1), zeros(1,0), zeros(1,0), 1.0) |
| 100 | + skalmanfilter3 = SteadyKalmanFilter(linmodel3) |
| 101 | + x̂ = updatestate!(skalmanfilter3, [0], [0]) |
| 102 | + @test x̂ ≈ [0, 0] |
| 103 | + @test isa(x̂, Vector{Float32}) |
99 | 104 | @test_throws ArgumentError updatestate!(skalmanfilter1, [10, 50])
|
100 | 105 | end
|
101 | 106 |
|
@@ -152,23 +157,23 @@ end
|
152 | 157 |
|
153 | 158 | @testset "KalmanFilter estimator methods" begin
|
154 | 159 | linmodel1 = setop!(LinModel(sys,Ts,i_u=[1,2]), uop=[10,50], yop=[50,30])
|
155 |
| - lo1 = KalmanFilter(linmodel1) |
156 |
| - @test updatestate!(lo1, [10, 50], [50, 30]) ≈ zeros(4) |
157 |
| - @test updatestate!(lo1, [10, 50], [50, 30], Float64[]) ≈ zeros(4) |
158 |
| - @test lo1.x̂ ≈ zeros(4) |
159 |
| - @test evaloutput(lo1) ≈ lo1() ≈ [50, 30] |
160 |
| - @test evaloutput(lo1, Float64[]) ≈ lo1(Float64[]) ≈ [50, 30] |
161 |
| - @test initstate!(lo1, [10, 50], [50, 30+1]) ≈ [zeros(3); [1]] |
162 |
| - setstate!(lo1, [1,2,3,4]) |
163 |
| - @test lo1.x̂ ≈ [1,2,3,4] |
| 160 | + kalmanfilter1 = KalmanFilter(linmodel1) |
| 161 | + @test updatestate!(kalmanfilter1, [10, 50], [50, 30]) ≈ zeros(4) |
| 162 | + @test updatestate!(kalmanfilter1, [10, 50], [50, 30], Float64[]) ≈ zeros(4) |
| 163 | + @test kalmanfilter1.x̂ ≈ zeros(4) |
| 164 | + @test evaloutput(kalmanfilter1) ≈ kalmanfilter1() ≈ [50, 30] |
| 165 | + @test evaloutput(kalmanfilter1, Float64[]) ≈ kalmanfilter1(Float64[]) ≈ [50, 30] |
| 166 | + @test initstate!(kalmanfilter1, [10, 50], [50, 30+1]) ≈ [zeros(3); [1]] |
| 167 | + setstate!(kalmanfilter1, [1,2,3,4]) |
| 168 | + @test kalmanfilter1.x̂ ≈ [1,2,3,4] |
164 | 169 | for i in 1:1000
|
165 |
| - updatestate!(lo1, [11, 52], [50, 30]) |
| 170 | + updatestate!(kalmanfilter1, [11, 52], [50, 30]) |
166 | 171 | end
|
167 |
| - @test lo1() ≈ [50, 30] atol=1e-3 |
| 172 | + @test kalmanfilter1() ≈ [50, 30] atol=1e-3 |
168 | 173 | for i in 1:100
|
169 |
| - updatestate!(lo1, [10, 50], [51, 32]) |
| 174 | + updatestate!(kalmanfilter1, [10, 50], [51, 32]) |
170 | 175 | end
|
171 |
| - @test lo1() ≈ [51, 32] atol=1e-3 |
| 176 | + @test kalmanfilter1() ≈ [51, 32] atol=1e-3 |
172 | 177 | kalmanfilter2 = KalmanFilter(linmodel1, nint_u=[1, 1])
|
173 | 178 | for i in 1:100
|
174 | 179 | updatestate!(kalmanfilter2, [11, 52], [50, 30])
|
|
178 | 183 | updatestate!(kalmanfilter2, [10, 50], [51, 32])
|
179 | 184 | end
|
180 | 185 | @test kalmanfilter2() ≈ [51, 32] atol=1e-3
|
181 |
| - @test_throws ArgumentError updatestate!(lo1, [10, 50]) |
| 186 | + linmodel3 = LinModel{Float32}(0.5*ones(1,1), ones(1,1), ones(1,1), zeros(1,0), zeros(1,0), 1.0) |
| 187 | + kalmanfilter3 = KalmanFilter(linmodel3) |
| 188 | + x̂ = updatestate!(kalmanfilter3, [0], [0]) |
| 189 | + @test x̂ ≈ [0, 0] |
| 190 | + @test isa(x̂, Vector{Float32}) |
| 191 | + @test_throws ArgumentError updatestate!(kalmanfilter1, [10, 50]) |
182 | 192 | end
|
183 | 193 |
|
184 | 194 | @testset "Luenberger construction" begin
|
|
249 | 259 | updatestate!(lo2, [10, 50], [51, 32])
|
250 | 260 | end
|
251 | 261 | @test lo2() ≈ [51, 32] atol=1e-3
|
| 262 | + linmodel3 = LinModel{Float32}(0.5*ones(1,1), ones(1,1), ones(1,1), zeros(1,0), zeros(1,0), 1.0) |
| 263 | + lo3 = Luenberger(linmodel3) |
| 264 | + x̂ = updatestate!(lo3, [0], [0]) |
| 265 | + @test x̂ ≈ [0, 0] |
| 266 | + @test isa(x̂, Vector{Float32}) |
252 | 267 | end
|
253 | 268 |
|
254 | 269 | @testset "InternalModel construction" begin
|
|
339 | 354 | @test internalmodel1.x̂s ≈ zeros(2)
|
340 | 355 | setstate!(internalmodel1, [1,2])
|
341 | 356 | @test internalmodel1.x̂ ≈ [1,2]
|
| 357 | + |
| 358 | + linmodel3 = LinModel{Float32}(0.5*ones(1,1), ones(1,1), ones(1,1), zeros(1,0), zeros(1,0), 1.0) |
| 359 | + internalmodel3 = InternalModel(linmodel3) |
| 360 | + x̂ = updatestate!(internalmodel3, [0], [0]) |
| 361 | + @test x̂ ≈ [0] |
| 362 | + @test isa(x̂, Vector{Float32}) |
342 | 363 | end
|
343 | 364 |
|
344 | 365 | @testset "UnscentedKalmanFilter construction" begin
|
|
429 | 450 | updatestate!(ukf2, [10, 50], [51, 32])
|
430 | 451 | end
|
431 | 452 | @test ukf2() ≈ [51, 32] atol=1e-3
|
| 453 | + linmodel3 = LinModel{Float32}(0.5*ones(1,1), ones(1,1), ones(1,1), zeros(1,0), zeros(1,0), 1.0) |
| 454 | + ukf3 = UnscentedKalmanFilter(linmodel3) |
| 455 | + x̂ = updatestate!(ukf3, [0], [0]) |
| 456 | + @test x̂ ≈ [0, 0] |
| 457 | + @test isa(x̂, Vector{Float32}) |
432 | 458 | end
|
433 | 459 |
|
434 | 460 | @testset "ExtendedKalmanFilter construction" begin
|
|
515 | 541 | updatestate!(ekf2, [10, 50], [51, 32])
|
516 | 542 | end
|
517 | 543 | @test ekf2() ≈ [51, 32] atol=1e-3
|
| 544 | + linmodel3 = LinModel{Float32}(0.5*ones(1,1), ones(1,1), ones(1,1), zeros(1,0), zeros(1,0), 1.0) |
| 545 | + ekf3 = ExtendedKalmanFilter(linmodel3) |
| 546 | + x̂ = updatestate!(ekf3, [0], [0]) |
| 547 | + @test x̂ ≈ [0, 0] |
| 548 | + @test isa(x̂, Vector{Float32}) |
518 | 549 | end
|
0 commit comments