NearestNeighbors

public final class NearestNeighbors

Selects the k nearest centers for each point.

Rows of points are assumed to be input points. Rows of centers are assumed to be the list of candidate centers. For each point, the k centers that have least L2 distance to it are computed.

Public Methods

static NearestNeighbors
create(Scope scope, Operand<Float> points, Operand<Float> centers, Operand<Long> k)
Factory method to create a class wrapping a new NearestNeighbors operation.
Output<Float>
nearestCenterDistances()
Matrix of shape (n, min(m, k)).
Output<Long>
nearestCenterIndices()
Matrix of shape (n, min(m, k)).

Inherited Methods

Public Methods

public static NearestNeighbors create (Scope scope, Operand<Float> points, Operand<Float> centers, Operand<Long> k)

Factory method to create a class wrapping a new NearestNeighbors operation.

Parameters
scope current scope
points Matrix of shape (n, d). Rows are assumed to be input points.
centers Matrix of shape (m, d). Rows are assumed to be centers.
k Number of nearest centers to return for each point. If k is larger than m, then only m centers are returned.
Returns
  • a new instance of NearestNeighbors

public Output<Float> nearestCenterDistances ()

Matrix of shape (n, min(m, k)). Each row contains the squared L2 distance to the corresponding center in nearest_center_indices.

public Output<Long> nearestCenterIndices ()

Matrix of shape (n, min(m, k)). Each row contains the indices of the centers closest to the corresponding point, ordered by increasing distance.