LinearQuadraticGaussian<T>
Models & Types · AiDotNet.Control
The linear quadratic Gaussian controller: an optimal regulator driven by an optimal estimate of a state it cannot measure.
For Beginners
You want to control something but can only see part of it, through noisy sensors. This runs a best-guess reconstruction of the full situation, then controls as if that guess were fact. Remarkably, that is provably the best you can do — for this class of problem.
How It Works
Combines LinearQuadraticRegulator with KalmanFilter for the
system x[k+1] = A·x[k] + B·u[k] + w[k], y[k] = C·x[k] + v[k], minimizing the
expected quadratic cost when neither the state nor the noise can be observed.
The separation principle is what makes this legitimate, and it is not obvious. The controller must choose inputs without knowing the state, so one might expect the estimator and the regulator to have to be designed together — the regulator compensating for the estimator’s errors, the estimator anticipating what the regulator will do. They do not. For a linear system with Gaussian noise and a quadratic cost, the optimal solution is exactly: estimate the state as well as possible, ignoring the control problem entirely; then apply the control law you would have used had the estimate been the truth. Each half is designed as if the other were perfect, and the combination is still optimal.
This is a genuinely surprising result — it fails for nonlinear systems, for non-Gaussian noise, and for non-quadratic costs — and it is the reason linear control theory is as clean as it is. See H. Kwakernaak and R. Sivan, Linear Optimal Control Systems (Wiley 1972), Chapter 5, and W. M. Wonham, “On the Separation Theorem of Stochastic Control”, SIAM Journal on Control 6(2), 1968, pp. 312-326.
A caution worth stating. LQR alone has famously good stability margins. LQG does not inherit them: J. C. Doyle, “Guaranteed Margins for LQG Regulators”, IEEE Transactions on Automatic Control 23(4), 1978, pp. 756-757, is a one-page paper whose entire content is that an LQG loop can have arbitrarily small margins. Optimal for the model you wrote down is not the same as robust to the ways that model is wrong.
Example
// A double integrator: state is (position, velocity), input is force, and only position is measured.
var a = new Matrix<double>(new double[,] { { 1.0, 1.0 }, { 0.0, 1.0 } });
var b = new Matrix<double>(new double[,] { { 0.5 }, { 1.0 } });
var c = new Matrix<double>(new double[,] { { 1.0, 0.0 } });
// Costs and noise are weighting matrices, not scalars: identity penalises every term equally.
var q = Matrix<double>.CreateIdentity(2);
var r = Matrix<double>.CreateIdentity(1);
var processCovariance = Matrix<double>.CreateIdentity(2);
var sensorCovariance = Matrix<double>.CreateIdentity(1);
var controller = new LinearQuadraticGaussian<double>(
stateMatrix: a, inputMatrix: b, observationMatrix: c,
stateCost: q, inputCost: r,
processNoise: processCovariance, measurementNoise: sensorCovariance);
var initialGuess = new Vector<double>(new double[] { 0.0, 0.0 });
controller.Initialize(initialGuess, Matrix<double>.CreateIdentity(2));
// Each control step: measure, then act.
var measurement = new Vector<double>(new double[] { 0.1 });
var input = controller.Step(measurement);
Constructors
| Constructor | Summary |
|---|---|
LinearQuadraticGaussian(Matrix<T> stateMatrix, Matrix<T> inputMatrix, Matrix<T> observationMatrix, Matrix<T> stateCost, Matrix<T> inputCost, Matrix<T> processNoise, Matrix<T> measurementNoise, AlgebraicRiccatiSolverOptions options) |
Creates a linear quadratic Gaussian controller, designing both halves. |
Properties
| Property | Summary |
|---|---|
KalmanFilter<T> Estimator { get; } |
Gets the estimator half, including its current state and covariance. |
LinearQuadraticRegulator<T> Regulator { get; } |
Gets the regulator half, including its gain and cost-to-go matrix. |
Vector<T> EstimatedState { get; } |
Gets the current state estimate. |
Methods
| Method | Summary |
|---|---|
Vector<T> Step(Vector<T> measurement) |
Runs one control step: folds in a measurement, then returns the input to apply. |
void Initialize(Vector<T> state, Matrix<T> covariance) |
Sets the initial state estimate and its covariance. |