예제 #1
0
파일: Pc.java 프로젝트: bd2kccd/r-causal
  public Graph search(IFas fas, List<Node> nodes) {
    this.logger.log("info", "Starting PC algorithm");
    this.logger.log("info", "Independence test = " + getIndependenceTest() + ".");

    //        this.logger.log("info", "Variables " + independenceTest.getVariables());

    long startTime = System.currentTimeMillis();

    if (getIndependenceTest() == null) {
      throw new NullPointerException();
    }

    List<Node> allNodes = getIndependenceTest().getVariables();
    if (!allNodes.containsAll(nodes)) {
      throw new IllegalArgumentException(
          "All of the given nodes must " + "be in the domain of the independence test provided.");
    }

    fas.setKnowledge(getKnowledge());
    fas.setDepth(getDepth());
    fas.setVerbose(verbose);

    graph = fas.search();
    sepsets = fas.getSepsets();

    this.numIndependenceTests = fas.getNumIndependenceTests();
    this.numFalseDependenceJudgements = fas.getNumFalseDependenceJudgments();
    this.numDependenceJudgements = fas.getNumDependenceJudgments();

    //        enumerateTriples();

    SearchGraphUtils.pcOrientbk(knowledge, graph, nodes);
    SearchGraphUtils.orientCollidersUsingSepsets(this.sepsets, knowledge, graph, verbose);

    MeekRules rules = new MeekRules();
    rules.setAggressivelyPreventCycles(this.aggressivelyPreventCycles);
    rules.setKnowledge(knowledge);
    rules.setUndirectUnforcedEdges(false);
    rules.orientImplied(graph);

    this.logger.log("graph", "\nReturning this graph: " + graph);

    this.elapsedTime = System.currentTimeMillis() - startTime;

    this.logger.log("info", "Elapsed time = " + (elapsedTime) / 1000. + " s");
    this.logger.log("info", "Finishing PC Algorithm.");
    this.logger.flush();

    return graph;
  }
예제 #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;
  }