Nonlinear Programming for Maximum Likelihood Estimation of parameters in Linear Time Invariant systems.
This repository is an adaptation from the repository "SQP-for-MLE-LTV" for the special case of time-invariant linear systems, with a more efficient optimization routine. The associated article (for the LTV version) is "An Efficient Method for the Joint Estimation of System Parameters and Noise Covariances for Linear Time-Variant Systems"
Python packages
- numpy
- scipy
- matplotlib
- casadi (with IPOPT)
- time
- contextlib
We assume that the data is generated through the following dynamical system (linear, and with Gaussian Noise)
where
Note that the time-varying behavior comes from the inputs
Also, the parameters are assumed to be in some set defined with inequality constraints:
Note that the inequality is of the opposite sign of how it is in the paper.
We consider optimization problems for estimation of
Regarding the cost function
The first of them is referred to as "MLE" because it corresponds to the Maximum Likelihood problem. The second is called "PredErr" because it corresponds to the Prediction Error Methods.
In the case of an LTI system, the Kalman Filter equations quickly converge to their steady state, which is given by the Riccati Equation. Replacing the Kalman Filter equation with their corresponding steady states equation considerably reduces the complexity of the equations:
Let us parameterize
We also define the following:
Finally, we simply stack all main optimization variables
where the function
One option is simply to call the solver IPOPT to solve the optimization problem in this lifted form:
One can also condense partially the problem to remove the dependency in
where the function
and
We propose a tailored SP method.
Here, we solve a sequence of optimization problems similar to the one above,
but where the function
In this algorithm, we update the current solution point
where
where
Note that
Regarding the size of the trust region,
whenever the objective value of the new candidate point
To assess the computational speed of the three algorithms,
we run them on a simple example, with generated data, for different realization of the data generation and different data lengths
For a simple model with
and with
The model is defined in models/example1, and illustrated with generated data in notebooks/illustrative_example1.
The benchmark is computed in the file notebooks/benchmark_example1, and is depicted here:
For a different example, we consider now the following sensor fusion:
and with
The parameters to estimate are
The model is defined in models/example2, and illustrated with generated data in notebooks/illustrative_example2.
'''
xplus_fn: casadi function
y_fn: casadi function
Q_fn: casadi function
R_fn: casadi function
y1, y2: arrays of measurement data with size N1 x ny and N2 x ny
u1, u2; arrays of input data with size N1 x nu and N2 x nu
x0: array of the initial state of size nx
theta0: initial guess to warm start the optimization routine
'''
from RiccatiEst import ModelParser # Model parser to define the model
from RiccatiEst import solve, compute_cost # main function to solve the problem
problem = {
"model": ModelParser(xplus_fn, y_fn, Q_fn, R_fn),
"ys": [y1, y2],
"us": [u1, u2],
"x0": x0 # can also be [x0_1, x0_2]
}
formulation = "MLE" # can be "MLE", "PredErr"
algorithm = "SP" # can be "SP" or "IPOPT-dense" or "IPOPT-lifted"
# default options for SP method (not necessary to specify them)
# when IPOPT is used, enter the ipopt options instead.
opts = {
"TR_init":1., # initial lentgth of trust region \Delta
"TR_shrink":0.5, # = \gamma such that the trust region decreases as \Delta = \gamma \Delta when needed
"maxiter":100, # for termination
"rtol.cost_decrease":1e-5, # for termination
"hessian_perturbation":0., # add \delta (p-\bar{p})^2 in the quadratic approximation of V
"verbose":True # printing information during optimization
}
theta_found, stats = solve(problem, theta0, formulation, algorithm,
opts=opts, verbose=True)
More detailed examples can be found in notebooks/illustrative_example1 and notebooks/illustrative_example2.