ddl.linear.BestLinearReconstructionDestructor

class ddl.linear.BestLinearReconstructionDestructor(linear_estimator=None, destructor=None, linear_projector_kwargs=None)[source]

Bases: ddl.base.CompositeDestructor

Best linear reconstruction after a linear destructor.

Class that converts a linear -> destructor combination into a combination that returns the data to as close to the original space as possible. Essentially, linear -> destructor -> independent Gaussian inverse cdf -> inverse linear -> independent Gaussian cdf. For example, if the linear projector was PCA and the destructor was a independent Gaussian, then this would correspond to ZCA whitening.

Parameters:
linear_estimator : estimator, default=IdentityLinearEstimator

A linear estimator that has either a coef_ attribute or a components_. For example, sklearn.decomposition.PCA.

destructor : estimator

Density destructor to use in between linear projections.

linear_projector_kwargs : dict

Keyword arguments to pass when constructing ddl.linear.LinearProjector.

Attributes:
fitted_destructors_ : list

List of fitted (sub)destructors. (Note that these objects are cloned via sklearn.base.clone from the destructors parameter so as to avoid mutating the destructors parameter.)

density_ : estimator

Implicit density of composite destructor.

Methods

create_fitted(fitted_destructors, \*\*kwargs) Create fitted destructor.
fit(self, X[, y]) Fit estimator to X.
fit_transform(self, X[, y]) [Placeholder].
get_domain(self) Get the domain of this destructor.
get_params(self[, deep]) Get parameters for this estimator.
inverse_transform(self, X[, y, partial_idx]) Apply inverse destructive transformation to X.
sample(self[, n_samples, y, random_state]) Sample from composite destructor.
score(self, X[, y, partial_idx]) Override super class to allow for partial_idx.
score_layers(self, X[, y, partial_idx]) Override super class to allow for partial_idx.
score_samples(self, X[, y, partial_idx]) Compute log-likelihood (or log(det(Jacobian))) for each sample.
score_samples_layers(self, X[, y, partial_idx]) [Placeholder].
set_params(self, \*\*params) Set the parameters of this estimator.
transform(self, X[, y, partial_idx]) Apply destructive transformation to X.
__init__(self, linear_estimator=None, destructor=None, linear_projector_kwargs=None)[source]

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

classmethod create_fitted(fitted_destructors, **kwargs)

Create fitted destructor.

Parameters:
fitted_destructors : array-like of Destructor

Fitted destructors.

**kwargs

Other parameters to pass to constructor.

Returns:
fitted_transformer : Transformer

Fitted transformer.

fit(self, X, y=None, **fit_params)

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.

fit_params : dict, optional

Optional extra fit parameters.

Returns:
self : estimator

Returns the instance itself.

fit_transform(self, X, y=None, **kwargs)[source]

[Placeholder].

Parameters:
X :
y :
kwargs :
Returns:
obj : object
get_domain(self)

Get the domain of this destructor.

Returns:
domain : array-like, shape (2,) or shape (n_features, 2)

If shape is (2, ), then domain[0] is the minimum and domain[1] is the maximum for all features. If shape is (n_features, 2), then each feature’s domain (which could be different for each feature) is given similar to the first case.

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.

inverse_transform(self, X, y=None, partial_idx=None)

Apply inverse destructive transformation to X.

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 in the transformation but kept for compatibility.

partial_idx : list or None, default=None

List of indices of the fitted destructor to use in the transformation. The default of None uses all the fitted destructors. Mainly used for visualization or debugging.

Returns:
X_new : array-like, shape (n_samples, n_features)

Transformed data (possibly only partial transformation).

sample(self, n_samples=1, y=None, random_state=None)

Sample from composite destructor.

Nearly the same as DestructorMixin.sample but the number of features is found from first fitted destructor to avoid recursion.

score(self, X, y=None, partial_idx=None)

Override super class to allow for partial_idx.

score_layers(self, X, y=None, partial_idx=None)

Override super class to allow for partial_idx.

score_samples(self, X, y=None, partial_idx=None)

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.

partial_idx : list or None, default=None

List of indices of the fitted destructor to use in the computing the log likelihood. The default of None uses all the fitted destructors. Mainly used for visualization or debugging.

Returns:
log_likelihood : array, shape (n_samples,)

Log likelihood of each data point in X.

score_samples_layers(self, X, y=None, partial_idx=None)

[Placeholder].

Parameters:
X :
y :
partial_idx :
Returns:
obj : object
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
transform(self, X, y=None, partial_idx=None)

Apply destructive transformation to X.

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 in the transformation but kept for compatibility.

partial_idx : list or None, default=None

List of indices of the fitted destructor to use in the transformation. The default of None uses all the fitted destructors. Mainly used for visualization or debugging.

Returns:
X_new : array-like, shape (n_samples, n_features)

Transformed data (possibly only partial transformation).