Regularizers¶
The regularizers module provides classes for adding regularization terms to objective functions, including constraints, penalties, and priors.
Base Classes¶
- class ionworkspipeline.data_fits.objective_functions.regularizers.Regularizer(fun, regularizer_weight=None)¶
A regularizer function that takes a dictionary of inputs and returns a value.
Parameters¶
- funpybamm.Symbol or Number
The regularizer expression as a pybamm symbol or a constant number.
- regularizer_weightfloat, optional
The weight applied to the regularizer term. Default is 1.0.
- evaluate_to_array(inputs: dict) ndarray¶
Evaluate the regularizer function with dictionary inputs, returning an array.
Parameters¶
- inputsdict
Dictionary of input values.
Returns¶
- ndarray
Array containing the regularizer value.
- evaluate_to_scalar(inputs: dict) float¶
Evaluate the regularizer function with dictionary inputs, returning a scalar. The scalar value evaluates the canonical form, which is \((w * f(x))^2\).
Parameters¶
- inputsdict
Dictionary of input values.
Returns¶
- float
Scalar regularizer value.
- property fun¶
callable: The underlying regularizer function.
- process_symbol(parameter_values: ParameterValues)¶
Process the stored symbolic expression into an evaluable function.
Parameters¶
- parameter_valuespybamm.ParameterValues
The parameter values used to resolve parameters in the expression.
- property regularizer_weight¶
float: Weight applied to the regularizer term. Defaults to 1.0.
- set_x_to_inputs(x_to_inputs)¶
Set the function that converts parameter vectors to input dictionaries.
Parameters¶
- x_to_inputscallable
Function that converts a parameter vector to a dictionary of inputs. See
ionworkspipeline.DataFit.x_to_inputs()for more information.
- property x_to_inputs¶
callable: Function converting parameter vectors to input dictionaries.
- class ionworkspipeline.data_fits.objective_functions.regularizers.RegularizerSet(regularizers: list | tuple | ndarray, x_to_inputs, regularizer_set_weight: float | None = None)¶
A collection of regularizer terms that can be evaluated together.
Parameters¶
- regularizerslist, tuple or ndarray
Collection of regularizer terms.
- x_to_inputscallable
Function converting parameter vectors to input dictionaries.
- regularizer_set_weightfloat, optional
Weight applied to the entire regularizer set. Default is 1.0.
Extends:
ionworkspipeline.data_fits.objective_functions.regularizers.regularizers.Regularizer- property base_regularizer_type¶
type: The base type for regularizers in this set.
- evaluate_to_array(inputs)¶
Evaluate all regularizers with dictionary inputs, returning an array.
For consistency with scalar mode (where sum(residuals²) == scalar), the set weight is applied as sqrt(weight) to the residuals. When the optimizer squares the residuals, the effective weight matches the scalar computation.
Parameters¶
- inputsdict
Dictionary of input values.
Returns¶
- ndarray
Array containing all regularizer residuals scaled by sqrt(set_weight).
- evaluate_to_scalar(inputs: dict) float¶
Evaluate all regularizers in scalar form, returning their weighted sum.
Parameters¶
- inputsdict
Dictionary of input values.
Returns¶
- float
Sum of all regularizer scalar values, multiplied by the set weight.
- property regularizer_set_weight¶
float: Weight applied to the entire regularizer set. Defaults to 1.0.
- property regularizers¶
list: The collection of regularizer terms in this set.