stacie.conditioning module

Cost function pre-conditioning.

class ConditionedCost(cost, par_scales, cost_scale)[source]

Bases: object

A wrapper for the cost function taking care of pre-conditioning.

The goal of the pre-conditioner is to let the optimizer work with normalized parameters, and to scale the cost function to a normalized range, such that all quantities are close to 1, even if the spectra and the frequencies have very different orders of magnitude.

Parameters:
cost: Callable[[ndarray[tuple[Any, ...], dtype[float]], int], list[ndarray[tuple[Any, ...], dtype[float]]]]
cost_scale: float
from_reduced(pars)[source]

Convert parameters from the reduced to the original space.

Parameters:

pars (ndarray[tuple[Any, ...], dtype[float]]) – The parameters to convert, in the reduced space.

Return type:

ndarray[tuple[Any, ...], dtype[float]]

Returns:

pars_orig – The parameters in the original space.

funcgrad(pars)[source]

Compute the cost function and the gradient.

Parameters:

pars (ndarray[tuple[Any, ...], dtype[float]]) – The parameters, in the reduced space.

Return type:

tuple[float, ndarray[tuple[Any, ...], dtype[float]]]

Returns:

cost_reduced – The cost normalized function value.

hess(pars)[source]

Compute the Hessian matrix of the cost function.

Return type:

ndarray[tuple[Any, ...], dtype[float]]

Parameters:

pars (ndarray[tuple[Any, ...], dtype[float]])

par_scales: ndarray[tuple[Any, ...], dtype[float]]
to_reduced(pars)[source]

Convert parameters from the original to the reduced space.

Parameters:

pars (ndarray[tuple[Any, ...], dtype[float]]) – The parameters to convert, in the original space.

Return type:

ndarray[tuple[Any, ...], dtype[float]]

Returns:

pars_reduced – The parameters in the reduced space.