Objective matrices module

Compute matrices involved in the cost function

pyrotor.objective_matrices.compute_objective_matrices(basis, basis_features, basis_dimension, quad_model, derivative)

Compute the matrices and vectors from a quadratic model and involved in the final cost function.

Inputs:
  • basis: string

    Name of the functional basis

  • basis_features: dict

    Contain information on the basis for each state

  • basis_dimension: dict

    Give the number of basis functions for each state

  • quad_model: list or sklearn model

    if list, the first element of the list is w and the second one is q

  • derivative: boolean

    Take into account or not derivatives of states

Outputs:
  • W: ndarray

    Vector involved in the linear part of the cost function

  • Q: ndarray

    Matrix involved in the quadratic part of the cost function

pyrotor.objective_matrices.extend_matrix(w, q, basis_dimension, derivative)

Extend respectively matrix and vector from a quadratic model to new matrix and vector with constant blocks for modelling optimization problem at the end.

Sizes are given by basis_dimension.

Inputs:
  • w: ndarray

    Vector of the linear term of the quadratic model

  • q: ndarray

    Matrix of the quadratic term of the quadratic model

  • basis_dimension: dict

    Give the number of basis functions for each state

  • derivative: boolean

    Take into account or not derivatives of states

Outputs:
  • W_: ndarray

    Extended vector from the linear term

  • Q_: ndarray

    Extended matrix from the quadratic term

pyrotor.objective_matrices.model_to_matrix(model, basis_dimension, derivative)

From a quadratic model f(x), compute q and w such that f(x) = <x, qx> + <w, x> + r . The model has to be in pickle format and previously trained using the pipeline [PolynomialFeatures(), StandardScaler(), LinearRegressor()] from scikit-learn.

Inputs:
  • model: sklearn.pipeline.Pipeline

    Quadratic model

  • basis_dimension: dict

    Give the number of basis functions for each state

  • derivative: boolean

    Take into account or not derivatives of states

Outputs:
  • w: ndarray

    Vector of the linear term (without intercept)

  • q: ndarray

    Matrix of the quadratic term