fuzzyclust.cluster.RegularizedFCM#
- class fuzzyclust.cluster.RegularizedFCM(n_clusters=3, regularization='entropy', lam=1.0, annealing=False, lam_start=None, anneal_rate=0.8, perturbation=0.001, tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#
Bases:
BaseFuzzyClustererFuzzy c-means by entropy or quadratic regularization, with optional deterministic annealing.
Instead of fuzzifying the hard c-means functional with the exponent \(m\), a regularization term weighted by \(\lambda\) is added to it. The entropy term (Li & Mukaidono; Miyamoto & Mukaidono) yields memberships proportional to \(\exp(-D^2_{ik}/\lambda)\), so a membership function is a Gaussian bump around every prototype and \(\lambda\) plays the role of a temperature: \(\lambda\to0\) gives k-means, \(\lambda\to\infty\) gives uniform memberships. The same functional is the free energy of deterministic annealing (Rose), which tracks the minimum while the temperature is lowered from a value at which all prototypes coincide: the prototypes split at critical temperatures (phase transitions), so that the number of distinct clusters grows with decreasing \(\lambda\). The quadratic term (Miyamoto & Umayahara) yields piecewise linear memberships that are exactly zero for prototypes much farther away than the nearest one, so distant clusters receive no membership at all.
- Parameters:
- n_clusters
int, default=3 Number of clusters \(c\) (with annealing: the maximal number of distinct prototypes; coinciding prototypes are counted once in
n_effective_clusters_).- regularization{“entropy”, “quadratic”}, default=”entropy”
The regularization term.
- lam
float, default=1.0 Regularization weight \(\lambda>0\) in the units of the squared distances (the final temperature when annealing). Scale it with the squared cluster radius.
- annealingbool, default=False
Run deterministic annealing: start at
lam_startwith all prototypes at the grand mean, converge, lower \(\lambda\) geometrically byanneal_rateand continue from the previous solution untillamis reached. Only for"entropy".- lam_start
floatorNone, default=None Initial temperature.
Noneuses \(2.2\lambda_{\max}\) of the data covariance, just above the critical temperature of the first split \(2\lambda_{\max}(\mathbf{F}_0)\) for the Euclidean distance.- anneal_rate
float, default=0.8 Geometric cooling factor \(\alpha\in(0,1)\), \(\lambda\leftarrow\alpha\lambda\).
- perturbation
float, default=1e-3 Relative size of the random perturbation of the prototypes after every cooling step (needed to break the symmetry of coinciding prototypes at a phase transition).
- tol
float, default=1e-4 - max_iter
int, default=300 Maximum number of iterations (per temperature when annealing).
- init{“random”, “kmeans++”}
orndarray, default=”random” Ignored when annealing (all prototypes start at the grand mean).
- n_init
int, default=1 - random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- cluster_centers_
ndarrayofshape(n_clusters,n_features) - membership_
ndarrayofshape(n_samples,n_clusters) Fuzzy partition; for
"quadratic"it contains exact zeros.- labels_, distances_, objective_, objective_history_, n_iter_
See
BaseFuzzyClusterer; with annealingobjective_history_holds the converged objective at every temperature andn_iter_the total number of iterations.- lam_
float The regularization weight actually used (the final temperature).
- covariances_
ndarrayofshape(n_clusters,n_features,n_features) Fuzzy covariance matrices of the final partition (weights \(\mu_{ik}\)).
- cluster_history_
pandas.DataFrame Only with annealing: one row per temperature with columns
lam(temperature),n_effective(number of distinct prototypes) andobjective; a jump ofn_effectivemarks a phase transition.- n_effective_clusters_
int Only with annealing: number of distinct prototypes at the end.
- critical_temperatures_
ndarrayofshape(n_clusters,) Only with annealing: \(2\lambda_{\max}(\mathbf{F}_i)\) of every final cluster, the temperature below which it would split further.
- cluster_centers_
Notes
The entropy-regularized functional is
\[J_E=\sum_{i=1}^{c}\sum_{k=1}^{N}\mu_{ik}D^2_{ik}+\lambda\sum_{i=1}^{c}\sum_{k=1}^{N}\mu_{ik}\log\mu_{ik},\]whose necessary conditions are the Gibbs memberships and the membership-weighted means,
\[\mu_{ik}=\frac{\exp(-D^2_{ik}/\lambda)}{\sum_{j=1}^{c}\exp(-D^2_{jk}/\lambda)},\qquad \mathbf{v}_i=\frac{\sum_k\mu_{ik}\mathbf{x}_k}{\sum_k\mu_{ik}} .\]The quadratic functional \(J_Q=\sum_{ik}\mu_{ik}D^2_{ik}+\lambda\sum_{ik}\mu_{ik}^2\) has the closed-form solution of
quadratic_memberships(). In both cases the memberships enter the prototypes linearly (no exponent). Deterministic annealing minimizes the free energy \(F=-\lambda\sum_k\log\sum_i\exp(-D^2_{ik}/\lambda)\), whose stationary points are exactly the equations above; a cluster with covariance \(\mathbf{F}_i\) splits when \(\lambda\) falls below \(2\lambda_{\max}(\mathbf{F}_i)\).References
[1]S. Miyamoto, M. Mukaidono, “Fuzzy c-means as a regularization and maximum entropy approach”, Proc. 7th IFSA World Congress, Prague, vol. II, 86–92, 1997.
[2]R.-P. Li, M. Mukaidono, “A maximum-entropy approach to fuzzy clustering”, Proc. FUZZ-IEEE/IFES, Yokohama, 2227–2232, 1995.
[3]S. Miyamoto, K. Umayahara, “Fuzzy clustering by quadratic regularization”, Proc. FUZZ-IEEE, Anchorage, 1394–1399, 1998.
[4]K. Rose, “Deterministic annealing for clustering, compression, classification, regression, and related optimization problems”, Proc. IEEE 86(11), 2210–2239, 1998.
Examples
>>> from fuzzyclust.cluster import RegularizedFCM >>> from fuzzyclust.datasets import make_fuzzy_blobs >>> X, _ = make_fuzzy_blobs(random_state=0) >>> efcm = RegularizedFCM(n_clusters=3, regularization="entropy", lam=0.5, random_state=0).fit(X) >>> efcm.membership_.shape (300, 3) >>> qfcm = RegularizedFCM(n_clusters=3, regularization="quadratic", lam=2.0, random_state=0).fit(X) >>> bool((qfcm.membership_ == 0).any()) True >>> da = RegularizedFCM(n_clusters=3, lam=0.5, annealing=True, random_state=0).fit(X) >>> int(da.n_effective_clusters_) 3
Examples using fuzzyclust.cluster.RegularizedFCM#
What makes a partition fuzzy: fuzzifiers, regularization, and annealing