control//system identification//ARX model

An ARX model is a linear black-box dynamic model in which today's output is a weighted sum of past outputs and past inputs plus an error term, and it is the first model an engineer fits to logged data when no physics is at hand: a thermal zone of a building, a motor's speed response, a level loop. The name says what it holds: autoregressive (past outputs) with exogenous input (past commands). With \(n_a\) output lags and \(n_b\) input lags,


An ARX model is a linear black-box dynamic model in which today's output is a weighted sum of past outputs and past inputs plus an error term, and it is the first model an engineer fits to logged data when no physics is at hand: a thermal zone of a building, a motor's speed response, a level loop. The name says what it holds: autoregressive (past outputs) with exogenous input (past commands). With nan_ana​ output lags and nbn_bnb​ input lags,

yk=−∑i=1naai yk−i+∑j=1nbbj uk−j+ek.y_k=-\sum_{i=1}^{n_a}a_i\,y_{k-i}+\sum_{j=1}^{n_b}b_j\,u_{k-j}+e_k.yk​=−i=1∑na​​ai​yk−i​+j=1∑nb​​bj​uk−j​+ek​.

The model is linear in its coefficients, so fitting is least squares: stack past outputs and inputs as columns of a regressor matrix, the current outputs as the target, and solve. For a second-order model the columns are −yk−1,−yk−2,uk−1,uk−2-y_{k-1},-y_{k-2},u_{k-1},u_{k-2}−yk−1​,−yk−2​,uk−1​,uk−2​, one row per sample of a test run with a PRBS or a sweep; numpy.linalg.lstsq returns a1,a2,b1,b2a_1,a_2,b_1,b_2a1​,a2​,b1​,b2​ in one line. The coefficients then give a discrete transfer function and its poles, which a controller design can use directly.

The ease of fitting hides a trap: the fit minimizes the one-step-ahead error, which a model can make tiny by learning that the next sample resembles the last. The fitted model is therefore judged in free-run simulation, driven only by the inputs, on data not used for fitting (model validation).

The order is a choice. Too few lags miss dynamics (the residuals stay coloured); too many fit noise and give spurious poles. Increase nan_ana​ and nbn_bnb​ until free-run error stops improving on validation data, and check the residual whiteness.

The error term is assumed white and to enter in a particular way, which biases the estimate when the real noise is coloured. ARMAX adds moving-average noise terms to model coloured noise properly, at the price of a nonlinear fit.

It is the input-driven sibling of the autoregressive model of forecasting, which predicts a series from its own past only. Same regression, different question: an ARX model says how the output answers the input, which is what a controller needs.

A black box knows only the operating range it was fed. Outside it, a grey-box model degrades gracefully because its physics still holds; an ARX model can do anything (system identification).