@@ -895,10 +895,14 @@ end
895895 @test isa (mhe13, MovingHorizonEstimator{Float32})
896896
897897 mhe14 = MovingHorizonEstimator (
898- nonlinmodel, He= 5 , gradient= AutoFiniteDiff (), jacobian= AutoFiniteDiff ()
898+ nonlinmodel, He= 5 ,
899+ gradient= AutoFiniteDiff (),
900+ jacobian= AutoFiniteDiff (),
901+ hessian= AutoFiniteDiff ()
899902 )
900903 @test mhe14. gradient == AutoFiniteDiff ()
901904 @test mhe14. jacobian == AutoFiniteDiff ()
905+ @test mhe14. hessian == AutoFiniteDiff ()
902906
903907 @test_throws ArgumentError MovingHorizonEstimator (linmodel)
904908 @test_throws ArgumentError MovingHorizonEstimator (linmodel, He= 0 )
@@ -952,30 +956,39 @@ end
952956 preparestate! (mhe1, [51 , 32 ], [5 ])
953957 @test mhe1 ([5 ]) ≈ [51 , 32 ] atol= 1e-3
954958
955- mhe1 = MovingHorizonEstimator (nonlinmodel, He= 2 , nint_u= [1 , 1 ], nint_ym= [ 0 , 0 ] , direct= false )
956- JuMP. set_attribute (mhe1 . optim, " tol" , 1e-7 )
957- preparestate! (mhe1 , [50 , 30 ], [5 ])
958- x̂ = updatestate! (mhe1 , [10 , 50 ], [50 , 30 ], [5 ])
959+ mhe1b = MovingHorizonEstimator (nonlinmodel, He= 2 , nint_u= [1 , 1 ], nint_ym= 0 , direct= false )
960+ JuMP. set_attribute (mhe1b . optim, " tol" , 1e-7 )
961+ preparestate! (mhe1b , [50 , 30 ], [5 ])
962+ x̂ = updatestate! (mhe1b , [10 , 50 ], [50 , 30 ], [5 ])
959963 @test x̂ ≈ zeros (6 ) atol= 1e-9
960- @test mhe1 . x̂0 ≈ zeros (6 ) atol= 1e-9
961- info = getinfo (mhe1 )
964+ @test mhe1b . x̂0 ≈ zeros (6 ) atol= 1e-9
965+ info = getinfo (mhe1b )
962966 @test info[:x̂ ] ≈ x̂ atol= 1e-9
963967 @test info[:Ŷ ][end - 1 : end ] ≈ [50 , 30 ] atol= 1e-9
964968
965- @test initstate! (mhe1, [11 , 52 ], [50 , 30 ], [5 ]) ≈ zeros (6 ) atol= 1e-9
966- @test mhe1. lastu0 ≈ [1 , 2 ]
967- setstate! (mhe1, [1 ,2 ,3 ,4 ,5 ,6 ])
968- @test mhe1. x̂0 ≈ [1 ,2 ,3 ,4 ,5 ,6 ]
969+ mhe1c = MovingHorizonEstimator (nonlinmodel, He= 2 , direct= false , hessian= true )
970+ preparestate! (mhe1c, [50 , 30 ], [5 ])
971+ x̂ = updatestate! (mhe1c, [10 , 50 ], [50 , 30 ], [5 ])
972+ @test x̂ ≈ zeros (6 ) atol= 1e-9
973+ @test mhe1c. x̂0 ≈ zeros (6 ) atol= 1e-9
974+ info = getinfo (mhe1c)
975+ @test info[:x̂ ] ≈ x̂ atol= 1e-9
976+ @test info[:Ŷ ][end - 1 : end ] ≈ [50 , 30 ] atol= 1e-9
977+
978+ @test initstate! (mhe1c, [11 , 52 ], [50 , 30 ], [5 ]) ≈ zeros (6 ) atol= 1e-9
979+ @test mhe1c. lastu0 ≈ [1 , 2 ]
980+ setstate! (mhe1c, [1 ,2 ,3 ,4 ,5 ,6 ])
981+ @test mhe1c. x̂0 ≈ [1 ,2 ,3 ,4 ,5 ,6 ]
969982 for i in 1 : 40
970- preparestate! (mhe1 , [50 , 30 ], [5 ])
971- updatestate! (mhe1 , [11 , 52 ], [50 , 30 ], [5 ])
983+ preparestate! (mhe1c , [50 , 30 ], [5 ])
984+ updatestate! (mhe1c , [11 , 52 ], [50 , 30 ], [5 ])
972985 end
973- @test mhe1 ([5 ]) ≈ [50 , 30 ] atol= 1e-3
986+ @test mhe1c ([5 ]) ≈ [50 , 30 ] atol= 1e-3
974987 for i in 1 : 40
975- preparestate! (mhe1 , [51 , 32 ], [5 ])
976- updatestate! (mhe1 , [10 , 50 ], [51 , 32 ], [5 ])
988+ preparestate! (mhe1c , [51 , 32 ], [5 ])
989+ updatestate! (mhe1c , [10 , 50 ], [51 , 32 ], [5 ])
977990 end
978- @test mhe1 ([5 ]) ≈ [51 , 32 ] atol= 1e-3
991+ @test mhe1c ([5 ]) ≈ [51 , 32 ] atol= 1e-3
979992
980993 mhe2 = MovingHorizonEstimator (linmodel, He= 2 )
981994 preparestate! (mhe2, [50 , 30 ], [5 ])
0 commit comments