clustering-tfjs
Version:
High-performance TypeScript clustering algorithms (K-Means, Spectral, Agglomerative) with TensorFlow.js acceleration and scikit-learn compatibility
40 lines • 1.67 kB
TypeScript
import * as tf from '../tf-adapter';
/**
* Computes the RBF (Gaussian) kernel affinity matrix for the given points.
*
* A[i, j] = exp(-gamma * ||x_i - x_j||^2)
*
* • The diagonal is guaranteed to be exactly 1 (because the distance is 0).
* • The result is symmetric by construction.
*
* The function is wrapped in `tf.tidy` so that all intermediate tensors are
* automatically disposed of once the result tensor has been returned.
*/
export declare function compute_rbf_affinity(points: tf.Tensor2D, gamma?: number): tf.Tensor2D;
/**
* Builds a (k-)nearest-neighbour adjacency / affinity matrix.
*
* For each sample the `k` closest neighbours are connected with affinity
* value **1**. Self-loops are included to ensure connectivity, matching
* sklearn's behavior. The final matrix is **symmetrised** via `max(A, Aᵀ)`
* so that an edge is present when either sample appears in the other's
* neighbourhood.
*
* The result is returned as a dense `tf.Tensor2D` containing zeros for
* non-connected pairs. While a sparse representation would be more memory
* efficient, downstream TensorFlow.js ops (e.g. eigen-decomposition) currently
* expect dense tensors.
*/
export declare function compute_knn_affinity(points: tf.Tensor2D, k: number, includeSelf?: boolean): tf.Tensor2D;
/**
* Convenience wrapper that dispatches to the appropriate affinity builder
* based on the provided `affinity` option.
*/
export declare function compute_affinity_matrix(points: tf.Tensor2D, options: {
affinity: 'rbf';
gamma?: number;
} | {
affinity: 'nearest_neighbors';
nNeighbors: number;
}): tf.Tensor2D;
//# sourceMappingURL=affinity.d.ts.map