ddl.linear
.LinearProjector¶
-
class
ddl.linear.
LinearProjector
(linear_estimator=None, orthogonal=False, fit_bias=True)[source]¶ Bases:
sklearn.base.BaseEstimator
,ddl.base.ScoreMixin
,sklearn.base.TransformerMixin
A linear projector based on an underlying linear estimator.
(Somewhat like a relative destructor with an implicit but unknown underlying density.)
- A few notes:
- 1. By construction, LinearProjector is density-agnostic and therefore is not a valid destructor. 2. However, if attached before any valid destructor, the joint transformer is a valid destructor, which implies a valid joint density. 3. Thus, LinearProjector can be seen as a relative destructor that requires a base density to be useful.
Parameters: - linear_estimator : estimator, default=IdentityLinearEstimator
A linear estimator that has either a coef_ attribute or a components_. For example,
sklearn.decomposition.PCA
.- orthogonal : bool, default=False
Whether to issue a warning if the matrix is not orthogonal.
- fit_bias : bool, default=True
Whether to fit the bias term, i.e., the b of the linear transform y = Ax + b.
Attributes: - A_ : object
Representation of linear transformation, i.e. a matrix. The linear object that implements
dot(X)
,logabsdet
, andinv
. Note that this can be a compact representation of a matrix such as merely storing the diagonal elements or a Householder transformation matrix.- A_inv_ :
Representation of the inverse linear transformation, i.e. a matrix. The linear object that implements
dot(X)
,logabsdet
, andinv
. Note that this can be a compact representation of a matrix such as merely storing the diagonal elements or a Householder transformation matrix.
Methods
create_fitted
([A, b, coef, intercept, …])Create fitted linear projector. fit
(self, X[, y, lin_est_fit_params, …])[Placeholder]. fit_transform
(self, X[, y])Fit to data, then transform it. get_domain
(self)Get the domain of this destructor. get_params
(self[, deep])Get parameters for this estimator. inverse_transform
(self, X[, y])Apply inverse destructive transformation to X. score
(self, X[, y])Return the mean log likelihood (or log(det(Jacobian))). score_samples
(self, X[, y])Compute log(det(Jacobian)) for each sample. set_params
(self, \*\*params)Set the parameters of this estimator. transform
(self, X[, y])Apply destructive transformation to X. -
__init__
(self, linear_estimator=None, orthogonal=False, fit_bias=True)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
classmethod
create_fitted
(A=None, b=None, coef=None, intercept=None, fitted_linear_estimator=None, **kwargs)[source]¶ Create fitted linear projector.
Must provide (A and b) OR (coef and intercept) OR (fitted_linear_estimator) but only one combination should be provided.
Parameters: - A : array-like, shape (n_features, n_features), optional
Matrix for projection.
- b : array-like, shape (n_features,), optional
Shift vector for linear projection.
- coef : array-like, shape (n_features,), optional
Vector of coefficents, will form scaled Householder reflector.
- intercept : float, optional
Intecept for 1D linear projection.
- fitted_linear_estimator : fitted estimator, optional
Must be a linear estimator that has coef_ or components_ fitted parameters.
- **kwargs
Other parameters to pass to constructor.
Returns: - fitted_transformer : Transformer
Fitted transformer.
-
fit
(self, X, y=None, lin_est_fit_params=None, fitted_lin_est=None)[source]¶ [Placeholder].
Parameters: - X :
- y :
- lin_est_fit_params :
- fitted_lin_est :
Returns: - obj : object
-
fit_transform
(self, X, y=None, **fit_params)¶ Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Parameters: - X : numpy array of shape [n_samples, n_features]
Training set.
- y : numpy array of shape [n_samples]
Target values.
Returns: - X_new : numpy array of shape [n_samples, n_features_new]
Transformed array.
-
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)[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.
Returns: - X_new : array-like, shape (n_samples, n_features)
Transformed data.
-
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(det(Jacobian)) for each sample.
Note that this is not the log-likelihood since this is not a destructor. This score is constant for all samples because the Jacobian is constant for linear operations and depends only on the transformation matrix.
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_det_jacobian : array, shape (n_samples,)
Log determinant of the Jacobian for 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
-
transform
(self, X, y=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.
Returns: - X_new : array-like, shape (n_samples, n_features)
Transformed data.