fuzzyCMeans
Executes one iteration of the fuzzy C-means clustering algorithm. Unlike the standard C-means algorithm, this uses fuzzy membership values that allow points to belong to multiple clusters with varying degrees of membership.Parameters
Array of points to cluster. Each point has
x and y coordinates.Array of initial centroids. Each centroid has
x and y coordinates.The fuzzification parameter is hardcoded to
m=2 in this implementation. This parameter controls the degree of fuzziness in the clustering.Returns
Returns an object containing the results of one fuzzy C-means iteration:Matrix of distances where each element [i][j] is the distance between the i-th centroid and the j-th point.
Fuzzy membership matrix where each element [i][j] represents the degree of membership (0 to 1) of the j-th point to the i-th cluster.
New array of centroids calculated using fuzzy weighted means.
Array of fuzzy cost values for each centroid.
Total cost as the sum of all individual fuzzy cost values.
Example
Fuzzification Parameter
The fuzzy C-means algorithm uses a fuzzification parameterm that controls the degree of fuzziness in the clustering:
m = 1: Hard clustering (equivalent to standard C-means)m = 2: Default fuzzy clustering (used in this implementation)m > 2: Increasingly fuzzy clustering
m=2, points can have meaningful membership in multiple clusters, allowing for soft boundaries between clusters.
Helper Functions
getFuzzyMembershipMatrix
Calculates the fuzzy membership matrix given a distance matrix and a fuzzification parameter.Matrix of distances between points and centroids.
Fuzzification parameter (typically set to 2).
getNewFuzzyCentroids
Calculates new centroids based on the fuzzy membership matrix.Array of points.
Fuzzy membership matrix.
Fuzzification parameter (typically set to 2).
getFuzzyCostValues
Calculates the cost values for each centroid based on the fuzzy membership and distance matrices.Matrix of distances between points and centroids.
Fuzzy membership matrix.
Fuzzification parameter (typically set to 2).
Comparison with Standard C-Means
Standard C-Means:- Hard assignment: Each point belongs to exactly one cluster
- Membership values: Binary (0 or 1)
- Best for: Well-separated clusters
- Soft assignment: Points can belong to multiple clusters
- Membership values: Continuous (0 to 1)
- Best for: Overlapping or ambiguous cluster boundaries