asaplib.reducedim package¶
Submodules¶
asaplib.reducedim.dim_reducer module¶
Methods and functions to perform dimensionality reduction
-
class
asaplib.reducedim.dim_reducer.
Dimension_Reducers
(dreduce_spec_dict={})[source]¶ Bases:
object
-
add
(dreduce_spec, tag)[source]¶ adding the specifications of a new dimensionality reducer :param dreduce_spec: :type dreduce_spec: a dictionary that specify which dimensionality reducer to use
-
bind
()[source]¶ binds the objects that actually performs dimension reduction these objects need to have .fit(desc)/.transform(desc)/.fit_transform(desc) methods to perform reduction on a design matrix desc
-
fit
(X)[source]¶ compute the global descriptor vector for a frame from atomic contributions :param X: Input points. :type X: array-like, shape=[n_samples,n_dim_high]
-
asaplib.reducedim.ml_kpca module¶
Tools for doing kernel PCA on environmental similarity e.g. kNN = np.genfromtxt(prefix+”.k”,skip_header=1) proj = KernelPCA(kpca_d).fit_transform(kNN)
KernelPCA with precomputed kernel for now only!!!!!!!!!!!!
-
class
asaplib.reducedim.ml_kpca.
KernelPCA
(n_components=2)[source]¶ Bases:
object
-
static
center_square
(kernel)[source]¶ Centering of a kernel matrix, with additional centering info
- Parameters
kernel (array-like, (shape=MxM)) – Kernel matrix
- Returns
colmean (ndarray, (shape=M)) – mean of columns from kernel matrix
mean (float) – mean of the entire kernel matrix
centered_kernel (ndarray, (shape=MxM)) – kernel centered in feature space
-
fit
(kmat)[source]¶ Fit kernel PCA on the precomputed kernel matrix
Notes
Keeps the kernel matrix intact
can be done only once on a given object, need to reinitialise if trying to run again
- Parameters
kmat (numpy.ndarray, shape=(M,M)) – kerenl matrix between the observations needs to be square and real, symmetric
-
fit_transform
(kmat, copy=True)[source]¶ Fit kernel PCA on the precomputed kernel matrix & project to lower dimensions
Notes
Keeps the kernel matrix intact
can be done only once on a given object, need to reinitialise if trying to run again
- Parameters
kmat (numpy.ndarray, shape=(M,M)) – kerenl matrix between the observations needs to be square and real, symmetric
copy (bool, optional, default=True) – copy the kernel matrix or overwrite it, passed to self.transform() nb. the kernel matrix will be left centered if this is False
-
fit_vectors
(vecs)[source]¶ Fit Kernel PCA from vectors in the large dimension
for future, not implemented yet
-
transform
(ktest, iscentered=False, copy=True)[source]¶ Transforms to the lower dimensions
- Parameters
ktest (array_like, shape=(L,M)) – kernel matrix of the test vectors with the training vectors
iscentered (bool, optional, default=False) – if the kernel is centered already, mainly used for the fit_transform function
copy (bool, optional, default=True) – copy the kernel matrix or overwrite it nb. the kernel matrix will be left centered if this is False
- Returns
projected_vectors – projections of the given kernel wrt. the training kernel
- Return type
numpy.array, shape=(L,n_components)
-
static
asaplib.reducedim.ml_pca module¶
tools for doing PCA e.g. desc = np.genfromtxt(prefix+”.desc”) proj = PCA(pca_d).fit_transform(desc)
-
class
asaplib.reducedim.ml_pca.
PCA
(n_components=2, scalecenter=True)[source]¶ Bases:
object
-
fit
(desc)[source]¶ Fit PCA on the precomputed descriptor matrix
- Parameters
desc (array-like, shape=[n_descriptors, n_samples]) –
matrix (design) –
-
fit_transform
(desc)[source]¶ Fit PCA on the design matrix & project to lower dimensions
- Parameters
desc_test (array_like, shape=[n_descriptors, n_samples]) – design matrix of the new samples
- Returns
projected_vectors – projections of the design matrix on low dimension
- Return type
numpy.array, shape=(L,n_components)
-
asaplib.reducedim.sparse_kpca module¶
Tools for performing dimensionality reduction of design matrices using sparse KPCA
-
class
asaplib.reducedim.sparse_kpca.
SPARSE_KPCA
(n_components=2, kernel={}, sparse_mode='fps', n_sparse=None)[source]¶ Bases:
object
-
fit
(desc)[source]¶ Fit KPCA on the precomputed descriptor matrix
- Parameters
desc (array-like, shape=[n_descriptors, n_samples]) –
matrix (design) –
-
fit_transform
(desc)[source]¶ Fit PCA on the design matrix & project to lower dimensions
- Parameters
desc (array_like, shape=[n_descriptors, n_samples]) – design matrix of the new samples
- Returns
projected_vectors – projections of the design matrix on low dimension
- Return type
numpy.array, shape=(L,n_components)
-