Skip to content

Commit a15f0f1

Browse files
committed
doc: adding all the kwargs to the Kalman filters and MHE
1 parent 065634e commit a15f0f1

File tree

3 files changed

+77
-16
lines changed

3 files changed

+77
-16
lines changed

src/estimator/construct.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ end
197197
198198
One integrator on each measured output by default if `model` is not a [`LinModel`](@ref).
199199
200-
If the integrator quantity per manipulated input `nint_u ≠ 0`, the method returns zero
201-
integrator on each measured output.
200+
Theres is no verification the augmented model remains observable. If the integrator quantity
201+
per manipulated input `nint_u ≠ 0`, the method returns zero integrator on each measured
202+
output.
202203
"""
203204
function default_nint(model::SimModel, i_ym=1:model.ny, nint_u=0)
204205
validate_ym(model, i_ym)

src/estimator/kalman.jl

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function correct_estimate_obsv!(estim::StateEstimator, y0m, d0, K̂)
249249
end
250250

251251
"Allow code reuse for `SteadyKalmanFilter` and `Luenberger` (observers with constant gain)."
252-
function predict_estimate_obsv!(estim::StateEstimator, y0m, d0, u0)
252+
function predict_estimate_obsv!(estim::StateEstimator, _ , d0, u0)
253253
x̂0corr = estim.x̂0
254254
Â, B̂u, B̂d = estim.Â, estim.B̂u, estim.B̂d
255255
x̂0next = estim.buffer.
@@ -341,13 +341,28 @@ is the estimation error covariance of `model` states augmented with the stochast
341341
Keyword arguments with *`emphasis`* are non-Unicode alternatives.
342342
343343
- `model::LinModel` : (deterministic) model for the estimations.
344+
- `i_ym=1:model.ny` : `model` output indices that are measured ``\mathbf{y^m}``, the rest
345+
are unmeasured ``\mathbf{y^u}``.
344346
- `σP_0=fill(1/model.nx,model.nx)` or *`sigmaP_0`* : main diagonal of the initial estimate
345347
covariance ``\mathbf{P}(0)``, specified as a standard deviation vector.
348+
- `σQ=fill(1/model.nx,model.nx)` or *`sigmaQ`* : main diagonal of the process noise
349+
covariance ``\mathbf{Q}`` of `model`, specified as a standard deviation vector.
350+
- `σR=fill(1,length(i_ym))` or *`sigmaR`* : main diagonal of the sensor noise covariance
351+
``\mathbf{R}`` of `model` measured outputs, specified as a standard deviation vector.
352+
- `nint_u=0`: integrator quantity for the stochastic model of the unmeasured disturbances at
353+
the manipulated inputs (vector), use `nint_u=0` for no integrator.
354+
- `nint_ym=default_nint(model,i_ym,nint_u)` : same than `nint_u` but for the unmeasured
355+
disturbances at the measured outputs, use `nint_ym=0` for no integrator.
356+
- `σQint_u=fill(1,sum(nint_u))` or *`sigmaQint_u`* : same than `σQ` but for the unmeasured
357+
disturbances at manipulated inputs ``\mathbf{Q_{int_u}}`` (composed of integrators).
346358
- `σPint_u_0=fill(1,sum(nint_u))` or *`sigmaPint_u_0`* : same than `σP_0` but for the unmeasured
347359
disturbances at manipulated inputs ``\mathbf{P_{int_u}}(0)`` (composed of integrators).
360+
- `σQint_ym=fill(1,sum(nint_ym))` or *`sigmaQint_u`* : same than `σQ` for the unmeasured
361+
disturbances at measured outputs ``\mathbf{Q_{int_{ym}}}`` (composed of integrators).
348362
- `σPint_ym_0=fill(1,sum(nint_ym))` or *`sigmaPint_ym_0`* : same than `σP_0` but for the unmeasured
349363
disturbances at measured outputs ``\mathbf{P_{int_{ym}}}(0)`` (composed of integrators).
350-
- `<keyword arguments>` of [`SteadyKalmanFilter`](@ref) constructor.
364+
- `direct=true`: construct with a direct transmission from ``\mathbf{y^m}`` (a.k.a. current
365+
estimator, in opposition to the delayed/predictor form).
351366
352367
# Examples
353368
```jldoctest
@@ -564,11 +579,31 @@ The ``\mathbf{ĥ^m}`` function represents the measured outputs of ``\mathbf{ĥ
564579
Keyword arguments with *`emphasis`* are non-Unicode alternatives.
565580
566581
- `model::SimModel` : (deterministic) model for the estimations.
582+
- `i_ym=1:model.ny` : `model` output indices that are measured ``\mathbf{y^m}``, the rest
583+
are unmeasured ``\mathbf{y^u}``.
584+
- `σP_0=fill(1/model.nx,model.nx)` or *`sigmaP_0`* : main diagonal of the initial estimate
585+
covariance ``\mathbf{P}(0)``, specified as a standard deviation vector.
586+
- `σQ=fill(1/model.nx,model.nx)` or *`sigmaQ`* : main diagonal of the process noise
587+
covariance ``\mathbf{Q}`` of `model`, specified as a standard deviation vector.
588+
- `σR=fill(1,length(i_ym))` or *`sigmaR`* : main diagonal of the sensor noise covariance
589+
``\mathbf{R}`` of `model` measured outputs, specified as a standard deviation vector.
590+
- `nint_u=0`: integrator quantity for the stochastic model of the unmeasured disturbances at
591+
the manipulated inputs (vector), use `nint_u=0` for no integrator (see Extended Help).
592+
- `nint_ym=default_nint(model,i_ym,nint_u)` : same than `nint_u` but for the unmeasured
593+
disturbances at the measured outputs, use `nint_ym=0` for no integrator (see Extended Help).
594+
- `σQint_u=fill(1,sum(nint_u))` or *`sigmaQint_u`* : same than `σQ` but for the unmeasured
595+
disturbances at manipulated inputs ``\mathbf{Q_{int_u}}`` (composed of integrators).
596+
- `σPint_u_0=fill(1,sum(nint_u))` or *`sigmaPint_u_0`* : same than `σP_0` but for the unmeasured
597+
disturbances at manipulated inputs ``\mathbf{P_{int_u}}(0)`` (composed of integrators).
598+
- `σQint_ym=fill(1,sum(nint_ym))` or *`sigmaQint_u`* : same than `σQ` for the unmeasured
599+
disturbances at measured outputs ``\mathbf{Q_{int_{ym}}}`` (composed of integrators).
600+
- `σPint_ym_0=fill(1,sum(nint_ym))` or *`sigmaPint_ym_0`* : same than `σP_0` but for the unmeasured
601+
disturbances at measured outputs ``\mathbf{P_{int_{ym}}}(0)`` (composed of integrators).
602+
- `direct=true`: construct with a direct transmission from ``\mathbf{y^m}`` (a.k.a. current
603+
estimator, in opposition to the delayed/predictor form).
567604
- `α=1e-3` or *`alpha`* : alpha parameter, spread of the state distribution ``(0 < α ≤ 1)``.
568605
- `β=2` or *`beta`* : beta parameter, skewness and kurtosis of the states distribution ``(β ≥ 0)``.
569606
- `κ=0` or *`kappa`* : kappa parameter, another spread parameter ``(0 ≤ κ ≤ 3)``.
570-
- `<keyword arguments>` of [`SteadyKalmanFilter`](@ref) constructor.
571-
- `<keyword arguments>` of [`KalmanFilter`](@ref) constructor.
572607
573608
# Examples
574609
```jldoctest
@@ -888,20 +923,16 @@ end
888923
889924
Construct an extended Kalman Filter with the [`SimModel`](@ref) `model`.
890925
891-
Both [`LinModel`](@ref) and [`NonLinModel`](@ref) are supported. The process model is
892-
identical to [`UnscentedKalmanFilter`](@ref). The Jacobians of the augmented model
926+
Both [`LinModel`](@ref) and [`NonLinModel`](@ref) are supported. The process model and the
927+
keyword arguments are identical to [`UnscentedKalmanFilter`](@ref), except for `α`, `β` and
928+
`κ` which do not apply to the extended Kalman Filter. The Jacobians of the augmented model
893929
``\mathbf{f̂, ĥ}`` are computed with [`ForwardDiff.jl`](https://github.com/JuliaDiff/ForwardDiff.jl)
894930
automatic differentiation.
895931
896932
!!! warning
897933
See the Extended Help of [`linearize`](@ref) function if you get an error like:
898934
`MethodError: no method matching (::var"##")(::Vector{ForwardDiff.Dual})`.
899935
900-
# Arguments
901-
- `model::SimModel` : (deterministic) model for the estimations.
902-
- `<keyword arguments>` of [`SteadyKalmanFilter`](@ref) constructor.
903-
- `<keyword arguments>` of [`KalmanFilter`](@ref) constructor.
904-
905936
# Examples
906937
```jldoctest
907938
julia> model = NonLinModel((x,u,_)->0.2x+u, (x,_)->-3x, 5.0, 1, 1, 1, solver=nothing);

src/estimator/mhe/construct.jl

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,37 @@ See [`UnscentedKalmanFilter`](@ref) for details on the augmented process model a
222222
`MethodError: no method matching (::var"##")(::Vector{ForwardDiff.Dual})`.
223223
224224
# Arguments
225+
!!! info
226+
Keyword arguments with *`emphasis`* are non-Unicode alternatives.
227+
225228
- `model::SimModel` : (deterministic) model for the estimations.
226229
- `He=nothing` : estimation horizon ``H_e``, must be specified.
230+
- `i_ym=1:model.ny` : `model` output indices that are measured ``\mathbf{y^m}``, the rest
231+
are unmeasured ``\mathbf{y^u}``.
232+
- `σP_0=fill(1/model.nx,model.nx)` or *`sigmaP_0`* : main diagonal of the initial estimate
233+
covariance ``\mathbf{P}(0)``, specified as a standard deviation vector.
234+
- `σQ=fill(1/model.nx,model.nx)` or *`sigmaQ`* : main diagonal of the process noise
235+
covariance ``\mathbf{Q}`` of `model`, specified as a standard deviation vector.
236+
- `σR=fill(1,length(i_ym))` or *`sigmaR`* : main diagonal of the sensor noise covariance
237+
``\mathbf{R}`` of `model` measured outputs, specified as a standard deviation vector.
238+
- `nint_u=0`: integrator quantity for the stochastic model of the unmeasured disturbances at
239+
the manipulated inputs (vector), use `nint_u=0` for no integrator (see Extended Help).
240+
- `nint_ym=default_nint(model,i_ym,nint_u)` : same than `nint_u` but for the unmeasured
241+
disturbances at the measured outputs, use `nint_ym=0` for no integrator (see Extended Help).
242+
- `σQint_u=fill(1,sum(nint_u))` or *`sigmaQint_u`* : same than `σQ` but for the unmeasured
243+
disturbances at manipulated inputs ``\mathbf{Q_{int_u}}`` (composed of integrators).
244+
- `σPint_u_0=fill(1,sum(nint_u))` or *`sigmaPint_u_0`* : same than `σP_0` but for the unmeasured
245+
disturbances at manipulated inputs ``\mathbf{P_{int_u}}(0)`` (composed of integrators).
246+
- `σQint_ym=fill(1,sum(nint_ym))` or *`sigmaQint_u`* : same than `σQ` for the unmeasured
247+
disturbances at measured outputs ``\mathbf{Q_{int_{ym}}}`` (composed of integrators).
248+
- `σPint_ym_0=fill(1,sum(nint_ym))` or *`sigmaPint_ym_0`* : same than `σP_0` but for the unmeasured
249+
disturbances at measured outputs ``\mathbf{P_{int_{ym}}}(0)`` (composed of integrators).
227250
- `Cwt=Inf` : slack variable weight ``C``, default to `Inf` meaning hard constraints only.
228251
- `optim=default_optim_mhe(model)` : a [`JuMP.Model`](https://jump.dev/JuMP.jl/stable/api/JuMP/#JuMP.Model)
229252
with a quadratic/nonlinear optimizer for solving (default to [`Ipopt`](https://github.com/jump-dev/Ipopt.jl),
230253
or [`OSQP`](https://osqp.org/docs/parsers/jump.html) if `model` is a [`LinModel`](@ref)).
231-
- `<keyword arguments>` of [`SteadyKalmanFilter`](@ref) constructor.
232-
- `<keyword arguments>` of [`KalmanFilter`](@ref) constructor.
254+
- `direct=true`: construct with a direct transmission from ``\mathbf{y^m}`` (a.k.a. current
255+
estimator, in opposition to the delayed/predictor form).
233256
234257
# Examples
235258
```jldoctest
@@ -285,10 +308,16 @@ MovingHorizonEstimator estimator with a sample time Ts = 10.0 s, Ipopt optimizer
285308
[^2]: M. Hovd (2012), "A Note On The Smoothing Formulation Of Moving Horizon Estimation",
286309
*Facta Universitatis*, Vol. 11 №2.
287310
311+
The Extended Help of [`SteadyKalmanFilter`](@ref) details the augmentation with `nint_ym`
312+
and `nint_u` arguments. The default augmentation scheme is identical, that is `nint_u=0`
313+
and `nint_ym` computed by [`default_nint`](@ref). Note that the constructor does not
314+
validate the observability of the resulting augmented [`NonLinModel`](@ref). In such
315+
cases, it is the user's responsibility to ensure that it is still observable.
316+
288317
The slack variable ``ϵ`` relaxes the constraints if enabled, see [`setconstraint!`](@ref).
289318
It is disabled by default for the MHE (from `Cwt=Inf`) but it should be activated for
290319
problems with two or more types of bounds, to ensure feasibility (e.g. on the estimated
291-
state and sensor noise).
320+
state ``\mathbf{x̂}`` and sensor noise ``\mathbf{v̂}``).
292321
293322
The optimization and the estimation of the covariance at arrival
294323
``\mathbf{P̂}_{k-N_k}(k-N_k+p)`` depend on `model`:

0 commit comments

Comments
 (0)