Algorithm Search⌘K

Algorithmcore

Self-tuning regulator

Also called STR.

Estimates the plant online by recursive least squares and redesigns the controller from the estimate at each sample.

Time
O(N d^2) worst
Space
O(d^2) extra
Where
N = the number of samples; d = the number of estimated parameters
Properties
deterministicnot exactonlineiterative
Origin
Karl Johan Åström, Björn Wittenmark, 1973

A self-tuning regulator (STR) is an adaptive controller that repeats two steps at every sample: it updates an estimate of a plant model from the latest input and output, and it computes the controller from the estimate as if the estimate were exact (certainty equivalence). The estimator is usually the RLS algorithm; the RLS page covers the estimator alone, and this page covers the closed loop that wraps a control design around it, where the data are generated by the controller that the estimate defines. This page treats the direct minimum variance self-tuner of Åström and Wittenmark (1973). Its main result is the self-tuning property: if the estimates converge, the limit controller gives the minimum output variance, even though the least squares estimates of a plant with coloured noise are biased.

In plain words

The regulator keeps a simple model of the plant and keeps improving it. At each sample it measures the output, checks how wrong the model's last prediction was, and corrects the model a little. Then it computes the input that, by the corrected model, would bring the next output as close to zero as possible, and it applies that input. The model is never assumed to be exact; the regulator just acts as if it were, and fixes the model again at the next sample. For the noise regulation problem on this page, this simple loop finds the best possible controller, even though the model it uses is too simple to describe the noise.

The problem

The plant is an ARMAX model with a delay of one sample,

yt=−a1yt−1−⋯−anyt−n+b1ut−1+⋯+bmut−m+et+c1et−1+⋯+cket−k,y_t = -a_1 y_{t-1} - \dots - a_n y_{t-n} + b_1 u_{t-1} + \dots + b_m u_{t-m} + e_t + c_1 e_{t-1} + \dots + c_k e_{t-k},

where ete_t is white noise with variance σ2\sigma^2, the polynomial C(q)=qk+c1qk−1+⋯+ckC(q) = q^k + c_1 q^{k-1} + \dots + c_k has all zeros inside the unit circle, and B(q)=b1qm−1+⋯+bmB(q) = b_1 q^{m-1} + \dots + b_m has all zeros inside the unit circle (the plant is minimum phase). The coefficients are unknown. The aim is to minimize the output variance E[yt2]E[y_t^2]. The controller that does this, when the plant is known, is the minimum variance controller: it makes the one step ahead prediction y^t+1∣t\hat y_{t+1|t} equal to zero, so that yt+1y_{t+1} is the prediction error et+1e_{t+1}, and the minimum variance is σ2\sigma^2.

The algorithm

The direct self-tuner does not estimate AA, BB and CC. It estimates the parameters of the controller directly, from the model

yt+1−β0ut=s0yt+⋯+snsyt−ns+r1ut−1+⋯+rnrut−nr+εt+1=φtTθ+εt+1,y_{t+1} - \beta_0 u_t = s_0 y_t + \dots + s_{n_s} y_{t-n_s} + r_1 u_{t-1} + \dots + r_{n_r} u_{t-n_r} + \varepsilon_{t+1} = \varphi_t^T \theta + \varepsilon_{t+1},

where β0\beta_0 is a fixed guess of b1b_1 with the correct sign, and θ=(s0,…,sns,r1,…,rnr)\theta = (s_0, \dots, s_{n_s}, r_1, \dots, r_{n_r}). The control sets the predicted output of this model to zero.

  1. STR-MV(β₀, θ₀, p₀, λ, N) ▷ λ ∈ (0, 1] is the forgetting factor
  2. 1θ̂ ← θ₀; P ← p₀ I
  3. 2for t ← 0 to N - 1 do
  4. 3measure y_t
  5. 4z ← y_t - β₀ u_{t-1} ▷ the regression target
  6. 5K ← P φ_{t-1} / (λ + φ_{t-1}ᵀ P φ_{t-1})
  7. 6θ̂ ← θ̂ + K (z - φ_{t-1}ᵀ θ̂)
  8. 7P ← (P - K φ_{t-1}ᵀ P) / λ
  9. 8u_t ← -φ_tᵀ θ̂ / β₀ ▷ certainty equivalence: predicted y_{t+1} = 0
  10. 9return θ̂

