Search in sources :

Example 11 with IndependenceTest

use of edu.cmu.tetrad.search.IndependenceTest in project tetrad by cmu-phil.

the class TestPcd method checkWithKnowledge.

/**
 * Presents the input graph to FCI and checks to make sure the output of FCI is equivalent to the given output
 * graph.
 */
private void checkWithKnowledge(String inputGraph, String outputGraph, IKnowledge knowledge) {
    // Set up graph and node objects.
    Graph graph = GraphConverter.convert(inputGraph);
    // Set up search.
    IndependenceTest independence = new IndTestDSep(graph);
    Pc pc = new Pc(independence);
    pc.setKnowledge(knowledge);
    // Run search
    Graph resultGraph = pc.search();
    // Build comparison graph.
    Graph trueGraph = GraphConverter.convert(outputGraph);
    resultGraph = GraphUtils.replaceNodes(resultGraph, trueGraph.getNodes());
    // Do test.
    assertTrue(resultGraph.equals(trueGraph));
}
Also used : IndependenceTest(edu.cmu.tetrad.search.IndependenceTest) IndTestDSep(edu.cmu.tetrad.search.IndTestDSep) Graph(edu.cmu.tetrad.graph.Graph) Pc(edu.cmu.tetrad.search.Pc)

Example 12 with IndependenceTest

use of edu.cmu.tetrad.search.IndependenceTest in project tetrad by cmu-phil.

the class TestIndTestFisherGeneralizedInverse method testDirections.

@Test
public void testDirections() {
    RandomUtil.getInstance().setSeed(48285934L);
    Graph graph1 = new EdgeListGraph();
    Graph graph2 = new EdgeListGraph();
    Node x = new GraphNode("X");
    Node y = new GraphNode("Y");
    Node z = new GraphNode("Z");
    graph1.addNode(x);
    graph1.addNode(y);
    graph1.addNode(z);
    graph2.addNode(x);
    graph2.addNode(y);
    graph2.addNode(z);
    graph1.addEdge(Edges.directedEdge(x, y));
    graph1.addEdge(Edges.directedEdge(y, z));
    graph2.addEdge(Edges.directedEdge(x, y));
    graph2.addEdge(Edges.directedEdge(z, y));
    SemPm pm1 = new SemPm(graph1);
    SemPm pm2 = new SemPm(graph2);
    SemIm im1 = new SemIm(pm1);
    SemIm im2 = new SemIm(pm2);
    im2.setEdgeCoef(x, y, im1.getEdgeCoef(x, y));
    im2.setEdgeCoef(z, y, im1.getEdgeCoef(y, z));
    DataSet data1 = im1.simulateData(500, false);
    DataSet data2 = im2.simulateData(500, false);
    IndependenceTest test1 = new IndTestFisherZGeneralizedInverse(data1, 0.05);
    IndependenceTest test2 = new IndTestFisherZGeneralizedInverse(data2, 0.05);
    test1.isIndependent(data1.getVariable(x.getName()), data1.getVariable(y.getName()));
    double p1 = test1.getPValue();
    test2.isIndependent(data2.getVariable(x.getName()), data2.getVariable(z.getName()), data2.getVariable(y.getName()));
    double p2 = test2.getPValue();
    test2.isIndependent(data2.getVariable(x.getName()), data2.getVariable(z.getName()));
    double p3 = test2.getPValue();
    assertEquals(0, p1, 0.01);
    assertEquals(0, p2, 0.01);
    assertEquals(0.38, p3, 0.01);
}
Also used : IndependenceTest(edu.cmu.tetrad.search.IndependenceTest) DataSet(edu.cmu.tetrad.data.DataSet) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) IndTestFisherZGeneralizedInverse(edu.cmu.tetrad.search.IndTestFisherZGeneralizedInverse) Test(org.junit.Test) IndependenceTest(edu.cmu.tetrad.search.IndependenceTest)

Aggregations

IndependenceTest (edu.cmu.tetrad.search.IndependenceTest)12 DataSet (edu.cmu.tetrad.data.DataSet)4 IndTestDSep (edu.cmu.tetrad.search.IndTestDSep)4 BootstrapEdgeEnsemble (edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble)4 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Graph (edu.cmu.tetrad.graph.Graph)3 Node (edu.cmu.tetrad.graph.Node)3 IndTestScore (edu.cmu.tetrad.search.IndTestScore)3 SemIm (edu.cmu.tetrad.sem.SemIm)3 SemPm (edu.cmu.tetrad.sem.SemPm)3 BdeuScore (edu.cmu.tetrad.algcomparison.score.BdeuScore)2 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)2 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)2 TsGFci (edu.cmu.tetrad.search.TsGFci)2 DataModel (edu.cmu.tetrad.data.DataModel)1 Discretizer (edu.cmu.tetrad.data.Discretizer)1 IKnowledge (edu.cmu.tetrad.data.IKnowledge)1 BdeuScoreImages (edu.cmu.tetrad.search.BdeuScoreImages)1