Algorithmresearch
L1 adaptive control
Also called L1 adaptive controller.
A fast adaptation law with a low-pass filter on the control signal that separates adaptation from robustness and bounds the transient.
- Time
- O(N n^2) worst
- Space
- O(n^2) extra
- Where
- N = the number of integration steps; n = the order of the plant
- Model
- Real RAM
- Properties
- deterministicnot exactonlineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Chengyu Cao, Naira Hovakimyan, 2006
L1 adaptive control is a predictor based form of model reference adaptive control in which the control signal passes through a strictly proper low-pass filter , so that the adaptation gain can be made very large without high frequency content in the input. Its theory gives bounds on the transient in the norm of the supremum over time (the norm): the distance between the adaptive closed loop and a non-adaptive reference system is of order , under a small gain condition on the norm of the impulse response of . The bandwidth of , not , then sets the robustness margins. The method has been disputed: Ioannou and co-authors and Ortega and Panteley (2014) argue that with a measured state it is an MRAC with a filtered input, and that in the limit of a large it becomes a fixed linear controller.
In plain words
An adaptive controller learns an unknown part of the plant while it controls it. Fast learning gives good tracking, but it also makes the control signal jump and shake, and that can excite parts of the plant that the model leaves out. L1 adaptive control lets the learning run very fast inside a software copy of the plant, the predictor, and then smooths the control signal with a filter before it reaches the real plant. The filter decides how aggressive the control can be; the learning speed only decides how closely the result matches an ideal controller that knows the unknown part. The price is that the filter must leave out some of the correction, so the loop cannot cancel the uncertainty at high frequencies.
The problem
The plant is with the state measured, a known Hurwitz matrix , a known , and unknown parameters in known sets: here the scalar case with and is treated, so
The aim is that tracks the response of with , with a transient that is bounded uniformly in time and a control signal without high frequency components, for every in the set.
The algorithm
Let solve , choose , a projection set given by and , and the filter . With , the controller is
- the state predictor ,
- the adaptive law , with the smooth projection operator of parameter projection,
- the control law .
L1-ADAPTIVE(Γ, θ_b, ε, ω_c, k_g, dt, N)- 1
θ̂ ← θ̂₀; x̂ ← x(0); u ← 0 - 2
for i ← 0 to N - 1 do - 3
r ← r(t); measure x ▷ t = i dt - 4
x̃ ← x̂ - x ▷ prediction error - 5
x̂' ← a_m x̂ + b (u + θ̂ x) ▷ state predictor - 6
θ̂' ← Γ Proj(θ̂, -x̃ p b x) ▷ adaptation with projection - 7
u' ← ω_c (k_g r - θ̂ x - u) ▷ low-pass filter C(s) - 8
advance x, x̂, θ̂ and u by one RK4 step of length dt - 9
return θ̂
The projection uses . It returns unchanged when or points inward, and otherwise , so for all time. The difference from MRAC is in line L7: the law of MRAC passes through .
Example
Take , , the unknown (so the open loop pole is at ), , , rad/s, , and the step . Everything starts at zero, and .
The condition. has the impulse response . It changes sign once, at , and integrates to , so . With :
| 1 | 0.7358 | 1.472 |
| 2 | 0.5000 | 1.000 |
| 5 | 0.2675 | 0.535 |
| 10 | 0.1549 | 0.310 |
| 20 | 0.0854 | 0.171 |
| 50 | 0.0369 | 0.074 |
The condition holds for and above, and fails for .
The reference system. With the loop is linear, with the characteristic polynomial and the poles and . Its step response is , and .
The adaptive loop. RK4 with s over 10 s. The bound on is (see Correctness). These are measurements, except the bound.
| bound | |||||
|---|---|---|---|---|---|
| 10 | 0.4955 | 0.6708 | 0.5316 | 1.162 | 1.4939 |
| 100 | 0.1759 | 0.2121 | 0.1817 | 0.595 | 1.4955 |
| 1000 | 0.0598 | 0.0671 | 0.0558 | 0.303 | 1.4962 |
The distance to the reference system falls by about per factor 10 of in , and by about 2 in . In every run is within 0.005 of 1, and reaches 2.0976, just inside the projection limit , during the first transient.
Correctness
The proof in proofs/correctness.md gives the prediction error bound in full. With and , the error equation is , and the projection gives whenever . So when , which gives , a theorem; the general form uses the largest possible , in place of . The second step is the main theorem of Cao and Hovakimyan, stated here and not reproved: if , the reference system is bounded in the norm, and and with constants that do not depend on . The proof combines the prediction error bound with the small gain theorem for the filtered loop.
Proof: The L1 adaptive law with projection bounds the prediction error by a term of order one over the square root of the adaptation gainfull
Notation is that of the page. The plant is with , and . The predictor is , the law is with , , and . The projection is if and , and otherwise, with .
Claim 1 (the estimate stays in the band). If , then for all .
Proof. The bound is the set . Along solutions, . When and , this is , which is at most when . In the other case, either , or and the derivative is . So cannot increase while , and it cannot cross the level from below.
Claim 2 (projection does not increase the parameter error). If , then .
Proof. The difference is nonzero only when and , and then it equals . Here means , and has the sign of , so has the sign of . Also has the sign of , because . So and .
Claim 3 (Lyapunov function). Let . Then .
Proof. Subtract the plant from the predictor: . Since is constant, . Then
With the second and third terms cancel, , and the last term is at most by Claim 2.
Claim 4 (the bound). If , then for all ,
Proof. The solution exists for all : by Claim 1, is bounded, and for a given the equations of , and are linear with bounded coefficients, so they have no finite escape time. By Claim 3, . For the second form, .
Claim 4 holds whatever the input is, so it needs no assumption on the filter. It is the first step of the analysis of Cao and Hovakimyan. Their main theorem, which is not reproved here, adds the condition for and , uses the small gain theorem to show that the reference system with the true in the control law is bounded in the norm, and then shows and .
The L1 norm in the example. For with , partial fractions give . The function is positive for and negative for , where , that is . Since , , which is the formula of the page. For , and the norm is . The tests check the formula against a numerical integral and the bound of Claim 4 against the simulation.
Complexity
For an -dimensional state, each evaluation of the right-hand side costs for the plant, the predictor and the matrix , and for the adaptive law and the filter, in the real-RAM model. RK4 steps cost , and the memory is for and . The large makes the adaptive law stiff, so must shrink as grows: with RK4 the product of and the adaptation rate must stay below about 2.8 (a rule of thumb from the stability region of RK4). In an implementation on a computer, the sampling period of the adaptive law limits the useful .
Properties
- Uniform transient bounds. Theorem (Cao and Hovakimyan): under the norm condition the state and the input stay within of a linear reference system, uniformly in time, not only as .
- Robustness set by the filter. The time delay margin of the loop is bounded below by a quantity that depends on and not on , as (theorem in Hovakimyan and Cao, Chapter 2).
- Trade-off in the filter. A wider filter bandwidth makes smaller and the reference system closer to the ideal model, but it lowers the robustness margins. The table shows how falls with .
- No parameter convergence claim. As in MRAC, need not converge to ; the example gives to after 10 s.
- Disputed interpretation. Ioannou and co-authors (2014) argue that with a measured state the scheme is an MRAC with an input filter, and that its claimed advantages can be obtained by standard robust adaptive designs. Ortega and Panteley (2014) show that as the controller tends to a linear time-invariant controller, so the adaptation is not needed for the limit. Hovakimyan and co-authors disputed these readings. This page states the theorems and the critique; it does not decide between them.
Variants and improvements
- Unknown input gain and disturbances. The general architecture estimates , and with three projection laws and uses a filter with a feedback gain in .
- Piecewise constant adaptation. The adaptive law is replaced by a law that updates once per sampling period from the prediction error, which makes the speed of adaptation a matter of (Hovakimyan and Cao treat this law in the later chapters of the book).
- Output feedback. For a plant with only the output measured, the predictor is an output predictor, and the same filter structure applies.
- Nonlinear and time-varying uncertainty. The theory extends to matched nonlinear uncertainty that is Lipschitz in and to unmatched uncertainty.
When to use it
Use L1 adaptive control when the state is measured, the uncertainty is matched and bounded in a known set, and a guaranteed transient bound in the norm matters more than parameter learning, for example in flight control research. The computer that runs it must have a fast sampling rate to support a large . If the analysis of a fixed robust controller with the same filter gives the same margins, as the critique says it often does, prefer the fixed controller.
Pitfalls
- The condition fails. For a narrow filter, , and the bounds do not hold. The example shows the border at .
- Stiff integration. A large needs a small step or sampling period ; otherwise the discrete adaptive law is not a good approximation of the continuous law, and the bounds of the continuous theory do not apply.
- Projection set too small. The proof needs the true inside the set . A wrong set gives a biased estimate and no bound.
- Filter too wide. A filter with a large bandwidth gives a small but passes the high frequency content of to the plant, which the filter was meant to remove.
- Reading as zero. The bounds compare with the reference system, not with the ideal model ; the reference system itself differs from by an amount set by .
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.
# SPDX-License-Identifier: MIT
# Shared helper of the control pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Fixed step simulation for the control pages.
Conventions:
- A continuous-time system is a function f(t, x, u) that returns x' as a
flat list. x is a flat list. u is whatever the control returns (a flat
list, a scalar, or None when there is no control).
- A discrete-time system is a function F(k, x, u) that returns x_(k+1).
- The integrator is the classical 4th order Runge-Kutta method with a fixed
step dt. The input is held constant over each step.
- Time t_k = t0 + k dt is computed by multiplication, not by summation.
- The number of steps round((t1 - t0) / dt) and the hold ratio
round(hold / dt) must match the real ratios within 1e-9 (relative), or
ValueError is raised.
This file holds no controller or observer of a control page.
"""
__all__ = ["rk4_step", "simulate", "simulate_discrete", "lti"]
def _axpy(a, x, y):
return [yi + a * xi for xi, yi in zip(x, y)]
def rk4_step(f, t, x, u, dt):
"""Return x(t + dt) after one RK4 step of x' = f(t, x, u), u held constant."""
k1 = f(t, x, u)
k2 = f(t + dt / 2, _axpy(dt / 2, k1, x), u)
k3 = f(t + dt / 2, _axpy(dt / 2, k2, x), u)
k4 = f(t + dt, _axpy(dt, k3, x), u)
return [xi + dt / 6 * (a + 2 * b + 2 * c + d) for xi, a, b, c, d in zip(x, k1, k2, k3, k4)]
def _ratio(num, den, what):
r = round(num / den)
if abs(r * den - num) > 1e-9 * max(abs(num), abs(den)):
raise ValueError(what + " is not an integer multiple of dt")
return r
def simulate(f, x0, t0, t1, dt, control=None, hold=None):
"""Simulate x' = f(t, x, u) from x(t0) = x0 to t1 with RK4 and step dt.
control(t, x) gives the input. It is called at each sampling instant
t0 + j hold, and its value is held (zero-order hold) until the next
instant. hold must be an integer multiple of dt; hold = None means
hold = dt. With control = None the input is None.
Returns (ts, xs, us): ts has N + 1 times, xs the N + 1 states, and us the
N inputs, where us[k] acts on [ts[k], ts[k + 1]].
"""
if dt <= 0:
raise ValueError("dt must be positive")
n_steps = _ratio(t1 - t0, dt, "t1 - t0")
if n_steps < 0:
raise ValueError("t1 is before t0")
r = 1 if hold is None else _ratio(hold, dt, "hold")
if r < 1:
raise ValueError("hold must be at least dt")
x = list(x0)
ts = [t0]
xs = [list(x)]
us = []
u = None
for k in range(n_steps):
t = t0 + k * dt
if control is not None and k % r == 0:
u = control(t, list(x))
x = rk4_step(f, t, x, u, dt)
ts.append(t0 + (k + 1) * dt)
xs.append(x)
us.append(u)
return ts, xs, us
def simulate_discrete(F, x0, N, control=None):
"""Run x_(k+1) = F(k, x_k, u_k) for k = 0, ..., N - 1.
u_k = control(k, x_k), or None if control is None. Returns (xs, us) with
N + 1 states and N inputs. Exact if F and control are exact.
"""
x = list(x0)
xs = [list(x)]
us = []
for k in range(N):
u = control(k, list(x)) if control is not None else None
x = list(F(k, x, u))
xs.append(x)
us.append(u)
return xs, us
def lti(A, B=None):
"""Return f(t, x, u) = A x + B u for the system x' = A x + B u.
u may be a flat list, a scalar (one input) or None (zero input). B may
be None for a system with no input.
"""
def f(t, x, u):
dx = [sum(a * xi for a, xi in zip(row, x)) for row in A]
if B is None or u is None:
return dx
uu = u if isinstance(u, (list, tuple)) else [u]
return [d + sum(b * ui for b, ui in zip(row, uu)) for d, row in zip(dx, B)]
return f
def _self_test():
import math
f = lti([[-1.0]])
_, xs, _ = simulate(f, [1.0], 0.0, 1.0, 0.01)
assert abs(xs[-1][0] - math.exp(-1.0)) < 1e-9
return True
if __name__ == "__main__":
_self_test()
l1_adaptive_control.py 94 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/l1-adaptive-control/. The authors are listed in prov/S1SMGT.jsonl.
"""L1 adaptive control of a scalar plant with an unknown state feedback gain.
Plant: x' = a_m x + b (u + theta x), a_m < 0, b > 0 known, theta unknown
with |theta| <= theta_b.
Predictor: xh' = a_m xh + b (u + thetah x)
Adaptation: thetah' = Gamma Proj(thetah, -xt p b x), xt = xh - x,
p = -1 / (2 a_m) solves 2 a_m p = -1.
Control: u = C(s) (k_g r - thetah x), C(s) = omega_c / (s + omega_c),
k_g = -a_m / b, as the state u' = omega_c (k_g r - thetah x - u).
Proj is the smooth projection operator with
f(theta) = (theta^2 - theta_b^2) / (eps theta_b^2): it leaves y unchanged
inside the ball |theta| <= theta_b, and on the outer band it removes the
outward part of y in proportion to f, so |thetah| <= theta_b sqrt(1 + eps)
for all time.
The simulation uses the classical RK4 method with a fixed step dt from
ctlsim. The time t1 must be an integer multiple of dt.
"""
import math
from ctlsim import rk4_step
__all__ = ["proj", "l1_simulate", "l1_norm_g", "prediction_bound"]
def _steps(t1, dt):
n = round(t1 / dt)
assert abs(n * dt - t1) <= 1e-9 * max(1.0, abs(t1)), "dt must divide t1"
return n
def proj(theta, y, theta_b, eps):
"""Smooth projection operator for a scalar parameter."""
f = (theta * theta - theta_b * theta_b) / (eps * theta_b * theta_b)
df = 2.0 * theta / (eps * theta_b * theta_b)
if f > 0 and y * df > 0:
return y - f * y # the scalar form of y - f grad f grad f^T y / |grad f|^2
return y
def l1_simulate(theta, theta_b, eps, gamma, omega_c, r, t1, dt, a_m=-1.0, b=1.0,
thetah0=0.0, x0=0.0, every=1):
"""Simulate the L1 adaptive controller. r(t) is the reference.
Returns (ts, xs, xhs, thetahs, us) sampled every `every` steps.
"""
p = -1.0 / (2.0 * a_m)
k_g = -a_m / b
s = [float(x0), float(x0), float(thetah0), 0.0] # @line L1
def f(t, z, _u):
x, xh, th, u = z
rt = r(t) # @line L3
xt = xh - x # @line L4
dx = a_m * x + b * (u + theta * x)
dxh = a_m * xh + b * (u + th * x) # @line L5
dth = gamma * proj(th, -xt * p * b * x, theta_b, eps) # @line L6
du = omega_c * (k_g * rt - th * x - u) # @line L7
return [dx, dxh, dth, du]
N = _steps(t1, dt)
out = ([0.0], [s[0]], [s[1]], [s[2]], [s[3]])
for i in range(N): # @line L2
s = rk4_step(f, i * dt, s, None, dt) # @line L8
if (i + 1) % every == 0:
out[0].append((i + 1) * dt)
for j in range(4):
out[j + 1].append(s[j])
return out # @line L9
def l1_norm_g(omega_c):
"""L1 norm of the impulse response of G(s) = s / ((s + 1)(s + omega_c)).
G = H (1 - C) with H = 1 / (s + 1) and C = omega_c / (s + omega_c). The
impulse response (omega_c e^(-omega_c t) - e^(-t)) / (omega_c - 1)
changes sign once, at t0 = ln(omega_c) / (omega_c - 1), and integrates
to G(0) = 0, so the norm is twice its integral over [0, t0].
"""
if omega_c == 1.0:
return 2.0 / math.e
t0 = math.log(omega_c) / (omega_c - 1.0)
return 2.0 * (math.exp(-t0) - math.exp(-omega_c * t0)) / (omega_c - 1.0)
def prediction_bound(thetah0, theta, gamma, a_m=-1.0):
"""Bound on |xh - x| from V = p xt^2 + (thetah - theta)^2 / Gamma, xt(0) = 0."""
p = -1.0 / (2.0 * a_m)
return math.sqrt((thetah0 - theta) ** 2 / (gamma * p))
test_l1_adaptive_control.py 74 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/l1-adaptive-control/. The authors are listed in prov/S1SMGT.jsonl.
"""Tests for the L1 adaptive controller. RK4 with a fixed step; tolerances are stated."""
import math
import unittest
from l1_adaptive_control import l1_norm_g, l1_simulate, prediction_bound, proj
THETA, THETA_B, EPS, OMEGA_C = 1.5, 2.0, 0.1, 10.0
def step(t):
return 1.0
def run(gamma, thetah0=0.0):
# 10 s with dt = 0.002: 5000 steps
return l1_simulate(THETA, THETA_B, EPS, gamma, OMEGA_C, step, 10.0, 0.002, thetah0=thetah0)
class TestL1Norm(unittest.TestCase):
def test_formula_against_quadrature(self):
# reference: trapezoid rule for the integral of |g| on [0, 40]
for w in (2.0, 5.0, 10.0, 20.0):
n, T = 20000, 40.0
h = T / n
g = [abs((w * math.exp(-w * k * h) - math.exp(-k * h)) / (w - 1.0)) for k in range(n + 1)]
quad = h * (sum(g) - (g[0] + g[-1]) / 2)
self.assertLess(abs(quad - l1_norm_g(w)), 1e-4)
def test_small_gain_condition(self):
# L = theta_b = 2; the condition ||G||_L1 L < 1 holds for omega_c = 5, 10, 20
self.assertAlmostEqual(l1_norm_g(2.0), 0.5, places=12)
self.assertFalse(l1_norm_g(2.0) * THETA_B < 1.0)
for w in (5.0, 10.0, 20.0):
self.assertLess(l1_norm_g(w) * THETA_B, 1.0)
class TestProjection(unittest.TestCase):
def test_operator(self):
self.assertEqual(proj(1.0, 3.0, 2.0, 0.1), 3.0) # inside the ball
self.assertEqual(proj(2.09, -1.0, 2.0, 0.1), -1.0) # pointing inward
f = (2.09 ** 2 - 4.0) / 0.4
self.assertAlmostEqual(proj(2.09, 1.0, 2.0, 0.1), 1.0 - f, places=12)
# on the outer boundary f = 1 and the outward part is removed
self.assertAlmostEqual(proj(2.0 * math.sqrt(1.1), 1.0, 2.0, 0.1), 0.0, places=12)
class TestClosedLoop(unittest.TestCase):
def test_prediction_error_bound_low_gains(self):
for gamma in (10.0, 100.0):
_, xs, xhs, ths, _ = run(gamma)
err = max(abs(a - b) for a, b in zip(xs, xhs))
self.assertLess(err, prediction_bound(0.0, THETA, gamma))
self.assertLessEqual(max(abs(v) for v in ths), THETA_B * math.sqrt(1 + EPS) + 1e-9)
self.assertLess(abs(xs[-1] - 1.0), 0.01)
def test_high_gain_approaches_reference_system(self):
# reference: the same loop with the true theta and no adaptation
_, x_ref, _, _, _ = run(0.0, thetah0=THETA)
self.assertLess(abs(x_ref[-1] - 1.0), 1e-4)
_, xs, xhs, _, _ = run(1000.0)
self.assertLess(max(abs(a - b) for a, b in zip(xs, xhs)), prediction_bound(0.0, THETA, 1000.0))
self.assertLess(max(abs(a - b) for a, b in zip(xs, x_ref)), 0.07)
def test_dt_must_divide_t1(self):
with self.assertRaises(AssertionError):
l1_simulate(THETA, THETA_B, EPS, 10.0, OMEGA_C, step, 1.0, 0.3)
if __name__ == "__main__":
unittest.main()
History
Cao and Hovakimyan introduced the architecture in 2006 and published the analysis with the uniform transient bounds in 2008. The book of Hovakimyan and Cao (2010) collects the state feedback, output feedback and nonlinear versions. In 2014 Ioannou, Annaswamy, Narendra, Jafari, Rudd, Ortega and Boskovic published a critique of the stability and robustness claims, and Ortega and Panteley showed that the controller tends to a fixed linear controller for large . The debate is about the interpretation of the results and their advantage over earlier robust adaptive designs.
References
- Naira Hovakimyan and Chengyu Cao, L1 Adaptive Control Theory: Guaranteed Robustness with Fast Adaptation, SIAM 2010, Chapter 2, State feedback in the presence of matched uncertainties (the architecture, the condition on the L1 norm and the transient bounds)
- C. Cao and N. Hovakimyan, Design and analysis of a novel L1 adaptive control architecture with guaranteed transient performance, IEEE Transactions on Automatic Control 53(2), 2008, pages 586 to 591
- P. A. Ioannou, A. M. Annaswamy, K. S. Narendra, S. Jafari, L. Rudd, R. Ortega and J. Boskovic, L1-adaptive control: stability, robustness, and interpretations, IEEE Transactions on Automatic Control 59(11), 2014, pages 3075 to 3080 (the critique)
- R. Ortega and E. Panteley, Adaptation is unnecessary in L1-adaptive control, International Journal of Control 87(3), 2014, pages 581 to 588 (the limit of a high adaptation gain)
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag S1SMGT Edit this page History Report an error Markdown