Search in sources :

Example 31 with DataSet

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

the class TestDataSetCellProbs method testCreateUsingBayesIm.

@Test
public void testCreateUsingBayesIm() {
    Graph graph = GraphConverter.convert("X1-->X2,X1-->X3,X2-->X4,X3-->X4");
    Dag dag = new Dag(graph);
    BayesPm bayesPm = new BayesPm(dag);
    BayesIm bayesIm = new MlBayesIm(bayesPm, MlBayesIm.RANDOM);
    BayesImProbs bayesImProbs = new BayesImProbs(bayesIm);
    DataSet dataSet = bayesIm.simulateData(1000, false);
    CellTableProbs dataSetProbs = new CellTableProbs(dataSet);
    int[] cell = new int[4];
    for (int i = 0; i < 200; i++) {
        for (int j = 0; j < 4; j++) {
            cell[j] = RandomUtil.getInstance().nextInt(bayesIm.getNumColumns(j));
        }
        double count1 = bayesImProbs.getCellProb(cell);
        double count2 = dataSetProbs.getCellProb(cell);
        assertEquals(count1, count2, .05);
    }
}
Also used : Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) Dag(edu.cmu.tetrad.graph.Dag) Test(org.junit.Test)

Example 32 with DataSet

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

the class TestDeltaSextadTest method testBollenExampleb.

@Test
public void testBollenExampleb() {
    DataSet data = null;
    try {
        String name = "src/test/resources/dataLG.txt";
        DataReader reader = new DataReader();
        data = reader.parseTabular(new File(name));
    } catch (IOException e) {
        e.printStackTrace();
    }
    int m1 = 0;
    int m2 = 1;
    int m3 = 2;
    int m4 = 3;
    int m5 = 4;
    int m6 = 5;
    IntSextad t1 = new IntSextad(m1, m2, m3, m4, m5, m6);
    IntSextad t2 = new IntSextad(m1, m2, m4, m3, m5, m6);
    IntSextad t3 = new IntSextad(m1, m2, m5, m3, m4, m6);
    IntSextad t4 = new IntSextad(m1, m2, m6, m3, m4, m5);
    IntSextad t5 = new IntSextad(m1, m3, m4, m2, m5, m6);
    IntSextad t6 = new IntSextad(m1, m3, m5, m2, m4, m6);
    IntSextad t7 = new IntSextad(m1, m3, m6, m2, m4, m5);
    IntSextad t8 = new IntSextad(m1, m4, m5, m2, m3, m6);
    IntSextad t9 = new IntSextad(m1, m4, m6, m2, m3, m5);
    IntSextad t10 = new IntSextad(m1, m5, m6, m2, m3, m4);
    DeltaSextadTest test = new DeltaSextadTest(data);
    IntSextad[] _sextads = { t2, t5, t10, t3, t6 };
    double p = test.getPValue(_sextads);
    assertEquals(0.21, p, 0.01);
    _sextads = new IntSextad[] { t10 };
    p = test.getPValue(_sextads);
    assertEquals(0.30, p, 0.01);
// This should throw an exception but doesn't.
// MySextad[] _sextads = {t1, t2, t3, t4, t5, t6, t7, t8, t9, t10};
}
Also used : IntSextad(edu.cmu.tetrad.search.IntSextad) DataReader(edu.cmu.tetrad.data.DataReader) DataSet(edu.cmu.tetrad.data.DataSet) IOException(java.io.IOException) File(java.io.File) DeltaSextadTest(edu.cmu.tetrad.search.DeltaSextadTest) Test(org.junit.Test) DeltaSextadTest(edu.cmu.tetrad.search.DeltaSextadTest)

Example 33 with DataSet

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

the class LoadContinuousDataAndSingleGraph method createData.

