Exemple #1
0
  public Graph createGraph(Clustering[] clusts) {
    Clustering c = clusts[0];
    // total number of items
    int n = c.instancesCount();

    Graph graph = new AdjListGraph();
    Object2LongOpenHashMap<Instance> mapping = new Object2LongOpenHashMap();

    Instance a, b;
    Node na, nb;
    // cluster membership
    int ca, cb;
    int x = 0;
    Edge edge;
    // accumulate evidence
    for (Clustering clust : clusts) {
      System.out.println("reducing " + (x++));
      for (int i = 1; i < n; i++) {
        a = clust.instance(i);
        na = fetchNode(graph, mapping, a);
        ca = clust.assignedCluster(a.getIndex());
        for (int j = 0; j < i; j++) {
          b = clust.instance(j);
          nb = fetchNode(graph, mapping, b);
          // for each pair of instances check if placed in the same cluster
          cb = clust.assignedCluster(b.getIndex());
          if (ca == cb) {
            edge = graph.getEdge(na, nb);
            // check if exists
            if (edge == null) {
              edge = graph.getFactory().newEdge(na, nb, 0, 0, false);
              graph.addEdge(edge);
            }
            // increase weight by 1
            edge.setWeight(edge.getWeight() + 1.0);
          }
        }
      }
    }
    return graph;
  }
Exemple #2
0
 private Node createNode(Graph g, Object2LongOpenHashMap<Instance> mapping, Instance inst) {
   Node node = g.getFactory().newNode(inst);
   mapping.put(inst, node.getId());
   g.addNode(node);
   return node;
 }