def decompose_features(features, decomposer, n_components=None, lag_time=1): ''' Decomposing features is a way to reduce the dimension of the features. Each of the components is a eigenvector of the feature space, dimension: (n_features,) The old features are transformed to the new feature space. Consider one sample, which is vectorized to (n_features,).T, apply the transform matrix, which is in the shape (n_components, n_features), we will get its projection onto the new space (n_components,). -------------------------------------------------------------------------------------------------------------------------------------- Input features : array-like, length n_trajs, each of shape (n_samples, n_features) Output features_new : array-like, length n_trajs, each of shape (n_samples, n_components) ((n_samples, n_samples) if n_components = None) dcmp.components_ : shape (n_components, n_features), ((n_samples, n_features) if n_components = None) PCA : Principal axes in feature space, representing the directions of maximum variance in the data. tICA : Components with maximum autocorrelation. ''' if decomposer == 'PCA': from msmbuilder.decomposition import PCA dcmp = PCA(n_components=n_components) elif decomposer == 'tICA': from msmbuilder.decomposition import tICA dcmp = tICA(n_components=n_components, lag_time=lag_time) features_new = dcmp.fit_transform(features) return features_new, dcmp.components_
def decompose_features(features, decomposer, n_components=None, lag_time=1): ''' Input features : list of arrays, length n_trajs, each of shape (n_samples, n_features) Output features_new : list of arrays, length n_trajs, each of shape (n_samples, n_features_new) ''' if decomposer == 'PCA': from msmbuilder.decomposition import PCA dcmp = PCA(n_components=n_components) elif decomposer == 'tICA': from msmbuilder.decomposition import tICA dcmp = tICA(n_components=n_components, lag_time=lag_time) return dcmp.fit_transform(features)