class ClusterModel¶
- class deeptime.clustering.ClusterModel(cluster_centers: ndarray, metric: str = 'euclidean', converged: bool = False)¶
A generic clustering model. Stores the number of cluster centers, the position of cluster centers, the metric that was used to compute the cluster centers and whether the estimation converged. It can be used to transform data by assigning each frame to its closest cluster center.
- Parameters:
cluster_centers ((k, d) ndarray) – The cluster centers, length of the array should match
n_clusters
.metric (str, default='euclidean') – The metric that was used for estimation, defaults to Euclidean metric.
converged (bool, optional, default=False) – Whether the estimation converged.
Examples
Let us create an artificial cluster model with three cluster centers in a three-dimensional space. The cluster centers are just the canonical basis vectors \(c_1 = (1,0,0)^\top\), \(c_2 = (0,1,0)^\top\), and \(c_3 = (0,0,1)^\top\).
We can transform data with the model. The data are five frames sampled around the third cluster center.
>>> model = ClusterModel(cluster_centers=np.eye(3)) >>> data = np.random.normal(loc=[0, 0, 1], scale=0.01, size=(5, 3)) >>> assignments = model.transform(data) >>> print(assignments) [2 2 2 2 2]
Attributes
Gets the cluster centers that were estimated for this model.
Whether the estimation process converged.
dim
The metric that was used.
The number of cluster centers.
Methods
copy
()Makes a deep copy of this model.
get_params
([deep])Get the parameters.
set_params
(**params)Set the parameters of this estimator.
transform
(data[, n_jobs])For each frame in data, yields the index of the closest point in
cluster_centers
.- __call__(*args, **kwargs)¶
Call self as a function.
- copy() Model ¶
Makes a deep copy of this model.
- Returns:
A new copy of this model.
- Return type:
copy
- get_params(deep=False)¶
Get the parameters.
- Returns:
params – Parameter names mapped to their values.
- Return type:
mapping of string to any
- set_params(**params)¶
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form
<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters:
**params (dict) – Estimator parameters.
- Returns:
self – Estimator instance.
- Return type:
object
- transform(data, n_jobs=None) ndarray ¶
For each frame in data, yields the index of the closest point in
cluster_centers
.- Parameters:
data ((T, d) ndarray) – frames
n_jobs (int, optional, default=None) – number of jobs to use for assignment
- Returns:
discrete_trajectory – A discrete trajectory where each frame denotes the closest cluster center.
- Return type:
(T, 1) ndarray
- property cluster_centers: ndarray¶
Gets the cluster centers that were estimated for this model.
- Returns:
Array containing estimated cluster centers.
- Return type:
np.ndarray
- property converged: bool¶
Whether the estimation process converged. Per default this is set to False, which can also indicate that the model was created manually and does not stem from an Estimator directly.
- Returns:
converged – Whether the clustering converged
- Return type:
bool
- property metric: str¶
The metric that was used.
- Returns:
metric – Name of the metric that was used. The name is related to the implementation via the
metric registry
.- Return type:
str
- property n_clusters: int¶
The number of cluster centers.
- Returns:
The number of cluster centers.
- Return type:
int