Tabnine Logo
AGNES
Code IndexAdd Tabnine to your IDE (free)

How to use
AGNES
in
de.lmu.ifi.dbs.elki.algorithm.clustering.hierarchical

Best Java code snippets using de.lmu.ifi.dbs.elki.algorithm.clustering.hierarchical.AGNES (Showing top 20 results out of 315)

origin: de.lmu.ifi.dbs.elki/elki-clustering

 @Override
 protected AGNES<O> makeInstance() {
  return new AGNES<>(distanceFunction, linkage);
 }
}
origin: de.lmu.ifi.dbs.elki/elki-clustering

@Override
public TypeInformation[] getInputTypeRestriction() {
 // The input relation must match our distance function:
 return TypeUtil.array(getDistanceFunction().getInputTypeRestriction());
}
origin: de.lmu.ifi.dbs.elki/elki

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;
}
origin: elki-project/elki

DistanceQuery<O> dq = db.getDistanceQuery(relation, getDistanceFunction());
initializeDistanceMatrix(mat, dq, linkage);
 end = shrinkActiveSet(ix, builder, end, //
   findMerge(end, mat, builder));
 LOG.incrementProcessed(prog);
origin: de.lmu.ifi.dbs.elki/elki

DistanceQuery<O> dq = db.getDistanceQuery(relation, getDistanceFunction());
ArrayDBIDs ids = DBIDUtil.ensureArray(relation.getDBIDs());
final int size = ids.size();
double[] scratch = new double[triangleSize(size)];
DBIDArrayIter ix = ids.iter(), iy = ids.iter();
boolean square = WardLinkageMethod.class.isInstance(linkage) && !(SquaredEuclideanDistanceFunction.class.isInstance(getDistanceFunction()));
initializeDistanceMatrix(scratch, dq, ix, iy, square);
int wsize = size;
for(int i = 1; i < size; i++) {
 int x = findMerge(wsize, scratch, ix, iy, builder);
 if(x == wsize - 1) {
  --wsize;
origin: de.lmu.ifi.dbs.elki/elki-clustering

/**
 * Execute the cluster merge.
 *
 * @param end Active set size
 * @param mat Matrix paradigm
 * @param builder Hierarchy builder
 * @param mindist Distance that was used for merging
 * @param x First matrix position
 * @param y Second matrix position
 */
protected void merge(int end, MatrixParadigm mat, PointerHierarchyRepresentationBuilder builder, double mindist, int x, int y) {
 // Avoid allocating memory, by reusing existing iterators:
 final DBIDArrayIter ix = mat.ix.seek(x), iy = mat.iy.seek(y);
 if(LOG.isDebuggingFine()) {
  LOG.debugFine("Merging: " + DBIDUtil.toString(ix) + " -> " + DBIDUtil.toString(iy) + " " + mindist);
 }
 // Perform merge in data structure: x -> y
 assert (y < x);
 // Since y < x, prefer keeping y, dropping x.
 builder.add(ix, linkage.restore(mindist, getDistanceFunction().isSquared()), iy);
 // Update cluster size for y:
 final int sizex = builder.getSize(ix), sizey = builder.getSize(iy);
 builder.setSize(iy, sizex + sizey);
 updateMatrix(end, mat, builder, mindist, x, y, sizex, sizey);
}
origin: elki-project/elki

AGNES.initializeDistanceMatrix(mat, dq, linkage);
DBIDArrayIter ix = mat.ix;
for(int i = 1, end = size; i < size; i++) {
 end = AGNES.shrinkActiveSet(ix, builder, end, //
   findMerge(end, mat, bestd, besti, builder));
 LOG.incrementProcessed(prog);
origin: elki-project/elki

/**
 * Run the algorithm on a database.
 * 
 * @param db Database
 * @param relation Relation to process.
 * @return Hierarchical result
 */
public PointerPrototypeHierarchyRepresentationResult run(Database db, Relation<O> relation) {
 DistanceQuery<O> dq = DatabaseUtil.precomputedDistanceQuery(db, relation, getDistanceFunction(), LOG);
 final DBIDs ids = relation.getDBIDs();
 final int size = ids.size();
 // Initialize space for result:
 PointerHierarchyRepresentationBuilder builder = new PointerHierarchyRepresentationBuilder(ids, dq.getDistanceFunction().isSquared());
 Int2ObjectOpenHashMap<ModifiableDBIDs> clusters = new Int2ObjectOpenHashMap<>(size);
 // Allocate working space:
 MatrixParadigm mat = new MatrixParadigm(ids);
 ArrayModifiableDBIDs prots = DBIDUtil.newArray(MatrixParadigm.triangleSize(size));
 initializeMatrices(mat, prots, dq);
 DBIDArrayMIter protiter = prots.iter();
 FiniteProgress progress = LOG.isVerbose() ? new FiniteProgress("MiniMax clustering", size - 1, LOG) : null;
 DBIDArrayIter ix = mat.ix;
 for(int i = 1, end = size; i < size; i++) {
  end = AGNES.shrinkActiveSet(ix, builder, end, //
    findMerge(end, mat, protiter, builder, clusters, dq));
  LOG.incrementProcessed(progress);
 }
 LOG.ensureCompleted(progress);
 return (PointerPrototypeHierarchyRepresentationResult) builder.complete();
}
origin: de.lmu.ifi.dbs.elki/elki

  continue;
 assert(xbase == triangleSize(ox));
 for(int oy = 0; oy < ox; oy++) {
merge(size, scratch, ix, iy, builder, mindist, x, y);
return x;
origin: de.lmu.ifi.dbs.elki/elki

double[] scratch = new double[AGNES.triangleSize(size)];
DBIDArrayIter ix = ids.iter(), iy = ids.iter();
AGNES.initializeDistanceMatrix(scratch, dq, ix, iy, square);
origin: elki-project/elki

merge(end, mat, builder, mindist, x, y);
return x;
origin: de.lmu.ifi.dbs.elki/elki

/**
 * Execute the cluster merge.
 *
 * @param size Data set size
 * @param scratch Scratch space.
 * @param ix First iterator
 * @param iy Second iterator
 * @param builder Hierarchy builder
 * @param mindist Distance that was used for merging
 * @param x First matrix position
 * @param y Second matrix position
 */
protected void merge(int size, double[] scratch, DBIDArrayIter ix, DBIDArrayIter iy, PointerHierarchyRepresentationBuilder builder, double mindist, int x, int y) {
 // Avoid allocating memory, by reusing existing iterators:
 ix.seek(x);
 iy.seek(y);
 if(LOG.isDebuggingFine()) {
  LOG.debugFine("Merging: " + DBIDUtil.toString(ix) + " -> " + DBIDUtil.toString(iy) + " " + mindist);
 }
 // Perform merge in data structure: x -> y
 assert(y < x);
 // Since y < x, prefer keeping y, dropping x.
 builder.add(ix, mindist, iy);
 // Update cluster size for y:
 final int sizex = builder.getSize(ix), sizey = builder.getSize(iy);
 builder.setSize(iy, sizex + sizey);
 // Note: this changes iy.
 updateMatrix(size, scratch, iy, builder, mindist, x, y, sizex, sizey);
}
origin: de.lmu.ifi.dbs.elki/elki-clustering

DistanceQuery<O> dq = db.getDistanceQuery(relation, getDistanceFunction());
initializeDistanceMatrix(mat, dq, linkage);
 end = shrinkActiveSet(ix, builder, end, //
   findMerge(end, mat, builder));
 LOG.incrementProcessed(prog);
origin: elki-project/elki

/**
 * Execute the cluster merge.
 *
 * @param end Active set size
 * @param mat Matrix paradigm
 * @param builder Hierarchy builder
 * @param mindist Distance that was used for merging
 * @param x First matrix position
 * @param y Second matrix position
 */
protected void merge(int end, MatrixParadigm mat, PointerHierarchyRepresentationBuilder builder, double mindist, int x, int y) {
 // Avoid allocating memory, by reusing existing iterators:
 final DBIDArrayIter ix = mat.ix.seek(x), iy = mat.iy.seek(y);
 if(LOG.isDebuggingFine()) {
  LOG.debugFine("Merging: " + DBIDUtil.toString(ix) + " -> " + DBIDUtil.toString(iy) + " " + mindist);
 }
 // Perform merge in data structure: x -> y
 assert (y < x);
 // Since y < x, prefer keeping y, dropping x.
 builder.add(ix, linkage.restore(mindist, getDistanceFunction().isSquared()), iy);
 // Update cluster size for y:
 final int sizex = builder.getSize(ix), sizey = builder.getSize(iy);
 builder.setSize(iy, sizex + sizey);
 updateMatrix(end, mat, builder, mindist, x, y, sizex, sizey);
}
origin: de.lmu.ifi.dbs.elki/elki-clustering

AGNES.initializeDistanceMatrix(mat, dq, linkage);
DBIDArrayIter ix = mat.ix;
for(int i = 1, end = size; i < size; i++) {
 end = AGNES.shrinkActiveSet(ix, builder, end, //
   findMerge(end, mat, bestd, besti, builder));
 LOG.incrementProcessed(prog);
origin: de.lmu.ifi.dbs.elki/elki-clustering

/**
 * Run the algorithm on a database.
 * 
 * @param db Database
 * @param relation Relation to process.
 * @return Hierarchical result
 */
public PointerPrototypeHierarchyRepresentationResult run(Database db, Relation<O> relation) {
 DistanceQuery<O> dq = DatabaseUtil.precomputedDistanceQuery(db, relation, getDistanceFunction(), LOG);
 final DBIDs ids = relation.getDBIDs();
 final int size = ids.size();
 // Initialize space for result:
 PointerHierarchyRepresentationBuilder builder = new PointerHierarchyRepresentationBuilder(ids, dq.getDistanceFunction().isSquared());
 Int2ObjectOpenHashMap<ModifiableDBIDs> clusters = new Int2ObjectOpenHashMap<>(size);
 // Allocate working space:
 MatrixParadigm mat = new MatrixParadigm(ids);
 ArrayModifiableDBIDs prots = DBIDUtil.newArray(MatrixParadigm.triangleSize(size));
 initializeMatrices(mat, prots, dq);
 DBIDArrayMIter protiter = prots.iter();
 FiniteProgress progress = LOG.isVerbose() ? new FiniteProgress("MiniMax clustering", size - 1, LOG) : null;
 DBIDArrayIter ix = mat.ix;
 for(int i = 1, end = size; i < size; i++) {
  end = AGNES.shrinkActiveSet(ix, builder, end, //
    findMerge(end, mat, protiter, builder, clusters, dq));
  LOG.incrementProcessed(progress);
 }
 LOG.ensureCompleted(progress);
 return (PointerPrototypeHierarchyRepresentationResult) builder.complete();
}
origin: de.lmu.ifi.dbs.elki/elki-clustering

merge(end, mat, builder, mindist, x, y);
return x;
origin: elki-project/elki

DBIDArrayIter ix = mat.ix;
for(int i = 1, end = size; i < size; i++) {
 end = AGNES.shrinkActiveSet(ix, builder, end, //
   findMerge(end, mat, protiter, builder, clusters, bestd, besti, dq));
 LOG.incrementProcessed(prog);
origin: de.lmu.ifi.dbs.elki/elki

 @Override
 protected AGNES<O> makeInstance() {
  return new AGNES<>(distanceFunction, linkage);
 }
}
origin: elki-project/elki

@Override
public TypeInformation[] getInputTypeRestriction() {
 // The input relation must match our distance function:
 return TypeUtil.array(getDistanceFunction().getInputTypeRestriction());
}
de.lmu.ifi.dbs.elki.algorithm.clustering.hierarchicalAGNES

Javadoc

Hierarchical Agglomerative Clustering (HAC) or Agglomerative Nesting (AGNES) is a classic hierarchical clustering algorithm. Initially, each element is its own cluster; the closest clusters are merged at every step, until all the data has become a single cluster.

This is the naive O(n³) algorithm. See SLINK for a much faster algorithm (however, only for single-linkage).

This implementation uses the pointer-based representation used by SLINK, so that the extraction algorithms we have can be used with either of them.

The algorithm is believed to be first published (for single-linkage) by:

P. H. Sneath
The application of computers to taxonomy
Journal of general microbiology, 17(1).

This algorithm is also known as AGNES (Agglomerative Nesting), where the use of alternative linkage criterions is discussed:

L. Kaufman, P. J. Rousseeuw
Agglomerative Nesting (Program AGNES),
in Finding Groups in Data: An Introduction to Cluster Analysis

Reference for the unified concept:

G. N. Lance, W. T. Williams
A general theory of classificatory sorting strategies 1. Hierarchical systems
The computer journal 9.4 (1967): 373-380.

See also:

R. M. Cormack
A Review of Classification
Journal of the Royal Statistical Society. Series A, Vol. 134, No. 3

Most used methods

  • <init>
    Constructor.
  • findMerge
    Perform the next merge step in AGNES.
  • getDistanceFunction
  • initializeDistanceMatrix
    Initialize a distance matrix.
  • merge
    Execute the cluster merge.
  • updateMatrix
    Update the scratch distance matrix.
  • shrinkActiveSet
    Shrink the active set: if the last x objects are all merged, we can reduce the working size accordin
  • triangleSize
    Compute the size of a complete x by x triangle (minus diagonal)

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getResourceAsStream (ClassLoader)
  • setRequestProperty (URLConnection)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now