Exemplo n.º 1
0
  /** Orients according to background knowledge */
  private void fciOrientbk(IKnowledge bk, Graph graph, List<Node> variables) {
    logger.log("info", "Starting BK Orientation.");

    for (Iterator<KnowledgeEdge> it = bk.forbiddenEdgesIterator(); it.hasNext(); ) {
      KnowledgeEdge edge = it.next();

      // match strings to variables in the graph.
      Node from = SearchGraphUtils.translate(edge.getFrom(), variables);
      Node to = SearchGraphUtils.translate(edge.getTo(), variables);

      if (from == null || to == null) {
        continue;
      }

      if (graph.getEdge(from, to) == null) {
        continue;
      }

      // Orient to*->from
      graph.setEndpoint(to, from, Endpoint.ARROW);
      graph.setEndpoint(from, to, Endpoint.CIRCLE);
      changeFlag = true;
      logger.log(
          "knowledgeOrientation",
          SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to)));
    }

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

      // match strings to variables in this graph
      Node from = SearchGraphUtils.translate(edge.getFrom(), variables);
      Node to = SearchGraphUtils.translate(edge.getTo(), variables);

      if (from == null || to == null) {
        continue;
      }

      if (graph.getEdge(from, to) == null) {
        continue;
      }

      graph.setEndpoint(to, from, Endpoint.TAIL);
      graph.setEndpoint(from, to, Endpoint.ARROW);
      changeFlag = true;
      logger.log(
          "knowledgeOrientation",
          SearchLogUtils.edgeOrientedMsg("Knowledge", graph.getEdge(from, to)));
    }

    logger.log("info", "Finishing BK Orientation.");
  }
Exemplo n.º 2
0
  public Graph search(IFas fas, List<Node> nodes) {
    long beginTime = System.currentTimeMillis();

    logger.log("info", "Starting FCI algorithm.");
    logger.log("info", "Independence test = " + getIndependenceTest() + ".");

    setMaxPathLength(maxPathLength);

    this.graph = new EdgeListGraph(nodes);

    long start1 = System.currentTimeMillis();

    fas.setKnowledge(getKnowledge());
    fas.setDepth(depth);
    fas.setVerbose(verbose);
    //        fas.setFci(true);
    graph = fas.search();
    graph.reorientAllWith(Endpoint.CIRCLE);
    this.sepsets = fas.getSepsets();

    long stop1 = System.currentTimeMillis();
    long start2 = System.currentTimeMillis();

    // The original FCI, with or without JiJi Zhang's orientation rules
    fciOrientbk(getKnowledge(), graph, variables);
    ruleR0_RFCI(getRTuples()); // RFCI Algorithm 4.4
    doFinalOrientation();

    long endTime = System.currentTimeMillis();
    this.elapsedTime = endTime - beginTime;

    logger.log("graph", "Returning graph: " + graph);
    long stop2 = System.currentTimeMillis();

    logger.log("info", "Elapsed time adjacency search = " + (stop1 - start1) / 1000L + "s");
    logger.log("info", "Elapsed time orientation search = " + (stop2 - start2) / 1000L + "s");

    return graph;
  }