Agglo
Fast hierarchical agglomerative clustering in Javascript
Install
npm install agglo
Usage
var levels = agglo(inputs, [options]);
inputs
An array of numbers to measure the distance between.
agglo([0, 1, 2]);
To measure multiple dimensions, use multiple arrays of numbers.
agglo([
[1, 10, 50.32],
[9, 3, 18.0]
[0, 1.5, 9.7]
]);
If you define your own distance function, your inputs can be more abstract.
agglo(db.get('users'), {
distance: measureUserDistance
});
options
Limits clustering to a maximum linkage (distance).
Default: Infinity
Note: This will likely change the number of returned levels
Specifies the linkage function to use (default: "average")
-
"average"
Merge clusters based on the average distance between items in each cluster.
-
"complete"
Merge clusters based on the largest distance between items in each cluster.
-
"single"
Merge clusters based on the smallest distance between items in each cluster.
-
function (source, target)
A custom linkage function that returns the distance between the source
cluster and the target
cluster.
The source
and target
look objects like this:
{
index: 5,
count: 2,
links: [],
linkage: 1.5,
cluster: []
}
-
distance
Specifies the function to use for measuring the distance between each input.
levels
Agglo will return an array of inputs.length - 1
levels. The first level represents the first two clusters that were merged. The last level represents the last two clusters that were merged.
[
{
linkage: 2,
source: {
index: 0,
value: [5, 13]
},
target: {
index: 2,
value: [6, 12]
},
clusters: [
[[9, 22]],
[[5, 13], [6, 12]],
...
]
},
...
]
levels.fit(regression, callback)