예제 #1
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;
  }
  private boolean quartetVanishes(Set<Integer> quartet) {
    if (quartet.size() != 4)
      throw new IllegalArgumentException("Expecting a quartet, size = " + quartet.size());

    Iterator<Integer> iter = quartet.iterator();
    int x = iter.next();
    int y = iter.next();
    int z = iter.next();
    int w = iter.next();

    return testVanishing(x, y, z, w);
  }
예제 #3
0
파일: Knowledge2.java 프로젝트: ps7z/tetrad
  /** Iterator over the KnowledgeEdge's representing required edges. */
  public final Iterator<KnowledgeEdge> requiredEdgesIterator() {
    Set<KnowledgeEdge> edges = new HashSet<>();

    for (OrderedPair<Set<MyNode>> o : requiredRulesSpecs) {
      final Set<MyNode> first = o.getFirst();
      for (MyNode s1 : first) {
        final Set<MyNode> second = o.getSecond();
        for (MyNode s2 : second) {
          if (!s1.equals(s2)) {
            edges.add(new KnowledgeEdge(s1.getName(), s2.getName()));
          }
        }
      }
    }

    return edges.iterator();
  }
예제 #4
0
파일: Knowledge2.java 프로젝트: ps7z/tetrad
  /** Iterator over the knowledge's explicitly forbidden edges. */
  public final Iterator<KnowledgeEdge> explicitlyForbiddenEdgesIterator() {
    Set<OrderedPair<Set<MyNode>>> copy = new HashSet<>(forbiddenRulesSpecs);
    copy.removeAll(forbiddenTierRules());

    for (KnowledgeGroup group : knowledgeGroups) {
      copy.remove(knowledgeGroupRules.get(group));
    }

    Set<KnowledgeEdge> edges = new HashSet<>();

    for (OrderedPair<Set<MyNode>> o : copy) {
      final Set<MyNode> first = o.getFirst();
      for (MyNode s1 : first) {
        final Set<MyNode> second = o.getSecond();
        for (MyNode s2 : second) {
          edges.add(new KnowledgeEdge(s1.getName(), s2.getName()));
        }
      }
    }

    return edges.iterator();
  }