Cost functions module

Compute the cost of a trajectory.

pyrotor.cost_functions.compute_cost(trajectory, model, independent_variable)

Compute total cost of a trajectory given a quadratic model - Vectorized version.

Inputs:
  • trajectory: DataFrame

    Trajectory of interest

  • model: list of arrays or sklearn model

    Model of the cost; if list, the first element of the list is the constant c, the second one is the linear part w and the third one is the quadratic part q

  • independent_variable: dict

    Describe the time-interval on which are defined the trajectories ex: {‘start’: 0, ‘end’: 1, ‘frequency’:.1}

Output:
  • trajectory_cost: float

    Total cost of the trajectory

pyrotor.cost_functions.compute_cost_by_time(trajectory, model)

Compute the cost of a trajectory at every time given a quadratic model - Vectorized version.

Inputs:
  • trajectory: DataFrame

    Trajectory of interest

  • model: list of arrays or sklearn model

    Model of the cost; if list, the first element of the list is the constant c, the second one is the linear part w and the third one is the quadratic part q

Output:
  • cost_by_time: ndarray

    Trajectory cost at each time

pyrotor.cost_functions.compute_f(vector_x, sigma_inverse, c_weight)

Compute the distance mean of a trajectory to the reference ones through its coefficients.

Inputs:
  • vector_x: ndarray

    Coefficients of a single trajectory

  • sigma_inverse: ndarray

    Pseudoinverse of the covariance matrix of the reference coefficients

  • c_weight: ndarray

    Coefficients of a weighted trajectory

Output:
  • cost: float

    Distance of the trajectory to the reference ones

pyrotor.cost_functions.compute_g(vector_x, format_model, extra_info)

Compute cost of a trajectory through its coefficients.

Inputs:
  • vector_x: ndarray

    Coefficients of a single trajectory

  • format_model: list of arrays or sklearn model

    Model of the cost; if list, the first element of the list is the the integrated linear part W and the second one the integrated quadratic part Q

  • extra_info: dict

    Contains independent_variable, basis, basis_features and basis_dimension dictionaries

Output:
  • g(vector_x): float

    The cost of the given trajectory

pyrotor.cost_functions.compute_trajectories_cost(trajectories, model, independent_variable)

Compute the cost for each trajectory of a list.

Inputs:
  • trajectories: list of pd.DataFrame

    Each element of the list is a trajectory

  • model: list of arrays or sklearn model

    Model of the cost; if list, the first element of the list is the constant c, the second one is the linear part w and the third one is the quadratic part q

  • independent_variable: dict

    Describe the time-interval on which are defined the trajectories ex: {‘start’: 0, ‘end’: 1, ‘frequency’:.1}

Output:
  • trajectories_cost: ndarray

    Array containing the cost of the trajectories

pyrotor.cost_functions.load_model(name)

Load model saved in a .pkl format.

Input:
  • name: string

    Name of the .pkl file

Output:
  • model: Python object

    Loaded machine learning model, scipy class…