public static boolean meekR1Locally2(
      Graph graph, Knowledge knowledge, IndependenceTest test, int depth) {
    List<Node> nodes = graph.getNodes();
    boolean changed = true;

    while (changed) {
      changed = false;

      for (Node a : nodes) {
        List<Node> adjacentNodes = graph.getAdjacentNodes(a);

        if (adjacentNodes.size() < 2) {
          continue;
        }

        ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2);
        int[] combination;

        while ((combination = cg.next()) != null) {
          Node b = adjacentNodes.get(combination[0]);
          Node c = adjacentNodes.get(combination[1]);

          // Skip triples that are shielded.
          if (graph.isAdjacentTo(b, c)) {
            continue;
          }

          if (graph.getEndpoint(b, a) == Endpoint.ARROW && graph.isUndirectedFromTo(a, c)) {
            if (existsLocalSepsetWithoutDet(b, a, c, test, graph, depth)) {
              continue;
            }

            if (isArrowpointAllowed(a, c, knowledge)) {
              graph.setEndpoint(a, c, Endpoint.ARROW);
              TetradLogger.getInstance()
                  .edgeOriented(SearchLogUtils.edgeOrientedMsg("Meek R1", graph.getEdge(a, c)));
              changed = true;
            }
          } else if (graph.getEndpoint(c, a) == Endpoint.ARROW && graph.isUndirectedFromTo(a, b)) {
            if (existsLocalSepsetWithoutDet(b, a, c, test, graph, depth)) {
              continue;
            }

            if (isArrowpointAllowed(a, b, knowledge)) {
              graph.setEndpoint(a, b, Endpoint.ARROW);
              TetradLogger.getInstance()
                  .edgeOriented(SearchLogUtils.edgeOrientedMsg("Meek R1", graph.getEdge(a, b)));
              changed = true;
            }
          }
        }
      }
    }

    return changed;
  }
Пример #2
0
  /**
   * 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;
  }