コード例 #1
0
ファイル: PcMax.java プロジェクト: renjiey/tetrad
 public static boolean isArrowpointAllowed(Object from, Object to, IKnowledge knowledge) {
   if (knowledge == null) {
     return true;
   }
   return !knowledge.isRequired(to.toString(), from.toString())
       && !knowledge.isForbidden(from.toString(), to.toString());
 }
コード例 #2
0
ファイル: Rfci.java プロジェクト: ajsedgewick/tetrad
  /**
   * Helper method. Appears to check if an arrowpoint is permitted by background knowledge.
   *
   * @param x The possible other node.
   * @param y The possible point node.
   * @return Whether the arrowpoint is allowed.
   */
  private boolean isArrowpointAllowed(Node x, Node y) {
    if (graph.getEndpoint(x, y) == Endpoint.ARROW) {
      return true;
    }

    if (graph.getEndpoint(x, y) == Endpoint.TAIL) {
      return false;
    }

    if (graph.getEndpoint(y, x) == Endpoint.ARROW) {
      if (!knowledge.isForbidden(x.getName(), y.getName())) return true;
    }

    if (graph.getEndpoint(y, x) == Endpoint.TAIL) {
      if (!knowledge.isForbidden(x.getName(), y.getName())) return true;
    }

    return graph.getEndpoint(y, x) == Endpoint.CIRCLE;
  }
コード例 #3
0
ファイル: GesConcurrent.java プロジェクト: renjiey/tetrad
  private void addRequiredEdges(Graph graph) {
    if (true) return;
    if (knowledgeEmpty()) return;

    for (Iterator<KnowledgeEdge> it = getKnowledge().requiredEdgesIterator(); it.hasNext(); ) {
      KnowledgeEdge next = it.next();

      Node nodeA = graph.getNode(next.getFrom());
      Node nodeB = graph.getNode(next.getTo());

      if (!graph.isAncestorOf(nodeB, nodeA)) {
        graph.removeEdges(nodeA, nodeB);
        graph.addDirectedEdge(nodeA, nodeB);
        TetradLogger.getInstance()
            .log("insertedEdges", "Adding edge by knowledge: " + graph.getEdge(nodeA, nodeB));
      }
    }
    for (Edge edge : graph.getEdges()) {
      final String A = edge.getNode1().getName();
      final String B = edge.getNode2().getName();

      if (knowledge.isForbidden(A, B)) {
        Node nodeA = edge.getNode1();
        Node nodeB = edge.getNode2();

        if (nodeA != null
            && nodeB != null
            && graph.isAdjacentTo(nodeA, nodeB)
            && !graph.isChildOf(nodeA, nodeB)) {
          if (!graph.isAncestorOf(nodeA, nodeB)) {
            graph.removeEdges(nodeA, nodeB);
            graph.addDirectedEdge(nodeB, nodeA);
            TetradLogger.getInstance()
                .log("insertedEdges", "Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA));
          }
        }
        if (!graph.isChildOf(nodeA, nodeB)
            && getKnowledge().isForbidden(nodeA.getName(), nodeB.getName())) {
          if (!graph.isAncestorOf(nodeA, nodeB)) {
            graph.removeEdges(nodeA, nodeB);
            graph.addDirectedEdge(nodeB, nodeA);
            TetradLogger.getInstance()
                .log("insertedEdges", "Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA));
          }
        }
      } else if (knowledge.isForbidden(B, A)) {
        Node nodeA = edge.getNode2();
        Node nodeB = edge.getNode1();

        if (nodeA != null
            && nodeB != null
            && graph.isAdjacentTo(nodeA, nodeB)
            && !graph.isChildOf(nodeA, nodeB)) {
          if (!graph.isAncestorOf(nodeA, nodeB)) {
            graph.removeEdges(nodeA, nodeB);
            graph.addDirectedEdge(nodeB, nodeA);
            TetradLogger.getInstance()
                .log("insertedEdges", "Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA));
          }
        }
        if (!graph.isChildOf(nodeA, nodeB)
            && getKnowledge().isForbidden(nodeA.getName(), nodeB.getName())) {
          if (!graph.isAncestorOf(nodeA, nodeB)) {
            graph.removeEdges(nodeA, nodeB);
            graph.addDirectedEdge(nodeB, nodeA);
            TetradLogger.getInstance()
                .log("insertedEdges", "Adding edge by knowledge: " + graph.getEdge(nodeB, nodeA));
          }
        }
      }
    }
  }