(vectors: number[][])
| 19 | } |
| 20 | |
| 21 | function 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 | |
| 38 | function normalizedLaplacian(affinity: Matrix): Matrix { |
| 39 | const n = affinity.rows; |
no test coverage detected