Search in sources :

Example 6 with CovarianceMatrixOnTheFly

use of edu.cmu.tetrad.data.CovarianceMatrixOnTheFly in project tetrad by cmu-phil.

the class TestSimulatedFmri method testClark2.

// @Test
public void testClark2() {
    Node x = new ContinuousVariable("X");
    Node y = new ContinuousVariable("Y");
    Node z = new ContinuousVariable("Z");
    Graph g = new EdgeListGraph();
    g.addNode(x);
    g.addNode(y);
    g.addNode(z);
    g.addDirectedEdge(x, y);
    g.addDirectedEdge(x, z);
    g.addDirectedEdge(y, z);
    GeneralizedSemPm pm = new GeneralizedSemPm(g);
    try {
        pm.setNodeExpression(g.getNode("X"), "E_X");
        pm.setNodeExpression(g.getNode("Y"), "0.4 * X + E_Y");
        pm.setNodeExpression(g.getNode("Z"), "0.4 * X + 0.4 * Y + E_Z");
        String error = "pow(Uniform(0, 1), 1.5)";
        pm.setNodeExpression(pm.getErrorNode(g.getNode("X")), error);
        pm.setNodeExpression(pm.getErrorNode(g.getNode("Y")), error);
        pm.setNodeExpression(pm.getErrorNode(g.getNode("Z")), error);
    } catch (ParseException e) {
        System.out.println(e);
    }
    GeneralizedSemIm im = new GeneralizedSemIm(pm);
    DataSet data = im.simulateData(1000, false);
    edu.cmu.tetrad.search.SemBicScore score = new edu.cmu.tetrad.search.SemBicScore(new CovarianceMatrixOnTheFly(data, false));
    Fask fask = new Fask(data, score);
    fask.setPenaltyDiscount(1);
    fask.setAlpha(0.5);
    Graph out = fask.search();
    System.out.println(out);
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) Fask(edu.cmu.tetrad.search.Fask) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) GeneralizedSemIm(edu.cmu.tetrad.sem.GeneralizedSemIm) ParseException(java.text.ParseException) CovarianceMatrixOnTheFly(edu.cmu.tetrad.data.CovarianceMatrixOnTheFly) GeneralizedSemPm(edu.cmu.tetrad.sem.GeneralizedSemPm) SemBicScore(edu.cmu.tetrad.algcomparison.score.SemBicScore)

Example 7 with CovarianceMatrixOnTheFly

use of edu.cmu.tetrad.data.CovarianceMatrixOnTheFly in project tetrad by cmu-phil.

the class FasLofs method search.

// ======================================== PUBLIC METHODS ====================================//
/**
 * Runs the search on the concatenated data, returning a graph, possibly cyclic, possibly with
 * two-cycles. Runs the fast adjacency search (FAS, Spirtes et al., 2000) follows by a modification
 * of the robust skew rule (Pairwise Likelihood Ratios for Estimation of Non-Gaussian Structural
 * Equation Models, Smith and Hyvarinen), together with some heuristics for orienting two-cycles.
 *
 * @return the graph. Some of the edges may be undirected (though it shouldn't be many in most cases)
 * and some of the adjacencies may be two-cycles.
 */
public Graph search() {
    long start = System.currentTimeMillis();
    SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(dataSet));
    score.setPenaltyDiscount(penaltyDiscount);
    IndependenceTest test = new IndTestScore(score, dataSet);
    System.out.println("FAS");
    FasStable fas = new FasStable(test);
    fas.setDepth(getDepth());
    fas.setVerbose(false);
    fas.setKnowledge(knowledge);
    Graph G0 = fas.search();
    System.out.println("LOFS orientation, rule " + rule);
    Lofs2 lofs2 = new Lofs2(G0, Collections.singletonList(dataSet));
    lofs2.setRule(rule);
    lofs2.setKnowledge(knowledge);
    Graph graph = lofs2.orient();
    System.out.println("Done");
    long stop = System.currentTimeMillis();
    this.elapsed = stop - start;
    return graph;
}
Also used : Graph(edu.cmu.tetrad.graph.Graph) CovarianceMatrixOnTheFly(edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)

Aggregations

CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)7 DataSet (edu.cmu.tetrad.data.DataSet)6 Graph (edu.cmu.tetrad.graph.Graph)6 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)3 Node (edu.cmu.tetrad.graph.Node)3 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)2 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)2 Fask (edu.cmu.tetrad.search.Fask)2 SemBicScore (edu.cmu.tetrad.search.SemBicScore)2 GeneralizedSemIm (edu.cmu.tetrad.sem.GeneralizedSemIm)2 GeneralizedSemPm (edu.cmu.tetrad.sem.GeneralizedSemPm)2 SemIm (edu.cmu.tetrad.sem.SemIm)2 SemPm (edu.cmu.tetrad.sem.SemPm)2 File (java.io.File)2 ParseException (java.text.ParseException)2 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)1 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)1 IKnowledge (edu.cmu.tetrad.data.IKnowledge)1 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)1 Dag (edu.cmu.tetrad.graph.Dag)1