Lines L4 to L7 are one step of recursive least squares. Line L8 is the control design; for this problem it is one division. In an indirect self-tuner, line L8 is replaced by a full design from an estimated plant model, for example the polynomial equation of adaptive pole placement.

Example

Take the first order plant yt+1=0.9 yt+0.5 ut+et+1+0.5 ety_{t+1} = 0.9\,y_t + 0.5\,u_t + e_{t+1} + 0.5\,e_t with σ=1\sigma = 1, so a1=−0.9a_1 = -0.9, b1=0.5b_1 = 0.5 and c1=0.5c_1 = 0.5. The open loop has the pole 0.90.9 and the variance (1+c12−2a1c1)/(1−a12)=2.15/0.19=11.3(1 + c_1^2 - 2a_1c_1)/(1 - a_1^2) = 2.15/0.19 = 11.3. The prediction is y^t+1∣t=0.9 yt+0.5 ut+0.5 et\hat y_{t+1|t} = 0.9\,y_t + 0.5\,u_t + 0.5\,e_t. Under the minimum variance law et=yte_t = y_t, so the law is ut=−2.8 ytu_t = -2.8\,y_t, and then yt=ety_t = e_t exactly.

The self-tuner uses ns=0n_s = 0, nr=0n_r = 0, so it estimates one number s0s_0 in yt+1−β0ut=s0yty_{t+1} - \beta_0 u_t = s_0 y_t, and it applies ut=−(s0/β0)ytu_t = -(s_0/\beta_0) y_t. The ideal value of s0/β0s_0/\beta_0 is 2.82.8. The start is θ0=0\theta_0 = 0, p0=100p_0 = 100, λ=1\lambda = 1 and N=5000N = 5000; the variance is taken over t≥1000t \ge 1000. These are measurements for one noise sequence (seed 0).

β0\beta_0 s0/β0s_0/\beta_0 at NN output variance
0.25 2.803 1.014
0.5 2.780 1.014
1 2.620 1.031
2 2.104 1.171

With β0=1\beta_0 = 1 and the seeds 0 to 7, s0s_0 at N=5000N = 5000 is between 2.62 and 2.785, the output variance is between 0.97 and 1.04, and the lag one autocorrelation of yy is at most 0.13 in absolute value. The variance is flat near the optimum: the gain 2.62 gives the closed loop pole −0.41-0.41 and the variance (1+0.25−2⋅0.41⋅0.5)/(1−0.412)=1.010(1 + 0.25 - 2 \cdot 0.41 \cdot 0.5)/(1 - 0.41^2) = 1.010, only 1 percent above the minimum. The open loop variance measured on one sequence of 3500 samples is 12.3.

Correctness

The proof in proofs/correctness.md shows two facts. First, the parameter θ∗\theta^* of the minimum variance controller is a fixed point of the least squares estimator in closed loop: when the regulator uses θ∗\theta^*, the output is yt=ety_t = e_t, the residual yt+1−β0ut−φtTθ∗y_{t+1} - \beta_0 u_t - \varphi_t^T\theta^* is et+1e_{t+1}, and this is uncorrelated with φt\varphi_t, so the normal equations hold at θ∗\theta^*. Second (the self-tuning property, a theorem of Åström and Wittenmark), if θ^t\hat\theta_t converges and the closed loop signals are bounded in mean square, the limit makes the sample correlations ry(τ)r_y(\tau) for τ=1,…,ns+1\tau = 1, \dots, n_s + 1 and ryu(τ)r_{yu}(\tau) for τ=1,…,nr\tau = 1, \dots, n_r zero; when nsn_s and nrn_r are large enough, this forces the minimum variance controller. Convergence itself is a separate and harder theorem: Ljung (1977) proved convergence with probability one under a positive real condition on CC, with the method of an associated differential equation.

