Overview
The distance matrix functions are fundamental utilities for calculating distances between points and centroids in clustering algorithms. These functions form the basis for both crisp and fuzzy C-means clustering.getDistanceMatrix
Calculates the distance matrix between each point and each centroid.Parameters
Array of points to calculate distances from. Each point should have
x and y coordinates.Array of centroids to calculate distances to. Each centroid should have
x and y coordinates.Returns
A matrix of distances where each element
[i][j] is the distance between the i-th centroid and the j-th point. Returns an empty array if either points or centroids is empty.Example
euclidianDistance
Calculates the Euclidean distance between two points.Parameters
First point with
x and y coordinates.Second point with
x and y coordinates.Returns
The Euclidean distance between the two points, calculated as
√((x₁ - x₂)² + (y₁ - y₂)²).Example
The Euclidean distance formula is used extensively throughout the clustering algorithms. It represents the straight-line distance between two points in 2D space.
Mathematical Formula
The Euclidean distance is calculated using the formula:AandBare two points in 2D spacexₐ, yₐare the coordinates of point Axᵦ, yᵦare the coordinates of point B