Skip to content

chc.lqr

Stability tier: stable.

LQR / AKOR: the r_θ→0 closed-form optimum and Riccati cross-checks.

For the linear(-ised) known system this is the analytic control optimum the learned controller must approach (a correctness limit). Maxima (exact symbolic) is the authority; scipy is the float64 numeric, cross-checked against PARI high-precision and Octave (see validation/).

linearize_continuous(dyn, x, u)

Jacobians (A, B) = (∂f/∂x, ∂f/∂u) of the continuous vector field at (x, u).

linearize_discrete(dyn, x, u, dt)

Jacobians (A_d, B_d) of one step of chc.integrate.rk4_step at (x, u): RK4's, or the Euler map of a field fitted to it.

continuous_lqr(a, b, q, r)

Solve the continuous ARE; return (P, K) with the optimal feedback u = -K x.

Raises:

Type Description
ValueError

if r is not positive definite. An action r charges nothing or less for leaves the cost no least-cost feedback, and the ARE's root is no optimum; SciPy's solver read an indefinite r and returned a gain.

finite_horizon_dlqr(a, b, q, r, qf, horizon)

Backward Riccati recursion for the finite-horizon discrete LQ problem.

Returns time-varying gains gains of shape (H, m, n) (u_k = -gains[k] x_k) and the initial cost-to-go P_0 (optimal cost 0.5 x0ᵀ P_0 x0).

Raises:

Type Description
ValueError

if r + bᵀ P_{k+1} b, the cost's curvature in the action at some step with the later steps' feedback in place, is not positive definite. The cost then has no least action sequence: the cost less its optimum is the sum over the steps of that curvature's quadratic form in each action's departure from its feedback, so a direction it does not charge lowers the cost, or leaves it flat. The recursion read an r of -1 and returned the gains of a saddle. Where it holds, as wherever r is positive definite and q and qf are not negative, the gains are the minimiser's.

dlqr_feedback_controls(dyn, x0, gains, dt)

Simulate u_k = -gains[k] x_k and return the realised control sequence (H, m).

Step k runs from t = k * dt, the clock of chc.integrate.rollout, so a plant that reads the time sees each step at its own.

linearized_regret_certificate(dyn, dyn_hat, x_star, u_star, q, r, x0, dt)

Local certainty-equivalence suboptimality certificate for a (non)linear plant.

Linearises the true dyn and estimated dyn_hat at (x_star, u_star) and returns the LQ certainty-equivalence regret bound (chc.regret.certainty_equivalence_gap) for that linearisation -- a local certificate valid where model error dominates the plant's curvature. Exact on a linear plant; empirically tracks the nonlinear closed-loop suboptimality to ~1.1x in the small-model-error regime. Extends the LQ guarantee of chc.regret to nonlinear plants, locally.

It is the regulator's gap about (x_star, u_star), read from the deviation x0 - x_star: up to 0.18.0 it read from x0 itself, as if the regulator's origin were 0, which moved it wherever x_star is not 0. The linearisation drops the RK4 step's constant term, so (x_star, u_star) should be an equilibrium of both models' steps. The cost is sum_k x_k' q x_k + u_k' r u_k, without the halves of chc.cost.QuadraticCost, so in that cost's units the gap is half what this returns.