Proof: The minimum variance self-tuner has the self-tuning propertyfull

Notation is that of the page. The regressor is φt=(yt,…,yt−ns,ut−1,…,ut−nr)\varphi_t = (y_t, \dots, y_{t-n_s}, u_{t-1}, \dots, u_{t-n_r}), the target is zt+1=yt+1−β0utz_{t+1} = y_{t+1} - \beta_0 u_t, and the control is ut=−φtTθ^t/β0u_t = -\varphi_t^T\hat\theta_t/\beta_0 (line L8), where θ^t\hat\theta_t is the estimate after the update with (φt−1,zt)(\varphi_{t-1}, z_t). We take λ=1\lambda = 1.

Claim 1 (the residual is the output). Line L8 gives β0ut=−φtTθ^t\beta_0 u_t = -\varphi_t^T\hat\theta_t. So

zt+1−φtTθ^t=yt+1−β0ut−φtTθ^t=yt+1.z_{t+1} - \varphi_t^T \hat\theta_t = y_{t+1} - \beta_0 u_t - \varphi_t^T\hat\theta_t = y_{t+1}.

In closed loop, the prediction error of the model at the current estimate is the next output.

Claim 2 (normal equations of RLS). Line L5 to L7 with λ=1\lambda = 1 are the recursive form of Pt−1=P0−1+∑k<tφkφkTP_t^{-1} = P_0^{-1} + \sum_{k<t}\varphi_k\varphi_k^T and Pt−1θ^t=P0−1θ0+∑k<tφkzk+1P_t^{-1}\hat\theta_t = P_0^{-1}\theta_0 + \sum_{k<t}\varphi_k z_{k+1} (a standard identity, proved on the page RLS algorithm with the Sherman-Morrison formula; the tests check it exactly in rational arithmetic). By Claim 1, zk+1=yk+1+φkTθ^kz_{k+1} = y_{k+1} + \varphi_k^T\hat\theta_k. Substitute and subtract Pt−1θ^t=P0−1θ^t+∑k<tφkφkTθ^tP_t^{-1}\hat\theta_t = P_0^{-1}\hat\theta_t + \sum_{k<t}\varphi_k\varphi_k^T\hat\theta_t:

∑k<tφkyk+1=P0−1(θ^t−θ0)+∑k<tφkφkT(θ^t−θ^k).\sum_{k<t}\varphi_k y_{k+1} = P_0^{-1}(\hat\theta_t - \theta_0) + \sum_{k<t}\varphi_k\varphi_k^T(\hat\theta_t - \hat\theta_k).

Claim 3 (self-tuning property). Assume θ^t→θ∞\hat\theta_t \to \theta_\infty and 1t∑k<t∣φk∣2≤M\frac1t\sum_{k<t}|\varphi_k|^2 \le M for all tt. Then 1t∑k<tφkyk+1→0\frac1t\sum_{k<t}\varphi_k y_{k+1} \to 0. In terms of sample correlations, r^y(τ)=lim⁡1t∑yk+τyk=0\hat r_y(\tau) = \lim \frac1t\sum y_{k+\tau}y_k = 0 for τ=1,…,ns+1\tau = 1, \dots, n_s + 1, and r^yu(τ)=lim⁡1t∑yk+τuk=0\hat r_{yu}(\tau) = \lim\frac1t\sum y_{k+\tau}u_k = 0 for τ=1,…,nr\tau = 1, \dots, n_r, whenever these limits exist.

