stacie.cost module

Cost function to optimize models for the low-frequency part of the spectrum.

class LowFreqCost(freqs, ndofs, amplitudes, weights, model)[source]

Bases: object

Cost function to fit a model to the low-frequency part of the spectrum.

Parameters:
__call__(pars, *, deriv=0)[source]

Evaluate the cost function and its derivatives.

Parameters:
  • pars (NDArray[float]) – The parameter vector for which the loss function must be computed.

  • deriv (int) – The order of derivatives of the cost function to include.

Return type:

list[NDArray[float]]

Returns:

results – A list with the cost function and the requested derivatives.

amplitudes: NDArray[float]

The actual spectrum amplitudes at frequencies in self.freqs.

expected(pars)[source]

Compute the expected value and variance of the cost function.

Parameters:

pars (NDArray[float]) – The model parameters. Vectorization is not supported yet.

Return type:

NDArray[float]

Returns:

expected, variance – The expected value and variance of the cost function.

freqs: NDArray[float]

The frequencies for which the spectrum amplitudes are computed.

model: SpectrumModel

The model to be fitted to the spectrum.

ndofs: NDArray[int]

The number of independent contributions to each spectrum amplitude.

weights: NDArray[float]

The fitting weights for each grid point.

entropy_gamma(alpha, theta, *, deriv=0)[source]

Compute the entropy of the Gamma distribution.

Parameters:
  • alpha (NDArray[float]) – The shape parameter.

  • theta (NDArray[float]) – The scale parameter.

  • deriv (int) – The order of the derivatives toward theta to compute: 0, 1 or 2.

Return type:

list[NDArray[float]]

Returns:

results – A list of results (function value and requested derivatives.) All elements have the same shape as the alpha and theta arrays.

logpdf_gamma(x, alpha, theta, *, deriv=0)[source]

Compute the logarithm of the probability density function of the Gamma distribution.

Parameters:
  • x (NDArray[float]) – The argument of the PDF (random variable). Array with shape (nfreq,).

  • alpha (NDArray[float]) – The shape parameter. Array with shape (nfreq,).

  • theta (NDArray[float]) – The scale parameter. Array with shape (..., nfreq,).

  • deriv (int) – The order of the derivatives toward theta to compute: 0, 1 or 2.

Return type:

list[NDArray[float]]

Returns:

results – A list of results (function value and requested derivatives.) All elements have the same shape as the theta array.

varlogp_gamma(alpha)[source]

Compute the variance of the log-probability density function of the Gamma distribution.

Parameters:

alpha (NDArray[float]) – The shape parameter.

Return type:

NDArray[float]

Returns:

var – The variance of the log-probability density function. Array with shape (alpha,).