Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
0
  public Graph search(List<Node> nodes) {
    long startTime = System.currentTimeMillis();
    localScoreCache.clear();

    if (!dataSet().getVariables().containsAll(nodes)) {
      throw new IllegalArgumentException("All of the nodes must be in " + "the supplied data set.");
    }

    Graph graph;

    if (initialGraph == null) {
      graph = new EdgeListGraphSingleConnections(nodes);
    } else {
      initialGraph = GraphUtils.replaceNodes(initialGraph, variables);
      graph = new EdgeListGraphSingleConnections(initialGraph);
    }

    topGraphs.clear();

    buildIndexing(graph);
    addRequiredEdges(graph);
    score = 0.0;

    // Do forward search.
    fes(graph, nodes);

    // Do backward search.
    bes(graph);

    long endTime = System.currentTimeMillis();
    this.elapsedTime = endTime - startTime;
    this.logger.log("graph", "\nReturning this graph: " + graph);

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

    return graph;
  }
Ejemplo n.º 3
0
  /**
   * Greedy equivalence search: Start from the empty graph, add edges till model is significant.
   * Then start deleting edges till a minimum is achieved.
   *
   * @return the resulting Pattern.
   */
  public Graph search() {

    Graph graph;

    if (initialGraph == null) {
      graph = new EdgeListGraphSingleConnections(getVariables());
    } else {
      graph = new EdgeListGraphSingleConnections(initialGraph);
    }

    fireGraphChange(graph);
    buildIndexing(graph);
    addRequiredEdges(graph);

    topGraphs.clear();

    storeGraph(graph);

    List<Node> nodes = graph.getNodes();

    long start = System.currentTimeMillis();
    score = 0.0;

    // Do forward search.
    fes(graph, nodes);

    // Do backward search.
    bes(graph);

    long endTime = System.currentTimeMillis();
    this.elapsedTime = endTime - start;
    this.logger.log("graph", "\nReturning this graph: " + graph);

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

    return graph;
  }
Ejemplo n.º 4
0
  public void rtestDSeparation4() {
    Graph graph = new Dag(GraphUtils.randomGraph(100, 20, 100, 5, 5, 5, false));

    long start, stop;
    int depth = -1;

    IndependenceTest test = new IndTestDSep(graph);

    Rfci fci = new Rfci(test);
    Fas fas = new Fas(test);
    start = System.currentTimeMillis();
    fci.setDepth(depth);
    fci.setVerbose(true);
    fci.search(fas, fas.getNodes());
    stop = System.currentTimeMillis();

    System.out.println("DSEP RFCI");
    System.out.println("# dsep checks = " + fas.getNumIndependenceTests());
    System.out.println("Elapsed " + (stop - start));
    System.out.println("Per " + fas.getNumIndependenceTests() / (double) (stop - start));

    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet data = im.simulateData(1000, false);
    IndependenceTest test2 = new IndTestFisherZ(data, 0.001);

    Rfci fci3 = new Rfci(test2);
    Fas fas2 = new Fas(test2);
    start = System.currentTimeMillis();
    fci3.setDepth(depth);
    fci3.search(fas2, fas2.getNodes());
    stop = System.currentTimeMillis();

    System.out.println("FISHER Z RFCI");
    System.out.println("# indep checks = " + fas.getNumIndependenceTests());
    System.out.println("Elapsed " + (stop - start));
    System.out.println("Per " + fas.getNumIndependenceTests() / (double) (stop - start));
  }
Ejemplo n.º 5
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;
  }
Ejemplo n.º 6
0
  /**
   * 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;
  }