Proof. Divide the identity of Claim 2 by tt. The first term is P0−1(θ^t−θ0)/t→0P_0^{-1}(\hat\theta_t - \theta_0)/t \to 0 because θ^t\hat\theta_t is bounded. For the second term, let ϵ>0\epsilon > 0 and choose KK with ∣θ^k−θ∞∣<ϵ|\hat\theta_k - \theta_\infty| < \epsilon for k≥Kk \ge K. For t>Kt > K, the terms with k≥Kk \ge K satisfy ∣θ^t−θ^k∣<2ϵ|\hat\theta_t - \hat\theta_k| < 2\epsilon, so their sum divided by tt is at most 2ϵ1t∑k<t∣φk∣2≤2ϵM2\epsilon\frac1t\sum_{k<t}|\varphi_k|^2 \le 2\epsilon M. The terms with k<Kk < K are a fixed finite sum, which divided by tt goes to 00. So the lim sup⁡\limsup of the norm is at most 2ϵM2\epsilon M for every ϵ\epsilon, which proves the limit. The components of φkyk+1\varphi_k y_{k+1} are yk+1yk−iy_{k+1}y_{k-i} for i=0,…,nsi = 0, \dots, n_s and yk+1uk−jy_{k+1}u_{k-j} for j=1,…,nrj = 1, \dots, n_r, which give the stated correlations. □\square

Claim 4 (the example limit is the minimum variance law). For the plant yt+1=p0yt+but+et+1+c ety_{t+1} = p_0 y_t + b u_t + e_{t+1} + c\,e_t with ∣c∣<1|c| < 1 and ns=nr=0n_s = n_r = 0, a constant gain ut=gytu_t = g y_t gives yt+1=p yt+et+1+c ety_{t+1} = p\,y_t + e_{t+1} + c\,e_t with p=p0+bgp = p_0 + b g. For ∣p∣<1|p| < 1 this is a stationary ARMA(1,1) process, and its correlations are ry(0)=σ2(1+c2+2pc)/(1−p2)r_y(0) = \sigma^2(1 + c^2 + 2pc)/(1 - p^2) and ry(1)=σ2(1+pc)(p+c)/(1−p2)r_y(1) = \sigma^2(1 + pc)(p + c)/(1 - p^2). Since ∣pc∣<1|pc| < 1, ry(1)=0r_y(1) = 0 if and only if p=−cp = -c, that is g=−(p0+c)/bg = -(p_0 + c)/b. Then yt+1+cyt=et+1+cety_{t+1} + c y_t = e_{t+1} + c e_t, so yt=ety_t = e_t up to a term (−c)t(y0−e0)(-c)^t(y_0 - e_0) that goes to zero, and the variance is σ2\sigma^2, the minimum: every causal law gives yt+1=et+1+(a function of the data up to t)y_{t+1} = e_{t+1} + (\text{a function of the data up to } t), whose variance is at least σ2\sigma^2 because et+1e_{t+1} is independent of the data up to tt. With p0=0.9p_0 = 0.9, b=0.5b = 0.5, c=0.5c = 0.5 this is g=−2.8g = -2.8, the value of the page. So by Claim 3, if the estimate converges and the loop is bounded in mean square, the limit gain is −2.8-2.8.

Remark. Claims 3 and 4 assume convergence; they do not prove it. Ljung (1977) proved convergence with probability one under a positive real condition on CC (a theorem not reproduced here). The tests measure convergence on fixed noise sequences.

Complexity

With d=ns+1+nrd = n_s + 1 + n_r parameters, one RLS step costs O(d2)O(d^2) operations in the real-RAM model and the control law costs O(d)O(d). So NN samples cost O(Nd2)O(N d^2), and the memory is the d×dd \times d matrix PP, O(d2)O(d^2). An indirect self-tuner adds the cost of the design, for example solving a polynomial equation of size O(n)O(n) by Gaussian elimination in O(n3)O(n^3) at each sample.

