ddl.base
.CompositeDestructor¶
-
class
ddl.base.
CompositeDestructor
(destructors=None, random_state=None)[source]¶ Bases:
sklearn.base.BaseEstimator
,ddl.base.DestructorMixin
Meta destructor composed of multiple destructors.
This meta destructor composes multiple destructors or other transformations (e.g. relative destructors like LinearProjector) into a single composite destructor. This is a fundamental building block for creating more complex destructors from simple atomic destructors.
Parameters: - destructors : list
List of destructor estimators to use as subdestructors.
- random_state : int, RandomState instance or None, optional (default=None)
Global random state used if any of the subdestructors are random-based. By seeding the global
numpy.random`
via random_state and then resetting to its previous state, we can avoid having to carefully pass around random states for random-based sub destructors.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 theRandomState
instance used bynumpy.random
.
Attributes: - fitted_destructors_ : list
List of fitted (sub)destructors. (Note that these objects are cloned via
sklearn.base.clone
from thedestructors
parameter so as to avoid mutating thedestructors
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])Fit estimator to X and then transform X. 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, destructors=None, random_state=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
classmethod
create_fitted
(fitted_destructors, **kwargs)[source]¶ 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)[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.
- fit_params : dict, optional
Optional extra fit parameters.
Returns: - self : estimator
Returns the instance itself.
-
fit_transform
(self, X, y=None, **fit_params)[source]¶ Fit estimator to X and then transform 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
Parameters to pass to the fit method.
Returns: - X_new : array-like, shape (n_samples, n_features)
Transformed data.
-
get_domain
(self)[source]¶ 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 anddomain[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)[source]¶ 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)[source]¶ 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_layers
(self, X, y=None, partial_idx=None)[source]¶ Override super class to allow for partial_idx.
-
score_samples
(self, X, y=None, partial_idx=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.
- 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)[source]¶ [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)[source]¶ 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).