costs package

Cost Base Classes

The CostFactory Class

class autompc.costs.CostFactory(system)[source]

The CostFactory class constructs cost objects and contains information about hyperparameter information.

abstract get_configuration_space()[source]

Returns ConfigurationSpace for cost factory.

abstract __call__(cfg, task, trajs)[source]

Build Cost according to configuration.

Parameters:
  • cfg (Configuration) – Cost hyperparameter configuration

  • task (Task) – Input task

  • trajs (List of Trajectory) – Trajectory training set. This is mostly used for regularization cost terms and is not required by all CostFactories. If not required, None can be passed instead.

The Cost Class

class autompc.costs.Cost(system)[source]

Base class for cost functions.

__call__(traj)[source]

Evaluate cost on whole trajectory

Parameters:

traj (Trajectory) – Trajectory to evaluate

get_cost_matrices()[source]

Return quadratic Q, R, and F matrices. Raises exception for non-quadratic cost.

get_goal()[source]

Returns the cost goal state if available. Raises exception if cost does not have goal.

Returnsnumpy array of size self.system.obs_dim

Goal state

eval_obs_cost(obs)[source]

Evaluates observation cost at a particular time step. Raises exception if not implemented.

Parameters:
  • obs (self.system.obs_dim) – Observation

  • Returns (float) – Cost

eval_obs_cost_diff(obs)[source]

Evaluates the observation cost at a particular time steps and computes Jacobian. Raises exception if not implemented.

Returns(float, numpy array of size self.system.obs_dim)

Cost, Jacobian

eval_obs_cost_hess(obs)[source]

Evaluates the observation cost at a particular time steps and computes Jacobian and Hessian. Raises exception if not implemented.

Returns(float, numpy array of size self.system.obs_dim,

numpy array of shape (self.system.obs_dim, self.system.obsd_im))

Cost, Jacobian, Hessian

eval_ctrl_cost(ctrl)[source]

Evaluates control cost at a particular time step. Raises exception if not implemented.

Parameters:
  • obs (self.system.ctrl_dim) – Control

  • Returns (float) – Cost

eval_ctrl_cost_diff(ctrl)[source]

Evaluates the control cost at a particular time step and computes Jacobian. Raises exception if not implemented.

Returns(float, numpy array of size self.system.ctrl_dim)

Cost, Jacobian

eval_ctrl_cost_hess(ctrl)[source]

Evaluates the control cost at a particular time steps and computes Jacobian and Hessian. Raises exception if not implemented.

Returns(float, numpy array of size self.system.ctrl_dim, numpy array of shape (self.system.ctrl_dim, self.system.ctrl_dim))

Cost, Jacobian, Hessian

eval_term_obs_cost(obs)[source]

Evaluates terminal observation cost. Raises exception if not implemented.

Parameters:
  • obs (self.system.obs_dim) – Observation

  • Returns (float) – Cost

eval_term_obs_cost_hess(obs)[source]

Evaluates the terminal observation cost and computes Jacobian and Hessian. Raises exception if not implemented.

Returns(float, numpy array of size self.system.obs_dim, numpy array of shape (self.system.obs_dim, self.system.obsd_im))

Cost, Jacobian, Hessian

property is_quad

True if cost is quadratic.

property is_convex

True if cost is convex.

property is_diff

True if cost is differentiable.

property is_twice_diff

True if cost is twice differentiable

Cost Factory Classes

QuadCostFactory

class autompc.costs.QuadCostFactory(system, goal=None)[source]

Factory to produce quadratic cost. This cost has the form

\[x_N^T F x_N + \sum_{t=0}^{N} (x_t^T Q x_t + u_t^T R u_t)\]
Parameters:

goal (-) – Goal state. Default is 0 state.

Hyperparameters:

    • **x**_Q* (float, Lower: 10^-3, Upper: 10^4): Digaonal Q matrix value

    corresponding to observation dimension with label x

    • **x**_R* (float, Lower: 10^-3, Upper: 10^4): Digaonal R matrix value

    corresponding to control dimension with label x

    • **x**_F* (float, Lower: 10^-3, Upper: 10^4): Digaonal F matrix value

    corresponding to ovservation dimension with label x

GaussRegFactory

class autompc.costs.GaussRegFactory(system)[source]

Cost factory for Gaussian regularization cost. This cost encourages the controller to stick close to the distribution of the training set, and is typically used in combination with another cost function. The factory returns a quadratic cost with \(Q= w \Sigma_x^{-1}\) and goal = \(\mu_x\).

Hyperparameters:
  • reg_weight (float, Lower: 10^-3, Upper: 10^4): Weight of regularization term.

SumCostFactory

class autompc.costs.SumCostFactory(system, factories)[source]

A factory which produces sums of other cost terms. A SumCostFactory can be crated by combining other costfactories with the + operator.

Cost Classes

QuadCost

class autompc.costs.QuadCost(system, Q, R, F=None, goal=None)[source]
__init__(system, Q, R, F=None, goal=None)[source]

Create quadratic cost.

Parameters:
  • system (System) – System for cost

  • Q (numpy array of shape (self.obs_dim, self.obs_dim)) – Observation cost matrix

  • R (numpy array of shape (self.ctrl_dim, self.ctrl_dim)) – Control cost matrix

  • F (numpy array of shape (self.ctrl_dim, self.ctrl_dim)) – Terminal observation cost matrix

  • goal (numpy array of shape self.obs_dim) – Goal state. Default is zero state

SumCost

class autompc.costs.SumCost(system, costs)[source]
__init__(system, costs)[source]

A cost which is the sum of other cost terms. It can be created by combining other Cost objects with the + operator

Parameters:
  • system (System) – System for the cost object.

  • costs (List of Costs) – Cost objects to be summed.

ThresholdCost

class autompc.costs.ThresholdCost(system, goal, obs_range, threshold)[source]
__init__(system, goal, obs_range, threshold)[source]

Create threshold cost. Returns 1 for every time steps where \(||x - x_\textrm{goal}||_\infty > \textrm{threshold}\). The check is performed only over the observation dimensions from obs_range[0] to obs_range[1].

BoxThresholdCost

class autompc.costs.BoxThresholdCost(system, limits, goal=None)[source]
__init__(system, limits, goal=None)[source]

Create Box threshold cost. Returns 1 for every time steps where observation is outisde of limits.

Paramters

systemSystem

System cost is computed for

limitsnumpy array of shape (system.obs_dim, 2)

Upper and lower limits. Use +np.inf or -np.inf to allow certain dimensions unbounded.

goalnumpy array of size system.obs_dim

Goal state. Not used directly for computing cost, but may be used by downstream cost factories.