UNPKG

clustering-tfjs

Version:

High-performance TypeScript clustering algorithms (K-Means, Spectral, Agglomerative) with TensorFlow.js acceleration and scikit-learn compatibility

52 lines 2.07 kB
import * as tf from '../tf-adapter'; /** * Converts a regular (nested) JavaScript array into a TensorFlow.js tensor * with the provided dtype (defaults to `float32`). * * The function is wrapped in `tf.tidy` to ensure that any intermediate * tensors that may be created by TensorFlow.js during conversion are * automatically disposed of. */ export declare function arrayToTensor(arr: tf.TensorLike, dtype?: tf.DataType): tf.Tensor; /** * Converts a tensor back to a JavaScript array (synchronously). * * The returned value is a *copy* of the underlying data, so further * manipulations will not affect the original tensor. */ export declare function tensorToArray(tensor: tf.Tensor): number[] | number[][] | number[][][]; /** * Computes the element-wise Euclidean (ℓ2) distance between two tensors along * their last dimension. * * Both inputs must be broadcast-compatible. The result will have the broadcast * shape of `tf.sub(a, b).sum(-1)` (i.e. the shapes minus the last dimension). * * Example: * ```ts * const a = tf.tensor([[0, 0], [1, 1]]); // (2, 2) * const b = tf.tensor([1, 0]); // (2) * euclideanDistance(a, b) // => Tensor([1, 1]) * ``` */ export declare function euclideanDistance(a: tf.Tensor, b: tf.Tensor): tf.Tensor; /** * Computes the Manhattan (ℓ1) distance between two tensors along their last * dimension. */ export declare function manhattanDistance(a: tf.Tensor, b: tf.Tensor): tf.Tensor; /** * Computes the cosine distance (1 ‑ cosine similarity) between two tensors * along their last dimension. */ export declare function cosineDistance(a: tf.Tensor, b: tf.Tensor): tf.Tensor; /** * Efficiently computes pairwise Euclidean distance matrix for a set of points * represented by a 2-D tensor of shape `(n, d)`. * * The implementation uses the well-known trick * ‖x − y‖² = ‖x‖² + ‖y‖² − 2·xᵀy with broadcasting to avoid allocating an * `(n, n, d)` intermediate tensor. */ export { pairwiseEuclideanMatrix } from './pairwise_distance'; //# sourceMappingURL=tensor.d.ts.map