Regularizers

class ionworkspipeline.regularizers.Regularizer(fun, regularizer_weight=None)

A regularizer function that takes a dictionary of inputs and returns a value.

Parameters

funcallable

The regularizer function that takes a dictionary of inputs and returns a value.

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.

Parameters

inputsdict

Dictionary of input values.

Returns

float

Scalar regularizer value.

property fun

callable: The underlying regularizer function.

property regularizer_weight

float: Weight applied to the regularizer term. Defaults to 1.0.

property scalar_output

bool: Whether the regularizer returns scalar values.

set_scalar_output(scalar_output)

Set whether the regularizer returns scalar or array outputs.

Parameters

scalar_outputbool

If True, regularizer returns scalar values. If False, returns arrays.

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.regularizers.RegularizerSet(regularizers: list | tuple | ndarray, scalar_output: bool, x_to_inputs: callable, 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.

scalar_outputbool

Whether the set returns scalar or array outputs.

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.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.

Parameters

inputsdict

Dictionary of input values.

Returns

ndarray

Array containing all regularizer values multiplied by the set weight.

evaluate_to_scalar(inputs: dict) float

Evaluate all regularizers with dictionary inputs, returning their sum.

Parameters

inputsdict

Dictionary of input values.

Returns

float

Sum of all regularizer values.

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.

set_scalar_output(scalar_output)

Set scalar output property for this set and all contained regularizers.

Parameters

scalar_outputbool

If True, regularizers return scalar values. If False, return arrays.

set_x_to_inputs(x_to_inputs)

Set x_to_inputs function for this set and all contained regularizers.

Parameters

x_to_inputscallable

Function converting parameter vectors to input dictionaries.