figaro.mixture module¶
- class figaro.mixture.DPGMM(bounds, prior_pars=None, alpha0=1.0, probit=True, n_reassignments=0.0)[source]¶
Bases:
density
Class to infer a distribution given a set of samples.
- Parameters:
bounds (iterable) – boundaries of the rectangle over which the distribution is defined. It should be in the format [[xmin, xmax],[ymin, ymax],…]
prior_pars (iterable) – NIW prior parameters (k, L, nu, mu)
alpha0 (double) – initial guess for concentration parameter
probit (bool) – whether to use the probit transformation or not
n_reassignments (int) – number of reassignments. Default is not to reassign.
- Returns:
instance of DPGMM class
- Return type:
- add_new_point(x, *args, **kwargs)¶
- build_mixture(make_comp=True)[source]¶
Instances a mixture class representing the inferred distribution
- Parameters:
make_comp (bool) – whether to instantiate the scipy.stats.multivariate_normal components or not
- Returns:
the inferred distribution
- Return type:
- class figaro.mixture.HDPGMM(bounds, alpha0=1.0, prior_pars=None, MC_draws=None, probit=True, n_reassignments=0.0, selection_function=None, injection_pdf=None, total_injections=None)[source]¶
Bases:
DPGMM
Class to infer a distribution given a set of observations (each being a set of samples). Child of DPGMM class
- Parameters:
bounds (iterable) – boundaries of the rectangle over which the distribution is defined. It should be in the format [[xmin, xmax],[ymin, ymax],…]
prior_pars (iterable) – IW parameters
alpha0 (double) – initial guess for concentration parameter
MC_draws (double) – number of MC draws for integral
probit (bool) – whether to use the probit transformation or not
n_reassignments (int) – number of reassignments. Default is not to reassign.
selection_function (callable) – selection function approximant or samples
injection_pdf (np.ndarray) – pdf of injected samples (for selection function inclusion)
- Returns:
instance of HDPGMM class
- Return type:
- add_new_point(ev)[source]¶
Update the probability density reconstruction adding a new sample
- Parameters:
ev (iterable) – set of single-event draws from a DPGMM inference
- build_mixture(make_comp=True)[source]¶
Instances a mixture class representing the inferred distribution
- Parameters:
make_comp (bool) – whether to instantiate the scipy.stats.multivariate_normal components or not
- Returns:
the inferred distribution
- Return type:
- compute_alpha_factor()[source]¶
Compute the integral int pdet(theta)p(theta|lambda) dtheta conditioned on the specific DPGMM parameters
- Returns:
value of the integral
- Return type:
double
- density_from_samples(events, make_comp=True)[source]¶
Reconstruct the probability density from a set of samples.
- Parameters:
samples (iterable) – set of single-event draws from DPGMM
make_comp (bool) – whether to instantiate the scipy.stats.multivariate_normal components or not
- Returns:
the inferred mixture
- Return type:
- class figaro.mixture.density[source]¶
Bases:
object
Class to initialise a common set of methods for mixture models. Not to be used.
- fast_logpdf(x)[source]¶
Fast logpdf evaluation using FIGARO implementation of log_norm (JIT) rather than Numpy’s. WARNING: it is meant to be used with MCMC samplers, therefore accepts only one point at a time.
- Parameters:
x (np.ndarray) – point to evaluate the mixture at
- Returns:
mixture.pdf(x)
- Return type:
np.ndarray
- fast_pdf(x)[source]¶
Fast pdf evaluation using FIGARO implementation of log_norm (JIT) rather than Numpy’s. WARNING: it is meant to be used with MCMC samplers, therefore accepts only one point at a time.
- Parameters:
x (np.ndarray) – point to evaluate the mixture at
- Returns:
mixture.pdf(x)
- Return type:
np.ndarray
- gradient(x)[source]¶
Gradient of the mixture.
- Parameters:
x (np.ndarray) – point to evaluate the gradient at
- Returns:
gradient
- Return type:
np.ndarray
- log_gradient(x)[source]¶
Logarithmic gradient of the mixture.
- Parameters:
x (np.ndarray) – point to evaluate the gradient at
- Returns:
logarithmic gradient
- Return type:
np.ndarray
- rvs(*args, **kwargs)¶
- class figaro.mixture.mixture(means, covs, w, bounds, dim, n_cl, n_pts, alpha=1.0, probit=True, log_w=None, make_comp=True, alpha_factor=1.0)[source]¶
Bases:
density
Class to store a single draw from DPGMM/(H)DPGMM. Methods inherited from density class
- Parameters:
means (iterable) – component means
covs (iterable) – component covariances
w (np.ndarray) – component weights
bounds (np.ndarray) – bounds of probit transformation
dim (int) – number of dimensions
n_cl (int) – number of clusters in the mixture
n_pts (int) – number of points used to infer the mixture
alpha (double) – concentration parameter
probit (bool) – whether to use the probit transformation or not
log_w (np.ndarray) – component log weights
make_comp (bool) – make component objects
alpha_factor (double) – evaluated int pdet(theta)p(theta|lambda) conditioned on the mixture parameters
- Returns:
instance of mixture class
- Return type:
- condition(vals, dims, norm=True, filter=True, tol=0.001)[source]¶
Mixture conditioned on specific values of a subset of parameters.
- Parameters:
vals (iterable) – value(s) to condition on
dims (int or list of int) – dimension(s) associated with given vals (starting from 0)
norm (bool) – whether to normalize the distribution or not
filter (bool) – filter the components with weight < tol
tol (double) – tolerance on the sum of the weights
- Returns:
conditioned mixture
- Return type: