Objective functions¶
- class ionworkspipeline.data_fits.ObjectiveFunction(objective: callable, cost: Cost, eq_constraints: EqualityConstraintSet | None = None, ineq_constraints: InequalityConstraintSet | None = None, penalties: PenaltySet | None = None)¶
Base class for objective functions that combine a main objective with optional constraints and penalties.
Parameters¶
- objectivecallable
The main objective function to minimize.
- costionworkspipeline.costs.Cost
The cost function that defines how to combine and process objective values.
- eq_constraintsionworkspipeline.constraints.EqualityConstraintSet, optional
Equality constraints that should evaluate to zero.
- ineq_constraintsionworkspipeline.constraints.InequalityConstraintSet, optional
Inequality constraints that should evaluate to greater than zero.
- penaltiesionworkspipeline.penalties.PenaltySet, optional
Additional penalty terms to add to the objective.
Notes¶
The objective function combines the main objective with optional constraints and penalties using the provided cost function’s combine method. The final output matches the cost function’s scalar_output property.
- combine(out: float | list, value: ndarray) float | list ¶
Combine a new value with the current output using the cost function.
Parameters¶
- outfloat or list
Current accumulated cost value
- valuenumpy.ndarray
New value to combine with the current cost
Returns¶
- float or list
Updated cost value after combining with the new value
- property cost¶
The cost function used to combine and process objective values.
- property eq_constraints¶
The equality constraints, if any.
- finalize_output(out: float | list) float | ndarray ¶
Process the final output using the cost function.
Parameters¶
- outfloat or list
The accumulated cost value to finalize
Returns¶
- float or numpy.ndarray
The finalized cost value, which may be a scalar or array depending on the cost function type
- property ineq_constraints¶
The inequality constraints, if any.
- initialize_output() float | list ¶
Initialize the output container based on the cost function.
Returns¶
- float or list
An empty container appropriate for the cost function type. For scalar costs, returns 0.0. For vector costs, returns an empty list.
- property objective¶
The main objective function.
- property penalties¶
The penalty terms, if any.
- property scalar_output¶
Whether the objective function returns scalar values.
- set_eq_constraints(eq_constraints: EqualityConstraintSet | None = None)¶
Set the equality constraints.
- set_ineq_constraints(ineq_constraints: InequalityConstraintSet | None = None)¶
Set the inequality constraints.
- set_penalties(penalties: PenaltySet | None = None)¶
Set the penalty terms.