Example #1
0
  private double scoreGraphChange(Node y, Set<Node> parents1, Set<Node> parents2) {
    int yIndex = hashIndices.get(y);

    double score1, score2;

    int[] parentIndices1 = new int[parents1.size()];

    int count = -1;
    for (Node parent : parents1) {
      parentIndices1[++count] = hashIndices.get(parent);
    }

    if (isDiscrete()) {
      score1 = localDiscreteScore(yIndex, parentIndices1);
    } else {
      score1 = localSemScore(yIndex, parentIndices1);
    }

    int[] parentIndices2 = new int[parents2.size()];

    int count2 = -1;
    for (Node parent : parents2) {
      parentIndices2[++count2] = hashIndices.get(parent);
    }

    if (isDiscrete()) {
      score2 = localDiscreteScore(yIndex, parentIndices2);
    } else {
      score2 = localSemScore(yIndex, parentIndices2);
    }

    return score1 - score2;
  }
Example #2
0
  // ===========================SCORING METHODS===================//
  public double scoreDag(Graph graph) {
    Graph dag = new EdgeListGraphSingleConnections(graph);
    buildIndexing(graph);

    double score = 0.0;

    for (Node y : dag.getNodes()) {
      Set<Node> parents = new HashSet<Node>(dag.getParents(y));
      int nextIndex = -1;
      for (int i = 0; i < getVariables().size(); i++) {
        nextIndex = hashIndices.get(variables.get(i));
      }
      int parentIndices[] = new int[parents.size()];
      Iterator<Node> pi = parents.iterator();
      int count = 0;
      while (pi.hasNext()) {
        Node nextParent = pi.next();
        parentIndices[count++] = hashIndices.get(nextParent);
      }

      if (this.isDiscrete()) {
        score += localDiscreteScore(nextIndex, parentIndices);
      } else {
        score += localSemScore(nextIndex, parentIndices);
      }
    }
    return score;
  }