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:
__call__(pars, *, deriv=0)[source]

Evaluate the pre-conditioned cost function.

Parameters:
  • pars (ndarray[tuple[int, ...], dtype[float]]) – The parameters to evaluate the cost function at, in the original space. For vectorized calculations, use N-dimensional inputs of which the last axis corresponds to the parameters.

  • deriv (int) – The order of the derivative to compute.

Return type:

list[ndarray[tuple[int, ...], dtype[float]]]

Returns:

results – The cost function value and its derivatives. In vectorized calculations, the last axis of the gradient and the last two of the Hessian correspond to the parameters.

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

Convert parameters from the reduced to the original space.

Parameters:

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

Return type:

ndarray[tuple[int, ...], 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[int, ...], dtype[float]]) – The parameters, in the reduced space.

Return type:

tuple[float, ndarray[tuple[int, ...], 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[int, ...], dtype[float]]

Parameters:

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

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

Convert parameters from the original to the reduced space.

Parameters:

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

Return type:

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

Returns:

pars_reduced – The parameters in the reduced space.