FastQueue<D> dst ) fitQuality.reset(); pairs.reset(); workBuffer.reset(); fitQuality.setMaxSize(src.size); workBuffer.setMaxSize(src.size*dst.size); for( int i = 0; i < src.size; i++ ) { D a = src.data[i]; workBuffer.push(fit); fitQuality.push(bestScore);
/** * Gets the value at the index which corresponds to the specified fraction * @param fraction 0 to 1 inclusive * @return value at fraction */ public double getFraction( double fraction ) { return get( (int)((size-1)*fraction) ); }
@Override public GrowQueue_F64 copy() { GrowQueue_F64 ret = new GrowQueue_F64(size); ret.setTo(this); return ret; }
/** * Randomly selects the next seed. The chance of a seed is based upon its distance * from the closest cluster. Larger distances mean more likely. * @param points List of all the points * @param target Number from 0 to 1, inclusive * @return Index of the selected seed */ protected final double[] selectNextSeed( List<double[]> points , double target ) { // this won't select previously selected points because the distance will be zero // If the distance is zero it will simply skip over it double sum = 0; for (int i = 0; i < distance.size(); i++) { sum += distance.get(i); double fraction = sum/totalDistance; if( fraction >= target ) return points.get(i); } throw new RuntimeException("This shouldn't happen"); }
optional = new GrowQueue_F64(); optional.reset(); double centerX = circle.center.x = sumX/(double)N; double centerY = circle.center.y = sumY/(double)N; optional.push(r); meanR += r; double diff = optional.get(i)-meanR; variance += diff*diff;
@Test public void addAll_queue() { GrowQueue_F64 queue0 = new GrowQueue_F64(2); GrowQueue_F64 queue1 = new GrowQueue_F64(3); queue0.add(1); queue0.add(2); queue1.add(3); queue1.add(4); queue1.add(5); assertEquals(2,queue0.size); queue0.addAll(queue1); assertEquals(5,queue0.size); for( int i = 0; i < queue0.size; i++ ) { assertEquals(queue0.get(i),i+1,1e-8); } queue0.reset(); queue0.addAll(queue1); assertEquals(3,queue0.size); for( int i = 0; i < queue0.size; i++ ) { assertEquals(queue0.get(i),i+3,1e-8); } }
@Override public void findNearest(P point, double maxDistance, int numNeighbors, FastQueue<NnData<P>> results) { results.reset(); if( maxDistance < 0 ) maxDistance = Double.MAX_VALUE; outputIndex.reset(); outputDistance.reset(); alg.findClosestN(point,maxDistance,numNeighbors,outputIndex,outputDistance); for( int i = 0; i < outputIndex.size; i++ ) { int index = outputIndex.get(i); NnData<P> r = results.grow(); r.distance = outputDistance.get(i); r.point = points.get(index); r.index = index; } } }
@Test public void auto_grow() { GrowQueue_F64 alg = new GrowQueue_F64(3); assertEquals(3,alg.data.length); for( int i = 0; i < 10; i++ ) alg.push(i); assertEquals(10,alg.size); for( int i = 0; i < 10; i++ ) assertEquals(i,alg.get(i),1e-8); }
@Override protected void handleDetection(ScalePoint p) { // adjust the image for the down sampling in each octave double localX = p.x / pixelScaleToInput; double localY = p.y / pixelScaleToInput; double localSigma = p.scale / pixelScaleToInput; // find potential orientations first orientation.process(localX,localY,localSigma); // describe each feature GrowQueue_F64 angles = orientation.getOrientations(); for (int i = 0; i < angles.size; i++) { BrightFeature feature = features.grow(); feature.white = p.white; describe.process(localX,localY,localSigma,angles.get(i),feature); orientations.add(angles.get(i)); locations.add(p); } }
@Test public void updateDistances() { InitializePlusPlus alg = new InitializePlusPlus(); alg.init(1,123); alg.distance.resize(3); alg.distance.data = new double[]{3,6,1}; List<double[]> points = new ArrayList<double[]>(); for (int i = 0; i < 3; i++) { points.add(new double[]{i*i}); } alg.updateDistances(points, new double[]{-1}); assertEquals(1,alg.distance.get(0),1e-8); assertEquals(4,alg.distance.get(1),1e-8); assertEquals(1,alg.distance.get(2),1e-8); assertEquals(6,alg.totalDistance,1e-8); }
@Override public void selectSeeds(List<double[]> points, List<double[]> seeds) { if( seeds.size() > points.size() ) throw new IllegalArgumentException("More seeds requested than points!"); distance.resize(points.size()); // the first seed is randomly selected from the list of points double[] seed = points.get( rand.nextInt(points.size()) ); copyInto(seed,seeds.get(0)); // compute the distance each points is from the seed totalDistance = 0; for (int i = 0; i < points.size(); i++) { double[] p = points.get(i); double d = StandardKMeans_F64.distanceSq(p,seed); distance.data[i] = d; totalDistance += d; } // iteratively select the next seed and update the list of point distances for (int i = 1; i < seeds.size(); i++) { if( totalDistance == 0 ) { // if the total distance is zero that means there are duplicate points and that // all the unique points have already been added as seeds. just select a point // and copy it into rest of the seeds copyInto(seed, seeds.get(i)); } else { double target = rand.nextDouble(); copyInto(selectNextSeed(points, target), seeds.get(i)); updateDistances(points, seeds.get(i)); } } }
GrowQueue_F64 outputDistance = new GrowQueue_F64(); outputDistance.reset(); exhaustive.findClosestN(where, 10.0, numNeighbors, outputIndex,outputDistance);