-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
53 lines (46 loc) · 1.39 KB
/
example.js
File metadata and controls
53 lines (46 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Import the clustering algorithm class and additional utilites.
*/
const { DBSCAN, util } = require("../build/api");
/**
* Obtain the data that is ought to be cluster.
*/
const DATA = require("./example.data.json");
/**
* Since the data is given as (vector, entity) tuples, preprocess
* by vector data map utility class.
*/
const dataMap = new util.VectorDataMap(DATA);
/**
* Define the clustering instance on the preprocessed vectors.
*/
const clustering = new DBSCAN(dataMap.vectors, 50, 4);
/**
* Below is a vector that is focused for further insights.
*/
const focusVector = [ 646.04912, 258.00177 ];
/**
* Print the clustering results, including to a supplementary
* noise cluster (as the example uses DBSCAN).
*/
console.log("Clusters, Noise:");
console.log(clustering.clusters);
console.log(clustering.noise);
/**
* Print the clustering quality according to the Silhouette
* coefficient computed through the respectively accessible quality
* helper utility.
*/
console.log(`\nQuality (Silhouette Coefficient): ${
util.Quality.silhouetteCoefficient(clustering.clusters)
}`);
/**
* Print specific information about the focused vector. Precisely, it
* is the associated entity ID, as well as the index of the cluster it
* was assigned to.
*/
console.log(`\nFocus: ${
dataMap.getEntity(focusVector)?.id
} | Cluster: ${
dataMap.getCluster(clustering.clusters, focusVector)
}`);