fuzzyclust.extensions.FuzzyCShells#
- class fuzzyclust.extensions.FuzzyCShells(n_clusters=3, m=2.0, algorithm='fcss', newton_steps=2, tol=0.0001, max_iter=300, init='fcm', n_init=1, random_state=None, verbose=0)[source]#
Bases:
BaseFuzzyClustererFuzzy c-(spherical) shells: circles / hyperspheres as prototypes.
Hollow clusters – rings in 2-D, spherical shells in higher dimension – have no interior points, so the point prototype of FCM placed at their center is far from every member, and concentric rings cannot be told apart at all. Shell clustering describes cluster \(i\) by a center \(\mathbf{v}_i\) and a radius \(r_i\) and measures the distance of a sample as its deviation from the sphere. Compared with FCM only the prototype and the distance change; the membership formula is the same. Two published algorithms are implemented and selected by
algorithm:"fcss"– the fuzzy c-spherical shells algorithm of Krishnapuram, Nasraoui and Frigui [2]. The squared algebraic distance \((\|\mathbf{x}_k-\mathbf{v}_i\|^2-r_i^2)^2\) is quadratic in a reparametrised prototype, so the prototype update is a closed-form weighted least-squares fit of a circle/sphere."fcs"– the original fuzzy c-shells algorithm of Davé [1] with the squared radial (geometric) distance \((\|\mathbf{x}_k-\mathbf{v}_i\|-r_i)^2\). Its necessary conditions are coupled nonlinear equations in \(\mathbf{v}_i\) and \(r_i\), which Davé solved by Newton’s method in every iteration; herenewton_stepsGauss–Newton steps on the radial residuals are started from the closed-form FCSS fit.
- Parameters:
- n_clusters
int, default=3 Number of shells \(c\).
- m
float, default=2.0 Fuzziness exponent \(m>1\).
- algorithm{“fcss”, “fcs”}, default=”fcss”
Shell distance and prototype update, see above.
- newton_steps
int, default=2 Gauss–Newton steps per iteration for
algorithm="fcs".- tol
float, default=1e-4 - max_iter
int, default=300 - init{“fcm”, “random”, “kmeans++”}
orndarray, default=”fcm” "fcm"runsFCMand starts from its hardened partition, which for intersecting or separate shells puts the groups on different shells and avoids the poor local minimum of one big circle through everything. For concentric shells FCM halves every ring, so usen_init > 1(the further restarts are random) orinit="random"."random"/"kmeans++"/array as in the base class; the first prototype update turns the point prototypes into shells.- n_init
int, default=1 Number of restarts; the solution with the smallest objective is kept. With
init="fcm"the first restart uses the hardened FCM partition and the further ones random point prototypes (FCM itself converges to nearly the same partition from most starts, so repeating it would not diversify the restarts).- random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- cluster_centers_
ndarrayofshape(n_clusters,n_features) Shell centers \(\mathbf{v}_i\).
- radii_
ndarrayofshape(n_clusters,) Shell radii \(r_i\).
- membership_, labels_, objective_, objective_history_, n_iter_
See
BaseFuzzyClusterer.- distances_
ndarrayofshape(n_samples,n_clusters) \(D_{ik}\) at convergence: \(|\,\|\mathbf{x}_k-\mathbf{v}_i\|^2-r_i^2|\) for FCSS, the absolute radial deviation \(|\,\|\mathbf{x}_k-\mathbf{v}_i\|-r_i|\) for FCS (the same holds for
transform();radial_deviation()gives the signed radial deviation for both).
- cluster_centers_
Notes
Both algorithms minimize the c-means functional with a shell distance,
\[J = \sum_{i=1}^{c}\sum_{k=1}^{N}\mu_{ik}^m D^2_{ik},\qquad D^2_{ik} = \left(\|\mathbf{x}_k-\mathbf{v}_i\|^2 - r_i^2\right)^2 \ \text{(FCSS)}\quad\text{or}\quad D^2_{ik} = \left(\|\mathbf{x}_k-\mathbf{v}_i\| - r_i\right)^2 \ \text{(FCS)},\]under \(\sum_i\mu_{ik}=1\), so the memberships follow the FCM formula with the shell distance. FCSS writes the algebraic distance as \(\|\mathbf{x}_k\|^2+\mathbf{p}_i^T\mathbf{y}_k\) with \(\mathbf{p}_i=[-2\mathbf{v}_i^T,\ \mathbf{v}_i^T\mathbf{v}_i-r_i^2]^T\) and regressors \(\mathbf{y}_k=[\mathbf{x}_k^T,\,1]^T\), so that the weighted least-squares solution
\[\mathbf{p}_i = -\Big(\sum_k\mu_{ik}^m\mathbf{y}_k\mathbf{y}_k^T\Big)^{-1} \sum_k\mu_{ik}^m\|\mathbf{x}_k\|^2\,\mathbf{y}_k\]gives \(\mathbf{v}_i\) and \(r_i^2=\mathbf{v}_i^T\mathbf{v}_i-p_{i,n+1}\) in closed form. For FCS the necessary conditions are
\[r_i = \frac{\sum_k\mu_{ik}^m\|\mathbf{x}_k-\mathbf{v}_i\|}{\sum_k\mu_{ik}^m}, \qquad \sum_k\mu_{ik}^m\Big(1-\frac{r_i}{\|\mathbf{x}_k-\mathbf{v}_i\|}\Big) (\mathbf{x}_k-\mathbf{v}_i) = \mathbf{0},\]which have no closed form. Near the shell the two distances are related by \(\|\mathbf{x}\|^2-r^2=(\|\mathbf{x}\|-r)(\|\mathbf{x}\|+r)\approx 2r(\|\mathbf{x}\|-r)\), so the algebraic distance weights the same radial deviation more on a large shell than on a small one: FCSS memberships favor small shells, a known bias that matters when shells of similar radius are nested or when only arcs are observed; FCS does not have it but costs a Newton iteration per cluster and iteration.
References
[1]R. N. Davé, “Fuzzy shell-clustering and applications to circle detection in digital images”, Int. J. General Systems 16(4), 343–355, 1990.
[2]R. Krishnapuram, O. Nasraoui, H. Frigui, “The fuzzy c spherical shells algorithm: a new approach”, IEEE Trans. Neural Networks 3(5), 663–671, 1992.
Examples
>>> from fuzzyclust.extensions import FuzzyCShells >>> from fuzzyclust.datasets import make_rings >>> X, y = make_rings(radii=(1.0, 3.0), random_state=0) >>> fcs = FuzzyCShells(n_clusters=2, n_init=5, random_state=0).fit(X) >>> sorted(fcs.radii_.round(1).tolist()) [1.0, 3.0]