fuzzyclust.relational.NERFCM#
- class fuzzyclust.relational.NERFCM(n_clusters=3, metric='euclidean', m=2.0, tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#
Bases:
RelationalFCMNon-Euclidean relational fuzzy c-means (Hathaway and Bezdek, 1994).
Relational fuzzy c-means (
RelationalFCM) is the exact dual of FCM only when the dissimilarity matrix \(\mathbf{R}\) is Euclidean (squared distances of some point configuration). Many relational data are not – dynamic-time-warping distances, Gower dissimilarities with missing values, subjective ratings – and then the relational distance \(d^2_{ik}=(\mathbf{R}\mathbf{v}_i)_k-\tfrac12\mathbf{v}_i\T\mathbf{R}\mathbf{v}_i\) can be negative. NERF c-means uses the \(\beta\)-spread transformation \(\mathbf{R}_\beta=\mathbf{R}+\beta(\mathbf{1}\mathbf{1}\T-\mathbf{I})\): adding \(\beta\) to every off-diagonal dissimilarity makes the matrix Euclidean for a large enough \(\beta\), and the paper shows that this shifts the relational distances by \(\tfrac{\beta}{2}\norm{\mathbf{e}_k-\mathbf{v}_i}^2\) – a term that is computed without ever forming \(\mathbf{R}_\beta\). The spread is applied adaptively: \(\beta\) starts at zero and is increased only when, and only as much as, a negative distance appears, so the partition stays as close to the RFCM result as the data allow.- Parameters:
- n_clusters, metric, m, tol, max_iter, init, n_init, random_state, verbose
As in
RelationalFCM.metric="precomputed"is the typical use; a feature metric that is not Euclidean (e.g."cityblock","cosine") also leads to a non-Euclidean \(\mathbf{R}\) after squaring.
- Attributes:
- beta_
float Final spread \(\beta\).
0.0means the matrix behaved as a Euclidean one and the result is the RFCM partition.- n_spread_updates_
int How many times \(\beta\) had to be increased during the run.
- relational_centers_, cluster_centers_, dissimilarity_matrix_, membership_, labels_,
- distances_, objective_, objective_history_, n_iter_
See
RelationalFCM. The objective is that of the spread matrix \(\mathbf{R}_\beta\).
- beta_
Notes
At every iteration the relational distances are computed with the current \(\beta\); if some \(d^2_{ik}<0\), the increment
\[\Delta\beta=\max_{i,k}\frac{-2\,d^2_{ik}}{\norm{\mathbf{e}_k-\mathbf{v}_i}^2},\qquad \beta\leftarrow\beta+\Delta\beta,\qquad d^2_{ik}\leftarrow d^2_{ik}+\tfrac{\Delta\beta}{2}\norm{\mathbf{e}_k-\mathbf{v}_i}^2\]is the smallest shift that makes all distances non-negative (the paper’s Step 3), and the iteration continues with the shifted distances. Since \(\norm{\mathbf{e}_k-\mathbf{v}_i}^2=1-2v_{ik}+\norm{\mathbf{v}_i}^2\) is larger for objects far from the prototype, the shift affects weakly related objects most and leaves the memberships of well-clustered objects nearly unchanged; a large final \(\beta\) nevertheless flattens the partition toward \(1/c\), which is the price of a strongly non-Euclidean matrix. New objects (
predict_proba) receive the same shift with \(\norm{\mathbf{e}-\mathbf{v}_i}^2=1+\norm{\mathbf{v}_i}^2\), the value for an object outside the training set.References
[1]R. J. Hathaway, J. C. Bezdek, “NERF c-means: non-Euclidean relational fuzzy clustering”, Pattern Recognition 27(3), 429–437, 1994.
[2]R. J. Hathaway, J. W. Davenport, J. C. Bezdek, “Relational duals of the c-means clustering algorithms”, Pattern Recognition 22(2), 205–212, 1989.
Examples
>>> import numpy as np >>> from fuzzyclust.datasets import make_fuzzy_blobs >>> from fuzzyclust.relational import NERFCM, pairwise_dissimilarity >>> X, _ = make_fuzzy_blobs(random_state=0) >>> R = pairwise_dissimilarity(X, metric="cityblock") ** 2 # squared L1 distances: not Euclidean >>> nerf = NERFCM(n_clusters=3, metric="precomputed", random_state=0).fit(R) >>> bool(nerf.beta_ > 0), nerf.n_spread_updates_, nerf.membership_.shape (True, 1, (300, 3))
Examples using fuzzyclust.relational.NERFCM#
Relational fuzzy c-means and NERF for non-Euclidean data
Gower’s dissimilarity versus one-hot encoding for mixed data