k-medoids
Version:
Implementation of the k-mediods clustering algorithm
14 lines (13 loc) • 433 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.distance = (a, b) => {
if (a.length !== b.length) {
throw new Error("the inputs must have the same dimension");
}
const sumOfSqrsOfDistances = Array.from(a.keys())
.map((i) => {
return Math.pow(Math.abs(a[i] - b[i]), 2);
})
.reduce((j, k) => j + k, 0);
return Math.sqrt(sumOfSqrsOfDistances);
};