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