pysensors.basis package

Module contents

class pysensors.basis.Identity(n_basis_modes=None)[source]

Bases: BaseEstimator, InvertibleBasis, MatrixMixin

Generate an identity transformation which maps all input features to themselves.

Parameters

n_basis_modes (int, optional (default None)) – Number of basis modes to retain. If None, all are included in the basis.

Attributes

basis_matrix_ (numpy ndarray, shape (n_features, n_basis_modes)) – The transpose of the first n_basis_modes examples from the input data.

fit(X)[source]

Memorize the input data.

Parameters

X (array-like, shape (n_samples, n_features)) – The training data.

Returns

self

Return type

instance

matrix_inverse(n_basis_modes=None)[source]

Get the inverse matrix mapping from measurement space to coordinates with respect to the basis.

Note that this is not the inverse of the matrix returned by self.matrix_representation. It is the (psuedo) inverse of the matrix whose columns are the basis modes.

Parameters

n_basis_modes (positive int, optional (default None)) – Number of basis modes to be used to compute inverse.

Returns

B – The inverse matrix. In this case B is the identity matrix.

Return type

numpy ndarray, shape (n_features, n_features)

class pysensors.basis.SVD(n_basis_modes=10, **kwargs)[source]

Bases: TruncatedSVD, InvertibleBasis, MatrixMixin

Generate an SVD transformation which maps input features to SVD modes.

Assumes the data has already been centered (to have mean 0).

Parameters
  • n_basis_modes (int, optional (default 10)) – Number of basis modes to retain. Cannot be larger than the number of features n_features, or the number of examples n_examples.

  • algorithm (string, optional (default "randomized")) – SVD solver to use. Either “arpack” for the ARPACK wrapper in SciPy (scipy.sparse.linalg.svds), or “randomized” for the randomized algorithm due to Halko (2009).

  • kwargs (dict, optional) – Keyword arguments to be passed to the TruncatedSVD constructor

Attributes

basis_matrix_ (numpy ndarray, shape (n_features, n_basis_modes)) – The top n_basis_modes left singular vectors of the training data.

References

https://scikit-learn.org/stable/modules/generated/ sklearn.decomposition.TruncatedSVD.html

Finding structure with randomness: Stochastic algorithms for constructing approximate matrix decompositions Halko, et al., 2009 (arXiv:909) https://arxiv.org/pdf/0909.4061.pdf

fit(X)[source]
Parameters

X (array-like, shape (n_samples, n_features)) – The training data.

Returns

self

Return type

instance

matrix_inverse(n_basis_modes=None)[source]

Get the inverse matrix mapping from measurement space to coordinates with respect to the basis.

Note that this is not the inverse of the matrix returned by self.matrix_representation. It is the (psuedo) inverse of the matrix whose columns are the basis modes.

Parameters

n_basis_modes (positive int, optional (default None)) – Number of basis modes to be used to compute inverse.

Returns

B – The inverse matrix.

Return type

numpy ndarray, shape (n_basis_modes, n_features)

property n_basis_modes

Number of basis modes.

class pysensors.basis.RandomProjection(n_basis_modes=10, eps=0.1, random_state=None)[source]

Bases: GaussianRandomProjection, InvertibleBasis, MatrixMixin

Generate a basis based on Gaussian random projection.

Wrapper for sklearn.random_projection.GaussianRandomProjection.

Parameters
  • n_basis_modes (int or "auto", optional (default 10)) –

    Dimensionality of the target projection space (number of modes).

    n_basis_modes can be automatically adjusted according to the number of samples in the dataset and the bound given by the Johnson-Lindenstrauss lemma. In that case the quality of the embedding is controlled by the eps parameter.

  • eps (positive float, optional (default 0.1)) –

    Parameter to control the quality of the embedding according to the Johnson-Lindenstrauss lemma when n_basis_modes is set to ‘auto’.

    Smaller values lead to better embedding and higher number of dimensions (n_basis_modes) in the target projection space.

  • random_state (int, RandomState instance or None, optional (default=None)) – Controls the pseudo random number generator used to generate the projection matrix at fit time. Pass an int for reproducible output across multiple function calls.

Attributes

basis_matrix_ (numpy ndarray, shape (n_features, n_basis_modes)) – Random projections of training data.

References

https://scikit-learn.org/stable/modules/generated/ sklearn.random_projection.GaussianRandomProjection.html

fit(X)[source]
Xarray-like, shape (n_samples, n_features)

The training data.

Returns

self

Return type

instance

matrix_inverse(n_basis_modes=None, **kwargs)[source]

Get the inverse matrix mapping from measurement space to coordinates with respect to the basis.

Note that this is not the inverse of the matrix returned by self.matrix_representation. It is the (psuedo) inverse of the matrix whose columns are the basis modes.

Parameters

n_basis_modes (positive int, optional (default None)) – Number of basis modes to be used to compute inverse.

Returns

B – The inverse matrix.

Return type

numpy ndarray, shape (n_basis_modes, n_features)

property n_basis_modes

Number of basis modes.

class pysensors.basis.Custom(U, n_basis_modes=10, **kwargs)[source]

Bases: InvertibleBasis, MatrixMixin

kwargs : Not defined but added to remain consistent with prior basis functions.

fit(X)[source]
Parameters

X (array-like, shape (n_samples, n_features)) – The training data.

Returns

self

Return type

instance

matrix_inverse(n_basis_modes=None)[source]

Get the inverse matrix mapping from measurement space to coordinates with respect to the basis.

Note that this is not the inverse of the matrix returned by self.matrix_representation. It is the (pseudo) inverse of the matrix whose columns are the basis modes.

Parameters

n_basis_modes (positive int, optional (default None)) – Number of basis modes to be used to compute inverse.

Returns

B – The inverse matrix.

Return type

numpy ndarray, shape (n_basis_modes, n_features)

property n_basis_modes

Number of basis modes.