예제 #1
0
  @Override
  protected void originateCommunity(Node node) {
    super.originateCommunity(node);

    // Correct the original community score for the Leung algorithm
    node.setAttribute(marker + ".score", 1.0);
  }
예제 #2
0
  @Override
  public void computeNode(Node node) {
    /*
     * Recall and update the node current community and previous score
     */
    Object previousCommunity = node.getAttribute(marker);
    Double previousScore = (Double) node.getAttribute(marker + ".score");
    super.computeNode(node);

    /*
     * Update the node label score
     */

    // Handle first iteration
    if (previousCommunity == null) {
      previousCommunity = node.getAttribute(marker);
      previousScore = (Double) node.getAttribute(marker + ".score");
    }

    /*
     * The node is the originator of the community and hasn't changed
     * community at this iteration (or we are at the first simulation step):
     * keep the maximum label score
     */
    if ((node.getAttribute(marker).equals(previousCommunity)) && (previousScore.equals(1.0)))
      node.setAttribute(marker + ".score", 1.0);

    /*
     * Otherwise search for the highest score amongst neighbors and reduce
     * it by decreasing factor
     */
    else {
      Double maxLabelScore = Double.NEGATIVE_INFINITY;
      for (Edge e : node.getEnteringEdgeSet()) {
        Node v = e.getOpposite(node);
        if (v.hasAttribute(marker) && v.getAttribute(marker).equals(node.getAttribute(marker))) {
          if ((Double) v.getAttribute(marker + ".score") > maxLabelScore)
            maxLabelScore = (Double) v.getAttribute(marker + ".score");
        }
      }
      node.setAttribute(marker + ".score", maxLabelScore - delta);
    }
  }