Skip to content

Commit 506a836

Browse files
committed
doc: additional comments MHE
1 parent e8be023 commit 506a836

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

src/estimator/internal_model.jl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,9 @@ function InternalModel(
9999
return InternalModel{NT, SM}(model, i_ym, stoch_ym.A, stoch_ym.B, stoch_ym.C, stoch_ym.D)
100100
end
101101

102-
"Validate if `model` is asymptotically stable for [`LinModel`](@ref)."
103-
function validate_internalmodel(model::LinModel, nym, Csm, Dsm)
104-
poles = eigvals(model.A)
105-
if any(abs.(poles) .≥ 1)
106-
error("InternalModel does not support integrating or unstable model")
107-
end
102+
"Validate if deterministic `model` and stochastic model `Csm, Dsm` for `InternalModel`s."
103+
function validate_internalmodel(model::SimModel, nym, Csm, Dsm)
104+
validate_poles(model)
108105
if size(Csm,1) nym || size(Dsm,1) nym
109106
error("Stochastic model output quantity ($(size(Csm,1))) is different from "*
110107
"measured output quantity ($nym)")
@@ -115,18 +112,15 @@ function validate_internalmodel(model::LinModel, nym, Csm, Dsm)
115112
return nothing
116113
end
117114

118-
"Only validate stochastic model size is `model` is not a [`LinModel`](@ref)."
119-
function validate_internalmodel(::SimModel, nym, Csm, Dsm)
120-
if size(Csm,1) nym || size(Dsm,1) nym
121-
error("Stochastic model output quantity ($(size(Csm,1))) is different from "*
122-
"measured output quantity ($nym)")
123-
end
124-
if iszero(Dsm)
125-
error("Stochastic model requires a nonzero direct transmission matrix D")
115+
"Validate if `model` is asymptotically stable for `LinModel`s."
116+
function validate_poles(model::LinModel)
117+
poles = eigvals(model.A)
118+
if any(abs.(poles) .≥ 1)
119+
error("InternalModel does not support integrating or unstable model")
126120
end
127121
return nothing
128122
end
129-
123+
validate_poles(::SimModel) = nothing
130124

131125
@doc raw"""
132126
matrices_internalmodel(model::LinModel)

src/estimator/mhe/construct.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ N_k = \begin{cases}
186186
```
187187
The vectors ``\mathbf{Ŵ}`` and ``\mathbf{V̂}`` encompass the estimated process noise
188188
``\mathbf{ŵ}(k-j)`` and sensor noise ``\mathbf{v̂}(k-j)`` from ``j=N_k-1`` to ``0``. The
189-
Extended Help defines the two vectors. See [`UnscentedKalmanFilter`](@ref) for details on
190-
the augmented process model and ``\mathbf{R̂}, \mathbf{Q̂}`` covariances. The matrix
191-
``\mathbf{P̂}_{k-N_k}(k-N_k+1)`` is estimated with an [`ExtendedKalmanFilter`](@ref).
189+
Extended Help defines the two vectors and the scalar ``ϵ``. See [`UnscentedKalmanFilter`](@ref)
190+
for details on he augmented process model and ``\mathbf{R̂}, \mathbf{Q̂}`` covariances. The
191+
matrix ``\mathbf{P̂}_{k-N_k}(k-N_k+1)`` is estimated with an [`ExtendedKalmanFilter`](@ref).
192192
193193
!!! warning
194194
See the Extended Help if you get an error like:
@@ -244,6 +244,10 @@ MovingHorizonEstimator estimator with a sample time Ts = 10.0 s, Ipopt optimizer
244244
\mathbf{x̂}_k(k-j+1) &= \mathbf{f̂}\Big(\mathbf{x̂}_k(k-j), \mathbf{u}(k-j), \mathbf{d}(k-j)\Big) + \mathbf{ŵ}(k-j)
245245
\end{aligned}
246246
```
247+
The slack variable ``ϵ`` relaxes the constraints if enabled, see [`setconstraint!`](@ref).
248+
It is disabled by default for the MHE (from `Cwt=Inf`) but it should be activated for
249+
problems with two or more types of bounds, to ensure feasibility (e.g. on the estimated
250+
state and sensor noise).
247251
248252
For [`LinModel`](@ref), the optimization is treated as a quadratic program with a
249253
time-varying Hessian, which is generally cheaper than nonlinear programming. For
@@ -317,10 +321,10 @@ noise ``\mathbf{ŵ}`` and sensor noise ``\mathbf{v̂}``:
317321
and also ``ϵ ≥ 0``. All the constraint parameters are vector. Use `±Inf` values when there
318322
is no bound. The constraint softness parameters ``\mathbf{c}``, also called equal concern
319323
for relaxation, are non-negative values that specify the softness of the associated bound.
320-
Use `0.0` values for hard constraints. The process and sensor noise constraints are all soft
321-
by default. Notice that constraining the estimated sensor noises is equivalent to bounding
322-
the innovation term, since ``\mathbf{v̂}(k) = \mathbf{y^m}(k) - \mathbf{ŷ^m}(k)``. See
323-
Extended Help for details on model augmentation and time-varying constraints.
324+
Use `0.0` values for hard constraints (default for all of them). Notice that constraining
325+
the estimated sensor noises is equivalent to bounding the innovation term, since
326+
``\mathbf{v̂}(k) = \mathbf{y^m}(k) - \mathbf{ŷ^m}(k)``. See Extended Help for details on
327+
model augmentation and time-varying constraints.
324328
325329
# Arguments
326330
!!! info

0 commit comments

Comments
 (0)