コード例 #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
ファイル: PcMax.java プロジェクト: renjiey/tetrad
  /**
   * Runs PC starting with a commplete graph over the given list of nodes, using the given
   * independence test and knowledge and returns the resultant graph. The returned graph will be a
   * pattern if the independence information is consistent with the hypothesis that there are no
   * latent common causes. It may, however, contain cycles or bidirected edges if this assumption is
   * not born out, either due to the actual presence of latent common causes, or due to statistical
   * errors in conditional independence judgments.
   *
   * <p>All of the given nodes must be in the domain of the given conditional independence test.
   */
  public Graph search(List<Node> nodes) {
    this.logger.log("info", "Starting PC algorithm");
    this.logger.log("info", "Independence test = " + getIndependenceTest() + ".");

    if (trueDag != null) {
      this.dsep = new IndTestDSep(trueDag);
    }

    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.");
    }

    IFas fas = new Fas2(getIndependenceTest());
    fas.setInitialGraph(initialGraph);
    fas.setKnowledge(getKnowledge());
    fas.setDepth(getDepth());
    fas.setVerbose(verbose);
    graph = fas.search();

    SearchGraphUtils.pcOrientbk(knowledge, graph, nodes);

    //        independenceTest = new ProbabilisticMAPIndependence((DataSet)
    // independenceTest.getData());

    SepsetsMaxPValue sepsetProducer =
        new SepsetsMaxPValue(graph, independenceTest, null, getDepth());
    sepsetProducer.setDsep(dsep);

    addColliders(graph, sepsetProducer, knowledge);

    MeekRules rules = new MeekRules();
    rules.setKnowledge(knowledge);
    rules.orientImplied(graph);

    //        Graph pattern = new EdgeListGraphSingleConnections(graph);
    //
    //        for (Node x : getNodes()) {
    //            for (Node y : getNodes()) {
    //                if (x == y) continue;
    //
    //                if (!localMarkovIndep(x, y, pattern, independenceTest)) {
    //                    graph.addUndirectedEdge(x, y);
    //                }
    //            }
    //        }
    //
    //        fas = new FasStableConcurrent(getIndependenceTest());
    //        fas.setInitialGraph(new EdgeListGraphSingleConnections(graph));
    //        fas.setKnowledge(getKnowledge());
    //        fas.setDepth(getDepth());
    //        fas.setVerbose(verbose);
    //        graph = fas.search();
    //
    //        sepsetProducer = new SepsetsMaxPValue(graph, independenceTest, null, getDepth());
    //
    //        addColliders(graph, sepsetProducer, knowledge);
    //
    //        rules = new MeekRules();
    //        rules.setKnowledge(knowledge);
    //        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;
  }