Exemplo n.º 1
0
 /**
  * Resets the values of clusters that have been merged.
  *
  * @param clustering
  * @param i
  * @param j
  */
 protected void updateScoreMatrix(Clustering clustering, int i, int j) {
   int size = clustering.getNumInstances();
   int[] ci = clustering.getIndicesWithLabel(i);
   for (int ni = 0; ni < ci.length; ni++) {
     for (int nj = 0; nj < size; nj++) if (ci[ni] != nj) scoreCache.set(ci[ni], nj, 0.0);
   }
   int[] cj = clustering.getIndicesWithLabel(j);
   for (int ni = 0; ni < cj.length; ni++) {
     for (int nj = 0; nj < size; nj++) if (cj[ni] != nj) scoreCache.set(cj[ni], nj, 0.0);
   }
 }
Exemplo n.º 2
0
  /**
   * @param clustering
   * @param i
   * @param j
   * @return The score for merging these two clusters.
   */
  protected double getScore(Clustering clustering, int i, int j) {
    if (scoreCache == null) scoreCache = new PairwiseMatrix(clustering.getNumInstances());

    int[] ci = clustering.getIndicesWithLabel(i);
    int[] cj = clustering.getIndicesWithLabel(j);
    if (scoreCache.get(ci[0], cj[0]) == 0.0) {
      double val =
          evaluator.evaluate(
              new AgglomerativeNeighbor(
                  clustering, ClusterUtils.copyAndMergeClusters(clustering, i, j), ci, cj));
      for (int ni = 0; ni < ci.length; ni++)
        for (int nj = 0; nj < cj.length; nj++) scoreCache.set(ci[ni], cj[nj], val);
    }

    return scoreCache.get(ci[0], cj[0]);
  }