ddl.gaussian.GaussianDensity

class ddl.gaussian.GaussianDensity(covariance_type='full', reg_covar=1e-06)[source]

Bases: sklearn.base.BaseEstimator, ddl.base.ScoreMixin

Gaussian density estimator with conditional and marginal methods.

Implements necessary functions for use with the mixture and autoregressive module. Estimator implements conditioning that will return a new proxy density and the densities also implement marginal density computations such as cdf and inverse cdf.

The parameters are based on the parameters from sklearn.mixture.GaussianMixture.

Parameters:
covariance_type : {‘full’, ‘tied’, ‘diag’, ‘spherical’}, default=’full’

String describing the type of covariance parameters to use. Must be one of:

'full' (each component has its own general covariance matrix),
'tied' (all components share the same general covariance matrix),
'diag' (each component has its own diagonal covariance matrix),
'spherical' (each component has its own single variance).
reg_covar : float, default=1e-6.

Non-negative regularization added to the diagonal of covariance. Allows to assure that the covariance matrices are all positive.

Attributes:
mean_ : array-like, shape (n_features,)

The mean of the Gaussian.

covariance_ : array-like or float

The covariance matrix of the Gaussian. The shape depends on covariance_type:

float                           if 'spherical',
(n_features, n_features)        if 'tied',
(n_features,)                   if 'diag',
(n_features, n_features)        if 'full'
precision_ : array-like or float

The precision matrix. A precision matrix is the inverse of a covariance matrix. A covariance matrix is symmetric positive definite so the mixture of Gaussian can be equivalently parameterized by the precision matrices. Storing the precision matrix instead of the covariance matrices makes it more efficient to compute the log-likelihood of new samples at test time. The shape depends on covariance_type:

float                           if 'spherical',
(n_features, n_features)        if 'tied',
(n_features,)                   if 'diag',
(n_features, n_features)        if 'full'
precision_cholesky_ : array-like or float

The cholesky decomposition of the precision matrix. A precision matrix is the inverse of a covariance matrix. A covariance matrix is symmetric positive definite so the mixture of Gaussian can be equivalently parameterized by the precision matrices. Storing the precision matrix instead of the covariance matrix makes it more efficient to compute the log-likelihood of new samples at test time. The shape depends on covariance_type:

float                           if 'spherical',
(n_features, n_features)        if 'tied',
(n_features,)                   if 'diag',
(n_features, n_features)        if 'full'

Methods

conditional_densities(self, X, cond_idx, …) Compute conditional densities.
fit(self, X[, y]) Fit estimator to X.
get_params(self[, deep]) Get parameters for this estimator.
marginal_cdf(self, x, target_idx) [Placeholder].
marginal_density(self, marginal_idx) Return a single marginal density based on marginal_idx.
marginal_inverse_cdf(self, x, target_idx) [Placeholder].
marginal_pdf(self, x, target_idx) Return marginal log-likelihood.
sample(self[, n_samples, random_state]) Generate random samples from this density/destructor.
score(self, X[, y]) Return the mean log likelihood (or log(det(Jacobian))).
score_samples(self, X[, y]) Compute log-likelihood (or log(det(Jacobian))) for each sample.
set_params(self, \*\*params) Set the parameters of this estimator.
__init__(self, covariance_type='full', reg_covar=1e-06)[source]

Initialize self. See help(type(self)) for accurate signature.

conditional_densities(self, X, cond_idx, not_cond_idx)[source]

Compute conditional densities.

Parameters:
X : array-like, shape (n_samples, n_features)

Data to condition on based on cond_idx.

cond_idx : array-like of int

Indices to condition on.

not_cond_idx :

Indices not to condition on.

Returns:
conditional_densities : array-like of estimators

Either a single density if all the same or a list of Gaussian densities with conditional variances and means.

fit(self, X, y=None)[source]

Fit estimator to X.

Parameters:
X : array-like, shape (n_samples, n_features)

Training data, where n_samples is the number of samples and n_features is the number of features.

y : None, default=None

Not used in the fitting process but kept for compatibility.

Returns:
self : estimator

Returns the instance itself.

get_params(self, deep=True)

Get parameters for this estimator.

Parameters:
deep : boolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
params : mapping of string to any

Parameter names mapped to their values.

marginal_cdf(self, x, target_idx)[source]

[Placeholder].

Parameters:
x :
target_idx :
Returns:
obj : object
marginal_density(self, marginal_idx)[source]

Return a single marginal density based on marginal_idx.

marginal_inverse_cdf(self, x, target_idx)[source]

[Placeholder].

Parameters:
x :
target_idx :
Returns:
obj : object
marginal_pdf(self, x, target_idx)[source]

Return marginal log-likelihood.

Either of a each dimension or a particular dimension specified by target_idx. x can be either a scalar or vector.

sample(self, n_samples=1, random_state=None)[source]

Generate random samples from this density/destructor.

Parameters:
n_samples : int, default=1

Number of samples to generate. Defaults to 1.

random_state : int, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by numpy.random.

Returns:
X : array, shape (n_samples, n_features)

Randomly generated sample.

score(self, X, y=None)

Return the mean log likelihood (or log(det(Jacobian))).

Parameters:
X : array-like, shape (n_samples, n_features)

New data, where n_samples is the number of samples and n_features is the number of features.

y : None, default=None

Not used but kept for compatibility.

Returns:
log_likelihood : float

Mean log likelihood data points in X.

score_samples(self, X, y=None)[source]

Compute log-likelihood (or log(det(Jacobian))) for each sample.

Parameters:
X : array-like, shape (n_samples, n_features)

New data, where n_samples is the number of samples and n_features is the number of features.

y : None, default=None

Not used but kept for compatibility.

Returns:
log_likelihood : array, shape (n_samples,)

Log likelihood of each data point in X.

set_params(self, **params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns:
self