@Override public int[][] assign(short[][] data) { int [][] indices = new int [data.length][numNeighbours]; float [][] distances = new float [data.length][numNeighbours]; nn.searchKNN(data, numNeighbours, indices, distances); return indices; }
@Override public void assignWeighted(short[][] data, int[][] assignments, float[][] weights) { nn.searchKNN(data, numNeighbours, assignments, weights); }
@Override public IndependentPair<int[], float[]> assignWeighted(short[] data) { int [][] indices = new int [data.length][numNeighbours]; float [][] distances = new float [data.length][numNeighbours]; nn.searchKNN(new short[][] { data }, numNeighbours, indices, distances); return new IndependentPair<int[], float[]>(indices[0], distances[0]); }
final int[][] idx = new int[1][K]; final float[][] dst = new float[1][K]; nn.searchKNN(qus, K, idx, dst);
final int[][] idx = new int[1][K]; final float[][] dst = new float[1][K]; nn.searchKNN(qus, K, idx, dst);
protected void computeDistances(short[] fullQuery, BoundedPriorityQueue<IntFloatPair> queue, IntFloatPair wp) { final float[][] distances = new float[pq.assigners.length][]; for (int j = 0, from = 0; j < this.pq.assigners.length; j++) { final ShortNearestNeighbours nn = this.pq.assigners[j]; final int to = nn.numDimensions(); final int K = nn.size(); final short[][] qus = { Arrays.copyOfRange(fullQuery, from, from + to) }; final int[][] idx = new int[1][K]; final float[][] dst = new float[1][K]; nn.searchKNN(qus, K, idx, dst); distances[j] = new float[K]; for (int k = 0; k < K; k++) { distances[j][idx[0][k]] = dst[0][k]; } from += to; } for (int i = 0; i < data.length; i++) { wp.first = i; wp.second = 0; for (int j = 0; j < this.pq.assigners.length; j++) { final int centroid = this.data[i][j] + 128; wp.second += distances[j][centroid]; } wp = queue.offerItem(wp); } }
protected void computeDistances(short[] fullQuery, BoundedPriorityQueue<IntFloatPair> queue, IntFloatPair wp) { final float[][] distances = new float[pq.assigners.length][]; for (int j = 0, from = 0; j < this.pq.assigners.length; j++) { final ShortNearestNeighbours nn = this.pq.assigners[j]; final int to = nn.numDimensions(); final int K = nn.size(); final short[][] qus = { Arrays.copyOfRange(fullQuery, from, from + to) }; final int[][] idx = new int[1][K]; final float[][] dst = new float[1][K]; nn.searchKNN(qus, K, idx, dst); distances[j] = new float[K]; for (int k = 0; k < K; k++) { distances[j][idx[0][k]] = dst[0][k]; } from += to; } for (int i = 0; i < data.length; i++) { wp.first = i; wp.second = 0; for (int j = 0; j < this.pq.assigners.length; j++) { final int centroid = this.data[i][j] + 128; wp.second += distances[j][centroid]; } wp = queue.offerItem(wp); } }