@Override public LongNearestNeighboursKDTree create(long[][] data) { return new LongNearestNeighboursKDTree(data, ntrees, nchecks); } }
@Override public int numDimensions() { return nn.numDimensions(); } }
@Override public int[] assign(long[][] data) { int [] argmins = new int [data.length]; double [] mins = new double [data.length]; nn.searchNN(data, argmins, mins); return argmins; }
@Override public int size() { return nn.size(); }
@Override public LongNearestNeighboursKDTree create(long[][] data) { return new LongNearestNeighboursKDTree(data, ntrees, nchecks); } }
@Override public void assignDistance(long[][] data, int[] indices, double[] distances) { nn.searchNN(data, indices, distances); }
/** * Construct the assigner using the given cluster data. * * @param data the cluster data */ public KDTreeLongEuclideanAssigner(long[][] data) { nn = new LongNearestNeighboursKDTree(data, LongNearestNeighboursKDTree.DEFAULT_NTREES, LongNearestNeighboursKDTree.DEFAULT_NCHECKS); }
@Override public IntDoublePair assignDistance(long[] data) { int [] index = new int [1]; double [] distance = new double [1]; nn.searchNN(new long[][] { data }, index, distance); return new IntDoublePair(index[0], distance[0]); }
/** * Construct the assigner using the given cluster data. The assigner * is backed by either a {@link LongNearestNeighboursExact} or * {@link LongNearestNeighboursKDTree}, depending on whether the exact * parameter is true or false. If the parameter is true, then the * resultant {@link LongNearestNeighboursExact} will use Euclidean * distance. * * @param data the cluster data * @param exact if true, then use exact mode; false implies approximate mode. * @param numNeighbours the number of nearest neighbours to select. */ public LongKNNAssigner(long[][] data, boolean exact, int numNeighbours) { this.numNeighbours = numNeighbours; if (exact) { nn = new LongNearestNeighboursExact(data); } else { nn = new LongNearestNeighboursKDTree(data, LongNearestNeighboursKDTree.DEFAULT_NTREES, LongNearestNeighboursKDTree.DEFAULT_NCHECKS); } }
/** * Construct the assigner using the given cluster data. * * @param provider the cluster data provider */ public KDTreeLongEuclideanAssigner(CentroidsProvider<long[]> provider) { if (provider instanceof LongNearestNeighboursProvider) { LongNearestNeighbours internal = ((LongNearestNeighboursProvider)provider).getNearestNeighbours(); if (internal != null && internal instanceof LongNearestNeighboursKDTree) { nn = (LongNearestNeighboursKDTree) internal; return; } } nn = new LongNearestNeighboursKDTree(provider.getCentroids(), LongNearestNeighboursKDTree.DEFAULT_NTREES, LongNearestNeighboursKDTree.DEFAULT_NCHECKS); }
/** * Construct the assigner using the given cluster data. The assigner * is backed by either a {@link LongNearestNeighboursExact} or * {@link LongNearestNeighboursKDTree}, depending on whether the exact * parameter is true or false. If the parameter is true, then the * resultant {@link LongNearestNeighboursExact} will use Euclidean * distance. * * @param provider the cluster data provider * @param exact if true, then use exact mode; false implies approximate mode. * @param numNeighbours the number of nearest neighbours to select. */ public LongKNNAssigner(CentroidsProvider<long[]> provider, boolean exact, int numNeighbours) { this.numNeighbours = numNeighbours; if (exact) { nn = new LongNearestNeighboursExact(provider.getCentroids()); } else { if (provider instanceof LongNearestNeighboursProvider) { LongNearestNeighbours internal = ((LongNearestNeighboursProvider)provider).getNearestNeighbours(); if (internal != null && internal instanceof LongNearestNeighboursKDTree) { nn = (LongNearestNeighboursKDTree) internal; return; } } nn = new LongNearestNeighboursKDTree(provider.getCentroids(), LongNearestNeighboursKDTree.DEFAULT_NTREES, LongNearestNeighboursKDTree.DEFAULT_NCHECKS); } }