Properties

  • Self-tuning property. Theorem (Åström and Wittenmark 1973): if the estimates converge, the limit controller is the minimum variance controller, for a model with enough parameters. The bias of least squares under coloured noise does not matter, because the controller, not the plant, is estimated.
  • Convergence. Theorem (Ljung 1977): convergence with probability one holds under a positive real condition on the noise polynomial CC. Without it, the estimates can fail to converge.
  • Choice of β0\beta_0. Only the sign of β0\beta_0 must be correct for the fixed point, but the speed of convergence depends on the ratio b1/β0b_1/\beta_0. The table shows faster convergence for β0\beta_0 near or below b1b_1 (measurement).
  • Not a dual controller. The regulator ignores the uncertainty of the estimate when it chooses the input. It does not add probing signals, so the estimates can stop learning when the loop is quiet.
  • Minimum phase plants only. The minimum variance law cancels the zeros of BB. An unstable zero gives an unbounded input. Indirect self-tuners with pole placement avoid this.

Variants and improvements

  • Indirect self-tuners. Estimate AA and BB by RLS and solve a design problem at each sample, for example adaptive pole placement or a linear quadratic design. This allows non-minimum phase plants.
  • Generalized minimum variance. Add a penalty on the input to the cost, which limits the control effort and can handle some non-minimum phase plants (Clarke and Gawthrop).
  • Forgetting. A forgetting factor λ<1\lambda < 1 tracks slowly changing parameters. Without excitation, PP then grows without bound (estimator windup); constant trace or directional forgetting limits this.
  • Predictive self-tuners. Generalized predictive control and model predictive control with an online model use a cost over a longer horizon.
  • Model reference adaptive control. MRAC is the continuous-time, direct counterpart with a Lyapunov design in place of least squares.

When to use it

Use a self-tuning regulator for a sampled process with slowly varying dynamics and a noise disturbance, where a model of fixed structure is acceptable, for example a process control loop whose gain drifts with the production rate. Use the minimum variance form only for minimum phase plants with a known delay. For a plant with a known operating schedule, gain scheduling is often simpler, and for a one-time tuning, relay autotuning of a PID controller is the usual industrial choice.

Pitfalls

  • Wrong delay. The law assumes a delay of one sample. With a longer delay, the one step predictor is wrong and the loop can go unstable; use the dd step predictor.
  • Wrong sign of β0\beta_0. The fixed point then has the wrong sign of the gain.
  • Estimator windup. With forgetting and a quiet loop, PP grows, and a later disturbance gives a large jump of the estimate.
  • Bursting. Without excitation the estimates can drift slowly until the closed loop becomes unstable, then the burst of data corrects them, and the cycle repeats.
  • Non-minimum phase zeros. Sampling a continuous plant of relative degree at least 3 with a short sampling period hh creates zeros outside the unit circle (a theorem of Åström, Hagander and Sternby, 1984); the minimum variance law then gives an unbounded input.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

self_tuning_regulator.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/self-tuning-regulator/. The authors are listed in prov/KY0VB7.jsonl.

"""The direct minimum variance self-tuning regulator of Astrom and Wittenmark.

Plant (ARMAX, delay one sample):

    y_t = -a_1 y_(t-1) - ... - a_n y_(t-n) + b_1 u_(t-1) + ... + b_m u_(t-m)
          + e_t + c_1 e_(t-1) + ... + c_k e_(t-k),

with white noise e_t. The regulator estimates by recursive least squares
the predictor model

    y_(t+1) - beta0 u_t = s_0 y_t + ... + s_ns y_(t-ns) + r_1 u_(t-1) + ... + r_nr u_(t-nr),

with beta0 fixed (a guess of b_1), and applies the control that makes the
predicted output zero (certainty equivalence):

    u_t = -(s_0 y_t + ... + r_nr u_(t-nr)) / beta0.

rls_update works with float or Fraction entries; with Fraction it is exact.
"""

import random

__all__ = ["rls_update", "str_minimum_variance", "mv_gain_first_order"]


