DPCUtils#

class do_dpc.dpc.dpc_utils.DPCUtils[source]#

Bases: object

Class for utility function that are used by DPC or DPC inherited classes.

Methods#

calculate_dimensions#

do_dpc.dpc.dpc_utils.DPCUtils.calculate_dimensions(dpc_params, m, p)#

Computes the required dimensions for control execution.

Returns:

Struct containing the computed dimension values.

Return type:

TPCDimensions

check_valid_closed_form_gains#

do_dpc.dpc.dpc_utils.DPCUtils.check_valid_closed_form_gains(dims, gains)#

Validates the dimensions of the closed-form gain matrices.

Parameters:
Raises:

ValueError – If any of the gain matrices have incorrect dimensions.

check_valid_controller_parameters#

do_dpc.dpc.dpc_utils.DPCUtils.check_valid_controller_parameters(dpc_params, m, p)#

Validates the dimensions of controller parameters Q and R.

Parameters:
  • dpc_params (DPCParameters) – Struct for the control parameters.

  • m (int) – Number of control inputs.

  • p (int) – Number of system outputs.

Raises:
  • ValueError – If Q is not a p × p matrix.

  • ValueError – If R is not an m × m matrix.

  • ValueError – If R_delta is not None or an m × m matrix.

  • ValueError – If R_delta_first is not None or an m × m matrix.

check_valid_trajectory_data#

do_dpc.dpc.dpc_utils.DPCUtils.check_valid_trajectory_data(training_data)#

Validates the trajectory data for consistency.

Parameters:

training_data (InputOutputTrajectory) – The trajectory data object containing y (outputs) and u (inputs).

Returns:

(m, p, num_samples), where
  • m (int): Number of control inputs.

  • p (int): Number of system outputs.

  • num_samples (int): Number of collected samples.

Return type:

tuple

Raises:
  • ValueError – If y and u have different numbers of samples.

  • TypeError – If y or u are not NumPy arrays.

  • ValueError – If y or u are empty.

construct_difference_matrix#

do_dpc.dpc.dpc_utils.DPCUtils.construct_difference_matrix(meas_dims, horizon)#

Constructs the difference operator matrix D of size (meas_dims * (horizon - 1), meas_dims * )

The structure of D:

[ 1 0 -1 0 … 0 0 0 0 ] [ 0 1 0 -1 … 0 0 0 0 ] [ . . . . … . . . . ] [ 0 0 0 0 … 1 0 -1 0 ] [ 0 0 0 0 … 0 1 0 -1 ]

This matrix applies finite differences between consecutive time steps.

Return type:

ndarray

Returns:

Difference matrix D

is_positive_definite#

do_dpc.dpc.dpc_utils.DPCUtils.is_positive_definite(matrix)#

Check if a matrix is positive definite.

Return type:

bool

is_positive_semidefinite#

do_dpc.dpc.dpc_utils.DPCUtils.is_positive_semidefinite(matrix, tolerance=0)#

Check if a matrix is positive semidefinite.

Return type:

bool

save_lq_decomposition#

do_dpc.dpc.dpc_utils.DPCUtils.save_lq_decomposition(matrix)#

Computes the LQ decomposition of a given matrix.

This method first attempts to compute the Cholesky decomposition of matrix @ matrix.T. If the matrix is not symmetric positive definite, it falls back to using the QR decomposition.

Parameters:

matrix (np.ndarray) – The input matrix to be decomposed.

Returns:

The lower triangular matrix L from the LQ decomposition.

Return type:

np.ndarray

Raises:

np.linalg.LinAlgError – If both Cholesky and QR decompositions fail.