pg_utils.numerics.utils.cluster_modes

pg_utils.numerics.utils.cluster_modes(eig_vals: ndarray, rtol: float = 1e-05, atol: float = 1e-08)[source]

Clustering of eigenvalues. This function takes in an array of eigenvalues, and decide whether they are degenerate or distinct, and then outputs the clustered result.

Parameters:
  • eig_vals (np.ndarray) – array of eigenvalues;

  • rtol (float) – relative tolerance between eigenvalues considered degenerate

  • atol (float) – absolute tolerance between eigenvalues considered degenerate

Returns:

index of distinct modes, degenerate ones share the same index

Note

The input eigenvalue array should be already “sorted” in some ways, so that clustering only occurs for adjacent eigenvalues.

Example:

>>> a = np.array([1., 2., 2.0000001, 2.99999999, 3.0, 3.00000001, 4.5])
>>> clusters = cluster_modes(a, rtol=1e-5, atol=1e-5)
>>> clusters
np.array([0, 1, 1, 1, 2, 2, 3])