Background Class

class Stats_Analysis.Compound_Dist.Background_Class.Background(mu_b, sigma_b, lower_bound_X, upper_bound_X, lower_bound_Y=None, upper_bound_Y=None)[source]

Bases: object

Background probability distribution defined by B(X, Y) = UnfiromDistribution(X) * NormalDistrution(Y).

This class supports computation of the joint PDF and joint CDF for scalar and array inputs, with optional truncation for Y (X’s Uniform must inherently be truncated).

Parameters:
  • mu_b (float) – The mean of the Normal distribution in the Y dimension.

  • sigma_b (float) – The standard deviation of the Normal distribution in the Y dimension. Must be sigma_b > 0.

  • lower_bound_X (float) – The lower bound of the Uniform distribution in the X dimension.

  • upper_bound_X (float) – The upper bound of the Uniform distribution in the X dimension. Must be lower_bound_X < upper_bound_X.

  • lower_bound_Y (float, optional) – The lower bound for truncation of the Normal distribution in the Y dimension. Default is None.

  • upper_bound_Y (float, optional) – The upper bound for truncation of the Normal distribution in the Y dimension. Default is None.

Raises:

ValueError – If sigma_b <= 0. If lower_bound_X >= upper_bound_X. If lower_bound_Y >= upper_bound_Y.

__init__(mu_b, sigma_b, lower_bound_X, upper_bound_X, lower_bound_Y=None, upper_bound_Y=None)[source]

Initialize the Background distribution with optional truncation by defining the Uniform and Normal distributions in the X and Y dimensions, respectively.

cdf(X, Y)[source]

Compute the joint Cumulative Distribution Function (CDF).

The Joint CDF is defined as: C(X, Y) = Integral of B(X,Y) from 0, X and 0, Y

As the distributions are independent, the joint CDF is the product of the individual CDFs: C(X, Y) = Unifrom_CDF(X) * Normal_CDF(Y)

Parameters:
  • X (float or np.ndarray) – The value(s) of X at which to evaluate the CDF.

  • Y (float or np.ndarray) – The value(s) of Y at which to evaluate the CDF.

Returns:

The joint CDF value(s),

Return type:

float or np.ndarray

cdf_fitting(X, Y, mu_b, sigma_b)[source]

Calculate the Cumulative Density Function (CDF) for a given set of parameters, for use with Binned MLE fitting.

normalisation_check(over_whole_plane=False)[source]

Check the normalization of the joint Probability Density Function (PDF) using numerical integration.

This method performs numerical integration with scipy.integrate.dblquad to ensure that the joint PDF integrates to 1. It supports both truncated and untruncated cases.

Parameters:

over_whole_plane (bool, optional) – If True, perform integration over the entire real plane (-infinity to infinity) for both X and Y. Default is False, in which case integration is only performed over the defined/truncated region.

Returns:

  • The defined/truncated region: [lower_bound_X, upper_bound_X] for X and [lower_bound_Y, upper_bound_Y] for Y.

  • The entire real plane: X in [-infinity, infinity] and Y in [-infinity, infinity] (only if over_whole_plane is True).

Return type:

Normalisation results for

Notes

  • If the PDF is truncated, the method integrates over the truncated region defined by the bounds (lower_bound_X, upper_bound_X, lower_bound_Y, upper_bound_Y).

  • If no bounds are defined, the truncated region defaults to the entire real plane.

  • The integration over the entire real plane is computationally intensive and can be skipped by setting over_whole_plane to False.

pdf(X, Y)[source]

Calculate the joint Probability Density Function (PDF).

The Joint PDF is defined as: B(X, Y) = Uniform_PDF(X) * Normal_PDF(Y)

Parameters:
  • X (float or np.ndarray) – The value(s) of X at which to evaluate the PDF.

  • Y (float or np.ndarray) – The value(s) of Y at which to evaluate the PDF.

Returns:

The normalized joint PDF value(s) 0 if X is outside [lower_bound_X, upper_bound_X] or Y is outside [lower_bound_Y, upper_bound_Y].

Return type:

float or np.ndarray

pdf_fitting(X, Y, mu_b, sigma_b)[source]

Calculate the Probability Density Function (PDF) for a given set of parameters, for use with MLE fitting.

plot_dist()[source]

2D plots of the background PDF.