/** * Construct the assigner using the given cluster data. * * @param data the cluster data */ public KDTreeDoubleEuclideanAssigner(double[][] data) { nn = new DoubleNearestNeighboursKDTree(data, DoubleNearestNeighboursKDTree.DEFAULT_NTREES, DoubleNearestNeighboursKDTree.DEFAULT_NCHECKS); }
@Override public DoubleNearestNeighboursKDTree create(double[][] data) { return new DoubleNearestNeighboursKDTree(data, ntrees, nchecks); } }
@Override public DoubleNearestNeighboursKDTree create(double[][] data) { return new DoubleNearestNeighboursKDTree(data, ntrees, nchecks); } }
/** * Construct the assigner using the given cluster data. The assigner * is backed by either a {@link DoubleNearestNeighboursExact} or * {@link DoubleNearestNeighboursKDTree}, depending on whether the exact * parameter is true or false. If the parameter is true, then the * resultant {@link DoubleNearestNeighboursExact} 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 DoubleKNNAssigner(double[][] data, boolean exact, int numNeighbours) { this.numNeighbours = numNeighbours; if (exact) { nn = new DoubleNearestNeighboursExact(data); } else { nn = new DoubleNearestNeighboursKDTree(data, DoubleNearestNeighboursKDTree.DEFAULT_NTREES, DoubleNearestNeighboursKDTree.DEFAULT_NCHECKS); } }
/** * Constructor that takes the two categories to classify between, * an input stream that points to a training set file and the size * of that training set. * * @param cat1 The first classification category * @param cat2 The second classification category * @param trainingSet The training set * @param trainingSetSize The size of the training set */ public CityLandscapeTree( String cat1, String cat2, InputStream trainingSet, int trainingSetSize ) { this( cat1, cat2 ); try { // Load the given training set double[][] train = loadTrainingSet( trainingSet, trainingSetSize ); // Construct DoubleNearestNeighbours Object dnn = new DoubleNearestNeighboursKDTree( train, NTREES, NCHECKS ); } catch( IOException e ) { e.printStackTrace(); } }
/** * Construct the assigner using the given cluster data. * * @param provider the cluster data provider */ public KDTreeDoubleEuclideanAssigner(CentroidsProvider<double[]> provider) { if (provider instanceof DoubleNearestNeighboursProvider) { DoubleNearestNeighbours internal = ((DoubleNearestNeighboursProvider)provider).getNearestNeighbours(); if (internal != null && internal instanceof DoubleNearestNeighboursKDTree) { nn = (DoubleNearestNeighboursKDTree) internal; return; } } nn = new DoubleNearestNeighboursKDTree(provider.getCentroids(), DoubleNearestNeighboursKDTree.DEFAULT_NTREES, DoubleNearestNeighboursKDTree.DEFAULT_NCHECKS); }
/** * Train the classifier by generating a bunch of random training examples * of characters in various fonts (using the {@link FontSimulator}) * and using the features extracted from those images, train a nearest * neighbour classifier. */ public void train() { // Create the FontSimListener that receives images from the FontSimulator ImageTrainer it = new ImageTrainer( (endChar-startChar)*nExamplesPerClass); System.out.println( "Created vector of length "+ ((endChar-startChar)*nExamplesPerClass) ); System.out.println( "Creating character data" ); // For each of the characters produce nExamplesPerCase training examples for( int i = startChar; i < endChar; i++ ) { FontSimulator<Float, FImage> fs = new FontSimulator<Float,FImage>( Character.toString( (char)i ) ); fs.setFontPointSize( 48 ); fs.makeRuns( nExamplesPerClass, it, new FImage(1,1) ); } // Train the classifier System.out.println( "\nCreating KDTree..."); nn = new DoubleNearestNeighboursKDTree( it.getVector(), NTREES, NCHECKS ); }
/** * Construct the assigner using the given cluster data. The assigner * is backed by either a {@link DoubleNearestNeighboursExact} or * {@link DoubleNearestNeighboursKDTree}, depending on whether the exact * parameter is true or false. If the parameter is true, then the * resultant {@link DoubleNearestNeighboursExact} 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 DoubleKNNAssigner(CentroidsProvider<double[]> provider, boolean exact, int numNeighbours) { this.numNeighbours = numNeighbours; if (exact) { nn = new DoubleNearestNeighboursExact(provider.getCentroids()); } else { if (provider instanceof DoubleNearestNeighboursProvider) { DoubleNearestNeighbours internal = ((DoubleNearestNeighboursProvider)provider).getNearestNeighbours(); if (internal != null && internal instanceof DoubleNearestNeighboursKDTree) { nn = (DoubleNearestNeighboursKDTree) internal; return; } } nn = new DoubleNearestNeighboursKDTree(provider.getCentroids(), DoubleNearestNeighboursKDTree.DEFAULT_NTREES, DoubleNearestNeighboursKDTree.DEFAULT_NCHECKS); } }