MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / buildAffinityMatrix

Function buildAffinityMatrix

src/core/clustering.ts:21–36  ·  view source on GitHub ↗
(vectors: number[][])

Source from the content-addressed store, hash-verified

19}
20
21function buildAffinityMatrix(vectors: number[][]): Matrix {
22 const n = vectors.length;
23 const data = new Array(n);
24 for (let i = 0; i < n; i++) {
25 data[i] = new Array(n);
26 data[i][i] = 0;
27 for (let j = i + 1; j < n; j++) {
28 const sim = Math.max(0, cosine(vectors[i], vectors[j]));
29 data[i][j] = sim;
30 }
31 for (let j = 0; j < i; j++) {
32 data[i][j] = data[j][i];
33 }
34 }
35 return new Matrix(data);
36}
37
38function normalizedLaplacian(affinity: Matrix): Matrix {
39 const n = affinity.rows;

Callers 1

spectralClusterFunction · 0.85

Calls 1

cosineFunction · 0.70

Tested by

no test coverage detected