1+ struct NonLinMHE{M<: SimModel } <: StateEstimator
2+ model:: M
3+ optim:: JuMP.Model
4+ lastu0:: Vector{Float64}
5+ x̂:: Vector{Float64}
6+ P̂:: Hermitian{Float64, Matrix{Float64}}
7+ i_ym:: Vector{Int}
8+ nx̂:: Int
9+ nym:: Int
10+ nyu:: Int
11+ nxs:: Int
12+ As:: Matrix{Float64}
13+ Cs:: Matrix{Float64}
14+ nint_ym:: Vector{Int}
15+ P̂0:: Hermitian{Float64, Matrix{Float64}}
16+ Q̂:: Hermitian{Float64, Matrix{Float64}}
17+ R̂:: Hermitian{Float64, Matrix{Float64}}
18+ He:: Int
19+ X̂max:: Vector{Float64}
20+ X̂min:: Vector{Float64}
21+ function NonLinMHE {M} (model:: M , i_ym, nint_ym, P̂0, Q̂, R̂, He) where {M<: SimModel }
22+ nu, nx, ny = model. nu, model. nx, model. ny
23+ nym, nyu = length (i_ym), ny - length (i_ym)
24+ Asm, Csm, nint_ym = init_estimstoch (i_ym, nint_ym)
25+ nxs = size (Asm,1 )
26+ nx̂ = nx + nxs
27+ validate_kfcov (nym, nx̂, Q̂, R̂, P̂0)
28+ As, _ , Cs, _ = stoch_ym2y (model, i_ym, Asm, [], Csm, [])
29+ nσ, γ, m̂, Ŝ = init_mhe (nx̂, He)
30+ i_ym = collect (i_ym)
31+ lastu0 = zeros (nu)
32+ x̂ = [zeros (model. nx); zeros (nxs)]
33+ P̂0 = Hermitian (P̂0, :L )
34+ Q̂ = Hermitian (Q̂, :L )
35+ R̂ = Hermitian (R̂, :L )
36+ P̂ = copy (P̂0)
37+ return new (
38+ model,
39+ lastu0, x̂, P̂,
40+ i_ym, nx̂, nym, nyu, nxs,
41+ As, Cs, nint_ym,
42+ P̂0, Q̂, R̂,
43+ nσ, γ, m̂, Ŝ
44+ )
45+ end
46+ end
47+
48+ @doc raw """
49+ NonLinMHE(model::SimModel; <keyword arguments>)
50+
51+ Construct a nonlinear moving horizon estimator with the [`SimModel`](@ref) `model`.
52+
53+ Both [`LinModel`](@ref) and [`NonLinModel`](@ref) are supported. The process model is
54+ identical to [`UnscentedKalmanFilter`](@ref).
55+
56+ # Arguments
57+ - `model::SimModel` : (deterministic) model for the estimations.
58+ - `He::Int=10` : estimation horizon.
59+ - `<keyword arguments>` of [`SteadyKalmanFilter`](@ref) constructor.
60+ - `<keyword arguments>` of [`KalmanFilter`](@ref) constructor.
61+
62+ # Examples
63+ ```jldoctest
64+ julia> model = NonLinModel((x,u,_)->0.1x+u, (x,_)->2x, 10.0, 1, 1, 1);
65+
66+ ```
67+ """
68+ function NonLinMHE (
69+ model:: M ;
70+ i_ym:: IntRangeOrVector = 1 : model. ny,
71+ σP0:: Vector = fill (1 / model. nx, model. nx),
72+ σQ:: Vector = fill (1 / model. nx, model. nx),
73+ σR:: Vector = fill (1 , length (i_ym)),
74+ nint_ym:: IntVectorOrInt = fill (1 , length (i_ym)),
75+ σP0_int:: Vector = fill (1 , max (sum (nint_ym), 0 )),
76+ σQ_int:: Vector = fill (1 , max (sum (nint_ym), 0 )),
77+ He:: Int = 10
78+ ) where {M<: SimModel }
79+ # estimated covariances matrices (variance = σ²) :
80+ P̂0 = Diagonal {Float64} ([σP0 ; σP0_int ]. ^ 2 );
81+ Q̂ = Diagonal {Float64} ([σQ ; σQ_int ]. ^ 2 );
82+ R̂ = Diagonal {Float64} (σR.^ 2 );
83+ return NonLinMHE {M} (model, i_ym, nint_ym, P̂0, Q̂ , R̂, He)
84+ end
85+
86+ @doc raw """
87+ NonLinMHE{M<:SimModel}(model::M, i_ym, nint_ym, P̂0, Q̂, R̂, He)
88+
89+ Construct the estimator from the augmented covariance matrices `P̂0`, `Q̂` and `R̂`.
90+
91+ This syntax allows nonzero off-diagonal elements in ``\m athbf{P̂}_{-1}(0), \m athbf{Q̂, R̂}``.
92+ """
93+ NonLinMHE {M} (model:: M , i_ym, nint_ym, P̂0, Q̂, R̂, He) where {M<: SimModel }
0 commit comments