@Override
public void createData(Parameters parameters) {
    this.dataSets = new ArrayList<>();
    File dir = new File(path + "/" + subdir);
    if (dir.exists()) {
        File[] files = dir.listFiles();
        for (File file : files) {
            if (!file.getName().endsWith(".txt"))
                continue;
            System.out.println("Loading data from " + file.getAbsolutePath());
            DataReader reader = new DataReader();
            reader.setVariablesSupplied(true);
            try {
                DataSet dataSet = reader.parseTabular(file);
                dataSets.add(dataSet);
                if (!(dataSet.isContinuous())) {
                    throw new IllegalArgumentException("Not a continuous data set: " + dataSet.getName());
                }
            } catch (Exception e) {
                System.out.println("Couldn't parse " + file.getAbsolutePath());
            }
        }
    }
    File dir2 = new File(path + "/graph");
    if (dir2.exists()) {
        File[] files = dir2.listFiles();
        if (files.length != 1) {
            throw new IllegalArgumentException("Expecting exactly one graph file.");
        }
        File file = files[0];
        System.out.println("Loading graph from " + file.getAbsolutePath());
        this.graph = GraphUtils.loadGraphTxt(file);
        // if (!graph.isAdjacentTo(graph.getNode("X3"), graph.getNode("X4"))) {
        // graph.addUndirectedEdge(graph.getNode("X3"), graph.getNode("X4"));
        // }
        GraphUtils.circleLayout(this.graph, 225, 200, 150);
    }
    if (parameters.get("numRuns") != null) {
        parameters.set("numRuns", parameters.get("numRuns"));
    } else {
        parameters.set("numRuns", dataSets.size());
    }
    System.out.println();
}
Also used : DataReader(edu.cmu.tetrad.data.DataReader) DataSet(edu.cmu.tetrad.data.DataSet) File(java.io.File)

Example 34 with DataSet

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

the class SpecialDataClark method createData.

@Override
public void createData(Parameters parameters) {
    Graph graph = randomGraph.createGraph(parameters);
    dataSets = new ArrayList<>();
    graphs = new ArrayList<>();
    for (int i = 0; i < parameters.getInt("numRuns"); i++) {
        System.out.println("Simulating dataset #" + (i + 1));
        if (parameters.getBoolean("differentGraphs") && i > 0) {
            graph = randomGraph.createGraph(parameters);
        }
        graphs.add(graph);
        DataSet dataSet = simulate(graph, parameters);
        dataSet.setName("" + (i + 1));
        dataSets.add(dataSet);
    }
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) SingleGraph(edu.cmu.tetrad.algcomparison.graph.SingleGraph) DataSet(edu.cmu.tetrad.data.DataSet)

Example 35 with DataSet

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

the class Cfci method search.

@Override
public Graph search(DataModel dataSet, Parameters parameters) {
    if (parameters.getInt("bootstrapSampleSize") < 1) {
        edu.cmu.tetrad.search.Cfci search = new edu.cmu.tetrad.search.Cfci(test.getTest(dataSet, parameters));
        search.setKnowledge(knowledge);
        search.setCompleteRuleSetUsed(parameters.getBoolean("completeRuleSetUsed"));
        search.setDepth(parameters.getInt("depth"));
        return search.search();
    } else {
        Cfci algorithm = new Cfci(test);
        DataSet data = (DataSet) dataSet;
        GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
        search.setKnowledge(knowledge);
        BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
        switch(parameters.getInt("bootstrapEnsemble", 1)) {
            case 0:
                edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
                break;
            case 1:
                edgeEnsemble = BootstrapEdgeEnsemble.Highest;
                break;
            case 2:
                edgeEnsemble = BootstrapEdgeEnsemble.Majority;
        }
        search.setEdgeEnsemble(edgeEnsemble);
        search.setParameters(parameters);
        search.setVerbose(parameters.getBoolean("verbose"));
        return search.search();
    }
}
Also used : GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) BootstrapEdgeEnsemble(edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble) DataSet(edu.cmu.tetrad.data.DataSet)

Aggregations

DataSet (edu.cmu.tetrad.data.DataSet)216 Test (org.junit.Test)65 Graph (edu.cmu.tetrad.graph.Graph)64 Node (edu.cmu.tetrad.graph.Node)60 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)48 ArrayList (java.util.ArrayList)45 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)36 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)32 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)29 SemIm (edu.cmu.tetrad.sem.SemIm)28 SemPm (edu.cmu.tetrad.sem.SemPm)28 BootstrapEdgeEnsemble (edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble)26 DataModel (edu.cmu.tetrad.data.DataModel)22 Parameters (edu.cmu.tetrad.util.Parameters)22 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)20 File (java.io.File)16 ParseException (java.text.ParseException)16 LinkedList (java.util.LinkedList)14 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)13 DMSearch (edu.cmu.tetrad.search.DMSearch)10