Clustering Pcca#
pcca
#
| CLASS | DESCRIPTION |
|---|---|
PCCA |
Perron Cluster Cluster Analysis (PCCA) for spectral clustering. |
| FUNCTION | DESCRIPTION |
|---|---|
pcca |
Perform PCCA spectral clustering (functional interface). |
Classes#
PCCA(n_states: int, optimize: bool = True, n_iter: int = 100, tol: float = 1e-05, eps: float = torch.finfo(torch.float32).eps, lr: float = 0.1, device: torch.device | str | None = None, dtype: torch.dtype = torch.float32)
#
Bases: Estimator
Perron Cluster Cluster Analysis (PCCA) for spectral clustering.
PCCA performs fuzzy clustering on eigenvectors of transition matrices to identify metastable states in Markov chains or general spectral clustering tasks. The algorithm identifies a simplex structure in eigenvector space and computes soft membership assignments.
The input features should resemble eigenvectors (excluding the constant stationary eigenvector corresponding to eigenvalue 1). A constant first column is automatically prepended internally to satisfy the partition of unity constraint required by PCCA.
| PARAMETER | DESCRIPTION |
|---|---|
n_states
|
Number of metastable states (clusters) to identify. Must be at least 2.
TYPE:
|
optimize
|
Whether to optimize the transition matrix after initialization. If False, uses only the initial simplex-based transformation.
TYPE:
|
n_iter
|
Maximum iterations for optimization.
TYPE:
|
tol
|
Convergence tolerance for optimization.
TYPE:
|
eps
|
Numerical stability regularization for preventing division by zero and ensuring positive definiteness.
TYPE:
|
lr
|
Learning rate for optimization.
TYPE:
|
device
|
Device to run computations on. If None, automatically selects CUDA if available, otherwise CPU.
TYPE:
|
dtype
|
Data type to use for computations.
TYPE:
|
Properties
proba : torch.Tensor
Fuzzy membership matrix of shape (n_samples, n_states). Each row sums
to 1 and represents probability of belonging to each state.
labels : torch.Tensor
State assignments of shape (n_samples,). Computed as argmax of
membership matrix.
transition_matrix : torch.Tensor
Transition matrix of shape (n_states, n_states).
References
.. [1] Deuflhard P, Weber M., "Robust Perron Cluster Analysis in Conformation Dynamics," Linear Algebra Appl., vol 398 pp 161-184, 2005. .. [2] Kube S, Weber M., "A coarse graining method for the identification of transition rates between molecular conformations," J. Chem. Phys., vol 126 pp 24103-024113, 2007. .. [3] Kube S., "Statistical Error Estimation and Grid-free Hierarchical Refinement in Conformation Dynamics," Doctoral Thesis, 2008.
Examples:
Basic PCCA clustering on eigenvectors:
>>> pcca = PCCA(n_states=3)
>>> X_eigenvectors = torch.randn(100, 2) # 2 non-trivial eigenvectors
>>> labels = pcca.fit_predict(X_eigenvectors)
>>> labels.shape
torch.Size([100])
Accessing memberships:
>>> pcca.fit(X_eigenvectors)
>>> proba = pcca.predict_proba(X_eigenvectors)
>>> proba.shape
torch.Size([100, 3])
>>> proba.sum(dim=1) # Each row sums to 1
tensor([1., 1., 1., ...])
| METHOD | DESCRIPTION |
|---|---|
fit |
Fit PCCA+ model to eigenvector data. |
predict |
Predict state labels for data. |
fit_predict |
Fit and predict state labels. |
predict_proba |
Predict probabilities for data. |
score |
Compute state clustering score. |
get_results |
Get all fitted parameters as a dictionary. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
proba |
Membership probability matrix of shape (n_samples, n_states).
TYPE:
|
labels |
State assignments of shape (n_samples,).
TYPE:
|
transition_matrix |
Transition matrix A of shape (n_states, n_states).
TYPE:
|
Source code in spectre/clustering/pcca.py
Attributes#
proba: torch.Tensor
property
#
Membership probability matrix of shape (n_samples, n_states).
labels: torch.Tensor
property
#
State assignments of shape (n_samples,).
transition_matrix: torch.Tensor
property
#
Transition matrix A of shape (n_states, n_states).
Functions#
fit(X: torch.Tensor, weights: torch.Tensor | None = None, target: torch.Tensor | None = None, **kwargs) -> PCCA
#
Fit PCCA+ model to eigenvector data.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Data of shape (n_samples, n_eigenvectors). Typically the non-trivial dominant eigenvectors from spectral decomposition (excluding the constant first eigenvector).
TYPE:
|
weights
|
Sample weights. Currently not used.
TYPE:
|
target
|
Target values for supervised learning. Not supported.
TYPE:
|
**kwargs
|
Additional keyword arguments.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
PCCA
|
Return self. |
Source code in spectre/clustering/pcca.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
predict(X: torch.Tensor) -> torch.Tensor
#
Predict state labels for data.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Data of shape (n_samples, in_features).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
State labels of shape (n_samples,). |
Source code in spectre/clustering/pcca.py
fit_predict(X: torch.Tensor, weights: torch.Tensor | None = None, target: torch.Tensor | None = None, **kwargs) -> torch.Tensor
#
Fit and predict state labels.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Data of shape (n_samples, in_features).
TYPE:
|
weights
|
Sample weights. Currently not used.
TYPE:
|
target
|
Target values. Not supported.
TYPE:
|
**kwargs
|
Additional keyword arguments.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Stete labels of shape (n_samples,). |
Source code in spectre/clustering/pcca.py
predict_proba(X: torch.Tensor) -> torch.Tensor
#
Predict probabilities for data.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Data of shape (n_samples, in_features).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Membership probabilities of shape (n_samples, n_states). |
Source code in spectre/clustering/pcca.py
score(X: torch.Tensor, weights: torch.Tensor | None = None, target: torch.Tensor | None = None) -> float
#
Compute state clustering score.
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Data of shape (n_samples, in_features).
TYPE:
|
weights
|
Weights of shape (n_samples,).
TYPE:
|
target
|
Target labels of shape (n_samples,).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Score of the clustering. |
Source code in spectre/clustering/pcca.py
get_results() -> dict[str, torch.Tensor]
#
Get all fitted parameters as a dictionary.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Tensor]
|
Dictionary containing computed results. |
Source code in spectre/clustering/pcca.py
Functions#
pcca(X: torch.Tensor, n_states: int, optimize: bool = True, n_iter: int = 100, tol: float = 1e-05, eps: float = torch.finfo(torch.float32).eps, device: torch.device | str | None = None, dtype: torch.dtype = torch.float32) -> dict[str, torch.Tensor]
#
Perform PCCA spectral clustering (functional interface).
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Data of shape (n_samples, in_features).
TYPE:
|
n_states
|
Number of metastable states to identify.
TYPE:
|
optimize
|
Whether to optimize transition matrix.
TYPE:
|
n_iter
|
Maximum optimization iterations.
TYPE:
|
tol
|
Convergence tolerance.
TYPE:
|
eps
|
Numerical stability parameter.
TYPE:
|
device
|
Computation device.
TYPE:
|
dtype
|
Data type.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Tensor]
|
Dictionary with results. |