/** * Construct the assigner using the given cluster data. * * @param data the cluster data */ public KDTreeFloatEuclideanAssigner(float[][] data) { nn = new FloatNearestNeighboursKDTree(data, FloatNearestNeighboursKDTree.DEFAULT_NTREES, FloatNearestNeighboursKDTree.DEFAULT_NCHECKS); }
@Override public int numDimensions() { return nn.numDimensions(); } }
@Override public int[] assign(float[][] data) { int [] argmins = new int [data.length]; float [] mins = new float [data.length]; nn.searchNN(data, argmins, mins); return argmins; }
@Override public int size() { return nn.size(); }
@Override public FloatNearestNeighboursKDTree create(float[][] data) { return new FloatNearestNeighboursKDTree(data, ntrees, nchecks); } }
@Override public void assignDistance(float[][] data, int[] indices, float[] distances) { nn.searchNN(data, indices, distances); }
@Override public FloatNearestNeighboursKDTree create(float[][] data) { return new FloatNearestNeighboursKDTree(data, ntrees, nchecks); } }
@Override public IntFloatPair assignDistance(float[] data) { int [] index = new int [1]; float [] distance = new float [1]; nn.searchNN(new float[][] { data }, index, distance); return new IntFloatPair(index[0], distance[0]); }
/** * Construct the assigner using the given cluster data. The assigner * is backed by either a {@link FloatNearestNeighboursExact} or * {@link FloatNearestNeighboursKDTree}, depending on whether the exact * parameter is true or false. If the parameter is true, then the * resultant {@link FloatNearestNeighboursExact} 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 FloatKNNAssigner(float[][] data, boolean exact, int numNeighbours) { this.numNeighbours = numNeighbours; if (exact) { nn = new FloatNearestNeighboursExact(data); } else { nn = new FloatNearestNeighboursKDTree(data, FloatNearestNeighboursKDTree.DEFAULT_NTREES, FloatNearestNeighboursKDTree.DEFAULT_NCHECKS); } }
/** * Construct the assigner using the given cluster data. * * @param provider the cluster data provider */ public KDTreeFloatEuclideanAssigner(CentroidsProvider<float[]> provider) { if (provider instanceof FloatNearestNeighboursProvider) { FloatNearestNeighbours internal = ((FloatNearestNeighboursProvider)provider).getNearestNeighbours(); if (internal != null && internal instanceof FloatNearestNeighboursKDTree) { nn = (FloatNearestNeighboursKDTree) internal; return; } } nn = new FloatNearestNeighboursKDTree(provider.getCentroids(), FloatNearestNeighboursKDTree.DEFAULT_NTREES, FloatNearestNeighboursKDTree.DEFAULT_NCHECKS); }
/** * Construct the assigner using the given cluster data. The assigner * is backed by either a {@link FloatNearestNeighboursExact} or * {@link FloatNearestNeighboursKDTree}, depending on whether the exact * parameter is true or false. If the parameter is true, then the * resultant {@link FloatNearestNeighboursExact} 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 FloatKNNAssigner(CentroidsProvider<float[]> provider, boolean exact, int numNeighbours) { this.numNeighbours = numNeighbours; if (exact) { nn = new FloatNearestNeighboursExact(provider.getCentroids()); } else { if (provider instanceof FloatNearestNeighboursProvider) { FloatNearestNeighbours internal = ((FloatNearestNeighboursProvider)provider).getNearestNeighbours(); if (internal != null && internal instanceof FloatNearestNeighboursKDTree) { nn = (FloatNearestNeighboursKDTree) internal; return; } } nn = new FloatNearestNeighboursKDTree(provider.getCentroids(), FloatNearestNeighboursKDTree.DEFAULT_NTREES, FloatNearestNeighboursKDTree.DEFAULT_NCHECKS); } }