theseus.Objective.add

Objective.add(cost_function: CostFunction)

Adds a cost function to the objective.

When a cost function is added, this method goes over its list of registered optimization and auxiliary variables, and adds any of them to the objective’s list of variables, as long as a variable with th4 same name hasn’t been added before. If any of the cost function’s variables has the same as that of a variable previously added to the objective, the method checks that they are referring to the same theseus.Variable. If this is not the case, an error will be triggered. In other words, the objective expects to have a unique mapping between variable names and objects.

The same procedure is followed for the cost function’s weight.

Parameters

cost_function (theseus.CostFunction) – the cost function to be added to the objective.

Warning

If a cost weight registers optimization variables that are not used in any theseus.CostFunction objects, these will NOT be added to the set of the objective’s optimization variables; they will be kept in a separate container. The update() method will check for this, and throw a warning whenever this happens. Also note that Theseus always considers cost weights as constants, even if their value depends on variables declared as optimization variables.