protected void findBest(int size, double[] scratch, double[] bestd, int[] besti, int j) { final int jbase = AGNES.triangleSize(j); // The distance has increased, we may no longer be the best merge. double bestdj = Double.POSITIVE_INFINITY; int bestij = -1; for(int i = 0, o = jbase; i < j; i++, o++) { if(besti[i] < 0) { continue; } if(scratch[o] < bestdj) { bestdj = scratch[o]; bestij = i; } } for(int i = j + 1, o = jbase + j + j; i < size; o += i, i++) { // assert(o == AGNES.triangleSize(i) + j); if(besti[i] < 0) { continue; } if(scratch[o] < bestdj) { bestdj = scratch[o]; bestij = i; } } bestd[j] = bestdj; besti[j] = bestij; }
/** * Initialize the NN cache. * * @param scratch Scatch space * @param bestd Best distance * @param besti Best index */ private static void initializeNNCache(double[] scratch, double[] bestd, int[] besti) { final int size = bestd.length; Arrays.fill(bestd, Double.POSITIVE_INFINITY); Arrays.fill(besti, -1); for(int x = 0, p = 0; x < size; x++) { assert(p == AGNES.triangleSize(x)); double bestdx = Double.POSITIVE_INFINITY; int bestix = -1; for(int y = 0; y < x; y++, p++) { final double v = scratch[p]; if(v < bestd[y]) { bestd[y] = v; besti[y] = x; } if(v < bestdx) { bestdx = v; bestix = y; } } bestd[x] = bestdx; besti[x] = bestix; } }
final int xbase = triangleSize(x), ybase = triangleSize(y); int jbase = triangleSize(j); for(; j < x; jbase += j++) { if(builder.isLinked(ij.seek(j))) {
continue; assert(xbase == triangleSize(ox)); for(int oy = 0; oy < ox; oy++) {
final int xbase = AGNES.triangleSize(x), ybase = AGNES.triangleSize(y); int jbase = AGNES.triangleSize(j); for(; j < x; jbase += j++) { if(builder.isLinked(ij.seek(j))) {
double[] scratch = new double[triangleSize(size)]; DBIDArrayIter ix = ids.iter(), iy = ids.iter(); boolean square = WardLinkageMethod.class.isInstance(linkage) && !(SquaredEuclideanDistanceFunction.class.isInstance(getDistanceFunction()));
double[] scratch = new double[AGNES.triangleSize(size)]; DBIDArrayIter ix = ids.iter(), iy = ids.iter();