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[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[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[float], int], list[NDArray[float]]]
-
cost_scale: float
-
from_reduced(pars)[source]
Convert parameters from the reduced to the original space.
- Parameters:
pars (NDArray[float]) – The parameters to convert, in the reduced space.
- Return type:
NDArray[float]
- Returns:
pars_orig – The parameters in the original space.
-
funcgrad(pars)[source]
Compute the cost function and the gradient.
- Parameters:
pars (NDArray[float]) – The parameters, in the reduced space.
- Return type:
tuple[float, NDArray[float]]
- Returns:
cost_reduced – The cost normalized function value.
-
hess(pars)[source]
Compute the Hessian matrix of the cost function.
- Return type:
NDArray[float]
- Parameters:
pars (NDArray[float])
-
par_scales: NDArray[float]
-
to_reduced(pars)[source]
Convert parameters from the original to the reduced space.
- Parameters:
pars (NDArray[float]) – The parameters to convert, in the original space.
- Return type:
NDArray[float]
- Returns:
pars_reduced – The parameters in the reduced space.