private void CalculateEntries() { int size = dataPointList.Count; double distance; for (int row = 0, columnOffset = 1; row < size; row++, columnOffset++) { for (int column = columnOffset; column < size; column++) { distance = distanceMetric.Calculate(dataPointList[row], dataPointList[column]); this[row, column] = distance; this[column, row] = distance; } } }
private void AssignEachDataPointToNearestCluster(IList <Cluster> clusters) { foreach (var dataItem in dataCollection) { Cluster closestCluster = null; double minDistance = double.MaxValue; foreach (var cluster in clusters) { var centroid = cluster.Centroid; double distance = distanceMetric.Calculate(centroid, dataItem); if (distance < minDistance) { minDistance = distance; closestCluster = cluster; } } ClusterMember member = new ClusterMember(dataItem, minDistance); closestCluster.Members.Add(member); } }
public double DistanceTo(Node other) => _distanceMetric.Calculate(Coords, other.Coords);