direct_data_driven_mpc.nonlinear_data_driven_mpc_controller.NonlinearDataDrivenMPCController#
- class NonlinearDataDrivenMPCController[source]#
A class that implements a Data-Driven Model Predictive Control (MPC) controller for nonlinear systems. The implementation is based on research by J. Berberich et al., as described in [2].
References
[2] J. Berberich, J. Köhler, M. A. Müller and F. Allgöwer, “Linear Tracking MPC for Nonlinear Systems—Part II: The Data-Driven Case,” in IEEE Transactions on Automatic Control, vol. 67, no. 9, pp. 4406-4421, Sept. 2022, doi: 10.1109/TAC.2022.3166851.
- __init__(n: int, m: int, p: int, u: ndarray, y: ndarray, L: int, Q: ndarray, R: ndarray, S: ndarray, y_r: ndarray, lamb_alpha: float, lamb_sigma: float, U: ndarray, Us: ndarray, alpha_reg_type: AlphaRegType = AlphaRegType.ZERO, lamb_alpha_s: float | None = None, lamb_sigma_s: float | None = None, ext_out_incr_in: bool = False, update_cost_threshold: float | None = None, n_mpc_step: int = 1)[source]#
Initialize a Direct Nonlinear Data-Driven MPC with specified system model parameters, an initial input-output data trajectory measured from the system, and Nonlinear Data-Driven MPC parameters.
Note
The input data u used to excite the system to get the initial output data must be persistently exciting of order (L + n + 1), as defined in the Data-Driven MPC formulation in [2].
- Parameters:
n (
int) – The estimated order of the system.m (
int) – The number of control inputs.p (
int) – The number of system outputs.u (
numpy.ndarray) – A persistently exciting input sequence.y (
numpy.ndarray) – The system’s output response to u.L (
int) – The prediction horizon length.Q (
numpy.ndarray) – The output weighting matrix for the MPC formulation.R (
numpy.ndarray) – The input weighting matrix for the MPC formulation.S (
numpy.ndarray) – The output setpoint weighting matrix for the MPC formulation.y_r (
numpy.ndarray) – The system output setpoint.lamb_alpha (
float) – The ridge regularization weight for alpha.lamb_sigma (
float) – The ridge regularization weight for sigma.U (
numpy.ndarray) – An array of shape (m, 2) containing the bounds for the m predicted inputs. Each row specifies the [min, max] bounds for a single input.Us (
numpy.ndarray) – An array of shape (m, 2) containing the bounds for the m predicted input setpoints. Us must be a subset of U. Each row specifies the [min, max] bounds for a single input.alpha_reg_type (
AlphaRegType) – The alpha regularization type for the Nonlinear Data-Driven MPC formulation.lamb_alpha_s (
float | None) – The ridge regularization weight for alpha_s for a controller that uses an approximation of alpha_Lin^sr(D_t) for the regularization of alpha.lamb_sigma_s (
float | None) – The ridge regularization weight for sigma_s for a controller that uses an approximation of alpha_Lin^sr(D_t) for the regularization of alpha.ext_out_incr_in (
bool) –The controller structure:
If True, the controller uses an extended output representation (y_ext[k] = [y[k], u[k]]) and input increments (u[k] = u[k-1] + du[k-1]).
If False, the controller operates as a standard controller with direct control inputs and without system state extensions.
Defaults to False.
update_cost_threshold (
float | None) – The tracking cost value threshold. Online input-output data updates are disabled when the tracking cost value is less than this value. If None, input-output data is always updated online. Defaults to None.n_mpc_step (
int) – The number of consecutive applications of the optimal input for an n-Step Data-Driven MPC Scheme (multi-step). Defaults to 1.
References
[2] J. Berberich, J. Köhler, M. A. Müller and F. Allgöwer, “Linear Tracking MPC for Nonlinear Systems—Part II: The Data-Driven Case,” in IEEE Transactions on Automatic Control, vol. 67, no. 9, pp. 4406-4421, Sept. 2022, doi: 10.1109/TAC.2022.3166851.
- ext_out_incr_in: bool#
The controller structure:
If True, the controller uses an extended output representation (y_ext[k] = [y[k], u[k]]) and input increments (u[k] = u[k-1] + du[k-1]).
If False, the controller operates as a standard controller with direct control inputs and without system state extensions.
Defaults to False.
- du: ndarray#
The input increment trajectory for a controller that uses input increments (ext_out_incr_in = True).
- U: ndarray#
An array of shape (m, 2) containing the bounds for the m predicted inputs. Each row specifies the [min, max] bounds for a single input.
- Us: ndarray#
An array of shape (m, 2) containing the bounds for the m predicted input setpoints. Us must be a subset of U. Each row specifies the [min, max] bounds for a single input.
- alpha_reg_type: AlphaRegType#
The alpha regularization type for the Nonlinear Data-Driven MPC formulation.
- lamb_alpha_s: float#
The ridge regularization weight for alpha_s for a controller that uses an approximation of alpha_Lin^sr(D_t) for the regularization of alpha.
- lamb_sigma_s: float#
The ridge regularization weight for sigma_s for a controller that uses an approximation of alpha_Lin^sr(D_t) for the regularization of alpha.
- update_cost_threshold: float#
The tracking cost value threshold. Online input-output data updates are disabled when the tracking cost value is less than this value.
- n_mpc_step: int#
The number of consecutive applications of the optimal input for an n-Step Data-Driven MPC Scheme (multi-step).
- update_and_solve_data_driven_mpc(warm_start: bool = False) None[source]#
Update the Data-Driven MPC optimization parameters, solve the problem, and store the optimal control input.
This method performs the following tasks:
Constructs Hankel matrices using the latest measured input-output data. If the tracking cost value from the previous solution is small enough (less than update_cost_threshold), omits this step and the previously defined matrices are used.
Updates the MPC optimization parameters to use the latest input-output measurements. Additionally, it updates the value of alpha_Lin^sr(D_t) if alpha is not regularized with respect to zero.
Note: The value of alpha_Lin^sr(D_t) is computed during the optimization parameter update.
Solves the MPC problem and stores the resulting optimal control input.
Stores the optimal value of alpha if alpha is regularized with respect to its previous optimal value (see Section V of [2]).
Toggles online data updates based on the current tracking cost value.
References
[2]: See class-level docstring for full reference details.
- get_problem_solve_status() str[source]#
Get the solve status of the optimization problem of the Data-Driven MPC formulation.
- Returns:
str – The status of the optimization problem after attempting to solve it (e.g., “optimal”, “optimal_inaccurate”, “infeasible”, “unbounded”).
- get_optimal_cost_value() float[source]#
Get the cost value corresponding to the solved optimization problem of the Data-Driven MPC formulation.
- Returns:
float – The optimal cost value of the solved MPC optimization problem.
- get_optimal_control_input_at_step(n_step: int = 0) ndarray[source]#
Get the optimal control input (u) from the MPC solution corresponding to a specified time step in the prediction horizon [0, L].
- Parameters:
n_step (
int) – The time step of the optimal control input to retrieve. It must be within the range [0, L].- Returns:
np.ndarray – An array containing the optimal control input for the specified prediction time step.
Note
This method assumes that the optimal control input from the MPC solution has been stored in the optimal_u attribute. For a controller that uses an extended output representation and input increments, the last du value should contain the optimal control input increment computed from the previous MPC solution (optimal_du[:m]).
- Raises:
ValueError – If n_step is not within the range [0, L].
- get_du_value_at_step(n_step: int = 0) ndarray | None[source]#
Get the optimal control input increment (du) from the MPC solution corresponding to a specified time step in the prediction horizon [0, L].
- Parameters:
n_step (
int) – The time step of the optimal control input to retrieve. It must be within the range [0, L].- Returns:
np.ndarray | None – An array containing the optimal control input increment for the specified prediction time step if the controller uses an extended output representation and input increments. Otherwise, returns None.
Note
This method assumes that the optimal_du attribute contains the optimal control input increments from the MPC solution.
- store_input_output_measurement(u_current: ndarray, y_current: ndarray, du_current: ndarray | None = None) None[source]#
Store an input-output measurement pair for the current time step in the input-output storage variables. If the controller uses an extended output representation and input increments, the input increment corresponding to the current input measurement is also stored.
This method updates the input-output storage variables u, y and du by shifting the arrays and replacing the oldest measurements with the current ones.
- Parameters:
u_current (
numpy.ndarray) – The control input (u[k]) for the current time step, expected to match the dimensions of prior inputs.y_current (
numpy.ndarray) – The measured system output for the current time step, expected to match the dimensions of prior outputs. This output should correspond to the system’s response to u_current, as both represent a trajectory of the system.du_current (
np.ndarray | None) – The control input increment (du[k] = u[k+1] - u[k]) for the current time step, expected to match the dimensions of prior inputs.
- Raises:
ValueError – If u_current, y_current, or du_current do not match the expected dimensions.
Note
This method updates the u, y, and du arrays.
References
[2]: See class-level docstring for full reference details.
- set_input_output_data(u: ndarray, y: ndarray) None[source]#
Set the variables for the current input-output measurements.
This method assigns the provided input-output measurements to the arrays storing the current input-output measurements, u and y.
- Parameters:
u (
numpy.ndarray) – An array containing the current measured control input. Expected to have a shape of (N, m), where ‘N’ is the trajectory length and ‘m’ is the dimension of the input.y (
numpy.ndarray) – An array containing the current measured system output. Expected to have a shape of (N, p) where ‘N’ is the trajectory length and ‘p’ is the dimension of the output.
- Raises:
ValueError – If u or y do not have correct dimensions.
Note
This method sets the values of the u and y attributes with the provided new input-output data.
- set_output_setpoint(y_r: ndarray) None[source]#
Set the system output setpoint of the Data-Driven MPC controller.
- Parameters:
y_r (
numpy.ndarray) – The setpoint for system outputs.- Raises:
ValueError – If y_r does not have the expected dimensions.
Note
This method sets the values of the y_r attribute with the provided new setpoint and updates the value of y_r_param to update the data-driven MPC controller setpoint.