def rls_update(theta, P, phi, z, lam=1):
    """One recursive least squares step with forgetting factor lam.

    theta: estimate (list), P: covariance (list of rows), phi: regressor,
    z: new measurement. Returns (theta, P) for the data up to z.
    """
    n = len(theta)
    Pphi = [sum(P[i][j] * phi[j] for j in range(n)) for i in range(n)]
    den = lam + sum(phi[i] * Pphi[i] for i in range(n))
    K = [v / den for v in Pphi]  # @line L5
    eps = z - sum(phi[i] * theta[i] for i in range(n))
    theta = [theta[i] + K[i] * eps for i in range(n)]  # @line L6
    P = [[(P[i][j] - K[i] * Pphi[j]) / lam for j in range(n)] for i in range(n)]  # @line L7
    return theta, P


def str_minimum_variance(a, b, c, beta0, N, seed, ns=0, nr=0, sigma=1.0, p0=100.0, lam=1.0,
                         theta0=None, adapt=True):
    """Run the self-tuning regulator for N samples on the ARMAX plant.

    a, b, c are the coefficient lists [a_1..a_n], [b_1..b_m], [c_1..c_k].
    The noise e_t is Gaussian with standard deviation sigma from
    random.Random(seed). The estimate starts at theta0 (zeros if None).
    With adapt=False the estimate stays at theta0, which gives a fixed
    controller. Returns (thetas, ys, us, es): the estimate after each
    sample, the outputs, the inputs and the noise.
    """
    rng = random.Random(seed)
    d = ns + 1 + nr
    theta = [0.0] * d if theta0 is None else [float(v) for v in theta0]  # @line L1
    P = [[p0 if i == j else 0.0 for j in range(d)] for i in range(d)]
    hist = max(len(a), len(b), len(c), ns + 1, nr + 1) + 1
    ys, us, es = [0.0] * hist, [0.0] * hist, [0.0] * hist
    thetas = []
    phi_prev = None
    for _ in range(N):  # @line L2
        e = rng.gauss(0.0, sigma)
        y = (-sum(ai * ys[-1 - i] for i, ai in enumerate(a))
             + sum(bi * us[-1 - i] for i, bi in enumerate(b))
             + e + sum(ci * es[-1 - i] for i, ci in enumerate(c)))  # @line L3
        ys.append(y)
        es.append(e)
        if phi_prev is not None and adapt:
            z = y - beta0 * us[-1]  # @line L4
            theta, P = rls_update(theta, P, phi_prev, z, lam)
        phi = [ys[-1 - i] for i in range(ns + 1)] + [us[-1 - i] for i in range(nr)]
        u = -sum(t * p for t, p in zip(theta, phi)) / beta0  # @line L8
        us.append(u)
        phi_prev = phi
        thetas.append(list(theta))
    return thetas, ys[hist:], us[hist:], es[hist:]  # @line L9


def mv_gain_first_order(a, b, c):
    """Minimum variance gain for y_(t+1) = -a y_t + b u_t + e_(t+1) + c e_t.

    u_t = g y_t with g = (a - c) / b makes y_t = e_t.
    """
    return (a - c) / b
test_self_tuning_regulator.py 79 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/self-tuning-regulator/. The authors are listed in prov/KY0VB7.jsonl.

"""Tests for the minimum variance self-tuning regulator."""

import random
import unittest
from fractions import Fraction

from self_tuning_regulator import mv_gain_first_order, rls_update, str_minimum_variance

# y_(t+1) = 0.9 y_t + 0.5 u_t + e_(t+1) + 0.5 e_t; minimum variance law u = -2.8 y
PLANT = ([-0.9], [0.5], [0.5])


def stats(ys, skip=0):
    y = ys[skip:]
    n = len(y)
    r0 = sum(v * v for v in y) / n
    r1 = sum(y[i] * y[i + 1] for i in range(n - 1)) / n
    return r0, r1 / r0


