theseus.Objective
- class theseus.Objective(dtype: Optional[dtype] = None, error_metric_fn: Optional[ErrorMetric] = None, __allow_mixed_optim_aux_vars__: bool = False)
An objective function to optimize.
Defines the structure of an optimization problem in Theseus by aggregating
cost functionsinto a single objective. The cost functions that comprise the final objective function are specified via theadd()method. Cost functions are responsible for registering their optimization and auxiliary variables, which are automatically added to the objective’s list of variables when a cost function is added. Importantly, optimization variables must be instances ofManifoldsubclasses, while auxiliary variables can be instances of anyVariableclass.- Parameters
dtype (optional[torch.dtype]) – the data type to use for all variables. If
Noneis passed, then usestorch.get_default_dtype().error_metric_fn (optional[callable]) – a reference to a Python function used to aggregate cost functions into a single objective. Defaults to using the sum of squared costs. If given, it must receive a single tensor as input. The objective will use it to pass the batched concatenated error vector, will all cost function errors concatenated.
- __init__(dtype: Optional[dtype] = None, error_metric_fn: Optional[ErrorMetric] = None, __allow_mixed_optim_aux_vars__: bool = False)
Methods
add(cost_function)Adds a cost function to the objective.
copy()Creates a new copy of this objective.
dim()Returns the dimension of the error vector.
erase(name)Removes a cost function from the objective given its name
error([input_tensors, also_update])Evaluates the error vector.
error_metric([input_tensors, also_update])Aggregates all cost function errors into a (batched) scalar objective.
get_aux_var(name)Returns a reference to the auxiliary variable with the given name.
get_cost_function(name)Returns a reference to the cost function with the given name.
get_functions_connected_to_aux_var(aux_var)Gets a list of functions that depend on a given auxiliary variable.
get_functions_connected_to_optim_var(variable)Gets a list of functions that depend on a given optimization variable.
get_optim_var(name)Returns a reference to the optimization variable with the given name.
has_aux_var(name)Checks if an auxiliary variable is used in the objective.
has_cost_function(name)Checks if a cost function with the given name is in the objective.
has_optim_var(name)Checks if an optimization variable is used in the objective.
retract_vars_sequence(delta, ordering[, ...])Retracts an ordered sequence of variables.
size()Returns the number of cost functions and variables in the objective.
size_aux_vars()Returns the number of auxiliary variables in the objective.
size_cost_functions()Returns the number of cost functions in the objective.
size_variables()Returns the number of optimization variables in the objective.
to(*args, **kwargs)Applies torch.Tensor.to() to all cost functions in the objective.
update([input_tensors, batch_ignore_mask, ...])Updates all variables with the given input tensor dictionary.