ast_toolbox.optimizers.direction_constraint_optimizer module

class ast_toolbox.optimizers.direction_constraint_optimizer.DirectionConstraintOptimizer(cg_iters=10, reg_coeff=1e-05, subsample_factor=1.0, backtrack_ratio=0.8, max_backtracks=15, debug_nan=False, accept_violation=False, hvp_approach=None, num_slices=1)[source]

Bases: object

Performs constrained optimization via line search on the given gradient direction.

Parameters:
  • cg_iters (int, optional) – The number of CG iterations used to calculate A^-1 g.
  • reg_coeff (float, optional) – A small value so that A -> A + reg*I.
  • subsample_factor (int, optional) – Subsampling factor to reduce samples when using “conjugate gradient. Since the computation time for the descent direction dominates, this can greatly reduce the overall computation time.
  • debug_nan (bool, optional) – If set to True, NanGuard will be added to the compilation, and ipdb will be invoked when nan is detected.
  • accept_violation (bool, optional) – Whether to accept the descent step if it violates the line search condition after exhausting all backtracking budgets.
constraint_val(inputs, extra_inputs=None)[source]

Calculate the constraint value.

Parameters:
  • inputs – A list of symbolic variables as inputs, which could be subsampled if needed. It is assumed that the first dimension of these inputs should correspond to the number of data points.
  • extra_inputs (optional) – A list of symbolic variables as extra inputs which should not be subsampled.
Returns:

constraint_value (float) – The value of the constrained variable.

get_magnitude(direction, inputs, max_constraint_val=None, extra_inputs=None, subsample_grouped_inputs=None)[source]

Calculate the update magnitude.

Parameters:
  • direction (:py:class:’tensorflow.Tensor’) – The gradient direction.
  • inputs – A list of symbolic variables as inputs, which could be subsampled if needed. It is assumed that the first dimension of these inputs should correspond to the number of data points.
  • max_constraint_val (float, optional) – The maximum value for the constrained variale.
  • extra_inputs (optional) – A list of symbolic variables as extra inputs which should not be subsampled.
  • subsample_grouped_inputs (optional) – The list of inputs that are needed to be subsampled.
Returns:

magnitude (float) – The update magnitude.

update_opt(target, leq_constraint, inputs, extra_inputs=None, constraint_name='constraint', *args, **kwargs)[source]

Update the internal tensowflow operations.

Parameters:
  • target – A parameterized object to optimize over. It should implement methods of the garage.core.paramerized.Parameterized class.
  • leq_constraint (:py:class:’tensorflow.Tensor’) – The variable to be constrained.
  • inputs – A list of symbolic variables as inputs, which could be subsampled if needed. It is assumed that the first dimension of these inputs should correspond to the number of data points.
  • extra_inputs – A list of symbolic variables as extra inputs which should not be subsampled.