class TestRLS(unittest.TestCase):
    def test_exact_against_weighted_least_squares(self):
        # reference: theta = (lam^t P0^-1 + sum lam^(t-i) phi phi^T)^-1 sum lam^(t-i) phi z
        rng = random.Random(1)
        for lam in (Fraction(1), Fraction(9, 10)):
            p0 = Fraction(100)
            theta = [Fraction(0), Fraction(0)]
            P = [[p0, Fraction(0)], [Fraction(0), p0]]
            data = []
            for t in range(1, 13):
                phi = [Fraction(rng.randint(-5, 5)), Fraction(rng.randint(-5, 5))]
                z = Fraction(rng.randint(-9, 9), rng.randint(1, 4))
                data.append((phi, z))
                theta, P = rls_update(theta, P, phi, z, lam)
                M = [[lam ** t / p0 if i == j else Fraction(0) for j in range(2)] for i in range(2)]
                v = [Fraction(0), Fraction(0)]
                for i, (ph, zz) in enumerate(data, start=1):
                    w = lam ** (t - i)
                    for r in range(2):
                        v[r] += w * ph[r] * zz
                        for c in range(2):
                            M[r][c] += w * ph[r] * ph[c]
                det = M[0][0] * M[1][1] - M[0][1] * M[1][0]
                want = [(v[0] * M[1][1] - M[0][1] * v[1]) / det,
                        (M[0][0] * v[1] - M[1][0] * v[0]) / det]
                self.assertEqual(theta, want)


class TestMinimumVariance(unittest.TestCase):
    def test_true_gain_gives_white_output(self):
        # reference: with the minimum variance gain the output equals the noise
        g = mv_gain_first_order(-0.9, 0.5, 0.5)
        self.assertAlmostEqual(g, -2.8, places=12)
        _, ys, _, es = str_minimum_variance(*PLANT, 1.0, 2000, 5, theta0=[-g], adapt=False)
        self.assertLess(max(abs(y - e) for y, e in zip(ys, es)), 1e-9)

    def test_self_tuner_reaches_minimum_variance(self):
        for seed in (0, 1):
            th, ys, _, es = str_minimum_variance(*PLANT, 1.0, 5000, seed)
            self.assertLess(abs(th[-1][0] - 2.8), 0.25)
            r0, rho1 = stats(ys, 1000)
            e0 = sum(e * e for e in es[1000:]) / len(es[1000:])
            self.assertLess(abs(r0 - e0), 0.1)
            self.assertLess(abs(rho1), 0.15)

    def test_much_better_than_open_loop(self):
        # open loop variance (1 + c^2 + 2 a c) / (1 - a^2) = 2.15 / 0.19 = 11.3
        _, y_ol, _, _ = str_minimum_variance(*PLANT, 1.0, 4000, 2, adapt=False)
        _, y_str, _, _ = str_minimum_variance(*PLANT, 1.0, 4000, 2)
        v_ol, v_str = stats(y_ol, 500)[0], stats(y_str, 500)[0]
        self.assertGreater(v_ol, 8.0)
        self.assertLess(v_str, 1.2)


if __name__ == "__main__":
    unittest.main()

History

Kalman (1958) built a self-optimizing controller that combined least squares estimation of a plant model with a control design, an early form of the idea. Åström and Wittenmark (1973) proposed the self-tuning regulator with least squares estimation and minimum variance control and proved the self-tuning property. Ljung (1977) proved convergence with an ordinary differential equation that describes the average behaviour of the estimates. Clarke and Gawthrop added a penalty on the control signal, and many industrial self-tuners followed in the late 1970s and the 1980s.

References

  1. Karl Johan Åström and Björn Wittenmark, Adaptive Control, second edition, Addison-Wesley 1995 (Dover reprint 2008), Chapter 3, Deterministic self-tuning regulators, and Chapter 4, Stochastic and predictive self-tuning regulators (the direct minimum variance self-tuner)
  2. K. J. Åström and B. Wittenmark, On self tuning regulators, Automatica 9(2), 1973, pages 185 to 199 (the algorithm and the self-tuning property)
  3. R. E. Kalman, Design of a self-optimizing control system, Transactions of the ASME 80, 1958, the whole paper (least squares estimation combined with a control design)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example