Ejemplo n.º 1
0
 public void drawCluster(Cluster cluster) {
   int index = clusters.indexOf(cluster);
   if (index != -1) {
     cluster.y = maxY;
     cluster.x = minX + index * factor;
     if (cluster.size() > 1) g.setColor(Color.RED);
     else g.setColor(Color.BLACK);
     g.drawRect(cluster.x - 1, cluster.y - cluster.size(), 2, 1 + cluster.size());
   } else {
     Cluster left = cluster.getLeft();
     Cluster right = cluster.getRight();
     drawCluster(left);
     drawCluster(right);
     int yBar = minY + (int) ((maxY - minY) * (cluster.getSimilarity() / threshold));
     g.setColor(Color.DARK_GRAY);
     if (left.y > yBar) {
       g.drawLine(left.x, left.y - 1, left.x, yBar);
       writeMap(left, yBar);
     }
     if (right.y > yBar) {
       g.drawLine(right.x, right.y - 1, right.x, yBar);
       writeMap(right, yBar);
     }
     g.setColor(Color.BLACK);
     g.drawLine(left.x, yBar, right.x, yBar);
     cluster.x = (right.x + left.x) / 2;
     cluster.y = yBar;
   }
 }
Ejemplo n.º 2
0
  private ArrayList<Cluster> getClusters(Cluster clustering, float threshold) {
    ArrayList<Cluster> clusters = new ArrayList<Cluster>();

    // First determine the clusters
    Stack<Cluster> stack = new Stack<Cluster>();
    stack.push(clustering);
    while (!stack.empty()) {
      Cluster current = stack.pop();

      if (current.size() == 1) {
        clusters.add(current); // singleton clusters
      } else {
        if (current.getSimilarity() >= threshold) {
          clusters.add(current);
        } else {
          // current.size() != 1   !!!
          stack.push(current.getLeft());
          stack.push(current.getRight());
        }
      }
    }
    return clusters;
  }