redback.likelihoods.MixtureGaussianLikelihood

class redback.likelihoods.MixtureGaussianLikelihood(*args: Any, **kwargs: Any)[source]

Bases: GaussianLikelihood

__init__(x: ndarray, y: ndarray, sigma: float | None | ndarray, function: callable, kwargs: dict = None, priors=None, fiducial_parameters=None) None[source]

Mixture Gaussian likelihood that handles outliers by modeling each data point’s likelihood as a weighted sum of two Gaussians. The likelihood for each datum is given by

L_i = α * N(y_i | f(x_i), σ²) + (1 - α) * N(y_i | f(x_i), σ_out²)

where:
  • N(y_i | f(x_i), σ²) is the Gaussian probability density evaluated at y_i with mean f(x_i) and variance σ².

  • α is the inlier fraction (between 0 and 1).

  • σ_out is the standard deviation for the outlier component.

In addition, the posterior probability that a data point is an outlier is computed via

P(outlier | r) = [(1 - α) * p_out(r)] / [α * p_in(r) + (1 - α) * p_out(r)]

where r is the residual (y - f(x)).

Parameters:
  • x (np.ndarray) – Independent variable data.

  • y (np.ndarray) – Observed dependent variable data.

  • sigma (float, None, or np.ndarray) – Standard deviation for the inlier component.

  • function (callable) – Model function. It should accept x as the first argument.

  • kwargs (dict, optional) – Additional keyword arguments for the model function. sigma_out: Standard deviation of outlier data, is set to 10 times the inlier sigma if not provided. alpha: Inlier fraction, i.e., fraction of data points from the underlying model. Default is 0.9.

  • priors (dict, optional) – Priors for the parameters (not used in this implementation).

  • fiducial_parameters (dict, optional) – Starting guesses for the model parameters.

__call__(*args: Any, **kwargs: Any) Any

Call self as a function.

Methods

__init__(x, y, sigma, function[, kwargs, ...])

Mixture Gaussian likelihood that handles outliers by modeling each data point’s likelihood as a weighted sum of two Gaussians.

calculate_outlier_posteriors(model_prediction)

Calculate the posterior probability that each data point is an outlier.

find_maximum_likelihood_parameters([...])

Estimate the maximum likelihood

get_bounds_from_priors(priors)

get_parameter_dictionary_from_list(...)

get_parameter_list_from_dictionary(...)

lnlike_scipy_maximize(parameter_list)

log_likelihood([parameters])

Compute the total log-likelihood for the mixture model.

noise_log_likelihood()

p_in(r)

Compute the inlier probability density for residuals.

p_out(r)

Compute the outlier probability density for residuals.

Attributes

kwargs

model_output

The model output for the given x values.

n

Length of the x/y-values :rtype: int

parameters

parameters_to_be_updated

residual

sigma

calculate_outlier_posteriors(model_prediction: ndarray) ndarray[source]

Calculate the posterior probability that each data point is an outlier.

Given a model prediction, the residual for each point is computed as:

r = y - model_prediction.

Then the posterior is given by

P(outlier | r) = [(1 - α) * p_out(r)] / [α * p_in(r) + (1 - α) * p_out(r)].

Parameters:

model_prediction (np.ndarray) – Model predictions for each data point.

Returns:

An array of posterior probabilities (between 0 and 1) for each data point being an outlier.

Return type:

np.ndarray

find_maximum_likelihood_parameters(iterations=5, maximization_kwargs=None, method='Nelder-Mead', break_threshold=0.001)

Estimate the maximum likelihood

Parameters:
  • iterations – Iterations to run the minimizer for before stopping. Default is 5.

  • maximization_kwargs – Any extra keyword arguments passed to the scipy minimize function

  • method – Minimize method to use. Default is ‘Nelder-Mead’

  • break_threshold – The threshold for the difference in log likelihood to break the loop. Default is 1e-3.

Returns:

Dictionary of maximum likelihood parameters

log_likelihood(parameters=None) float[source]

Compute the total log-likelihood for the mixture model.

For each data point, the log-likelihood is given by

log(L_i) = log(α * N(0, σ²) + (1 - α) * N(0, σ_out²)).

Returns:

The overall log-likelihood (summed over all data points).

Return type:

float

property model_output: ndarray

The model output for the given x values. :rtype: np.ndarray

Type:

return

property n: int

Length of the x/y-values :rtype: int

Type:

return

noise_log_likelihood() float
Returns:

The noise log-likelihood, i.e. the log-likelihood assuming the signal is just noise.

Return type:

float

p_in(r: ndarray) ndarray[source]

Compute the inlier probability density for residuals.

Parameters:

r (np.ndarray) – Residuals.

Returns:

Inlier probability density evaluated at each residual.

Return type:

np.ndarray

p_out(r: ndarray) ndarray[source]

Compute the outlier probability density for residuals.

Parameters:

r (np.ndarray) – Residuals.

Returns:

Outlier probability density evaluated at each residual.

Return type:

np.ndarray