Search in sources :

Example 1 with ContinuousVariable

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

the class LoadTimeSeriesDataAction method loadTimeSeriesDataSet.

/**
 * Method loadDataSet_TabDelim
 */
private void loadTimeSeriesDataSet() {
    // select a file to load using the file chooser
    JFileChooser chooser = getJFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.showOpenDialog(this.editor);
    // get the file
    File file = chooser.getSelectedFile();
    Preferences.userRoot().put("fileSaveLocation", file.getParent());
    try {
        BufferedReader in = new BufferedReader(new FileReader(file));
        String line;
        StringTokenizer st;
        // read in variable name and set up DataSet.
        List<Node> variables = new LinkedList<>();
        st = new StringTokenizer(in.readLine());
        while (st.hasMoreTokens()) {
            String name = st.nextToken();
            ContinuousVariable var = new ContinuousVariable(name);
            variables.add(var);
        }
        DataSet dataSet = new ColtDataSet(0, variables);
        int row = -1;
        while ((line = in.readLine()) != null) {
            int col = -1;
            st = new StringTokenizer(line);
            while (st.hasMoreTokens()) {
                String literal = st.nextToken();
                if (literal.length() == 0) {
                    continue;
                }
                dataSet.setObject(row, ++col, literal);
            }
        }
        TimeSeriesData dataSet3 = new TimeSeriesData(dataSet.getDoubleData(), dataSet.getVariableNames());
        editor.getDataWrapper().setDataModel(dataSet3);
        firePropertyChange("modelChanged", null, null);
        editor.reset();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) LinkedList(java.util.LinkedList) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) StringTokenizer(java.util.StringTokenizer) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) TimeSeriesData(edu.cmu.tetrad.data.TimeSeriesData)

Example 2 with ContinuousVariable

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

the class SpecialGraphClark method createGraph.

@Override
public Graph createGraph(Parameters parameters) {
    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(z, x);
    // g.addDirectedEdge(z, y);
    g.addDirectedEdge(x, y);
    g.addDirectedEdge(x, z);
    g.addDirectedEdge(y, z);
    // 
    return g;
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph)

Example 3 with ContinuousVariable

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

the class TestColtDataSet method testMixed.

@Test
public void testMixed() {
    List<Node> variables = new LinkedList<>();
    DiscreteVariable x1 = new DiscreteVariable("X1");
    variables.add(x1);
    ContinuousVariable x2 = new ContinuousVariable("X2");
    variables.add(x2);
    DataSet dataSet = new ColtDataSet(5, variables);
    assertTrue(dataSet.getVariables().get(0) instanceof DiscreteVariable);
    assertTrue(dataSet.getVariables().get(1) instanceof ContinuousVariable);
    assertTrue(dataSet.getInt(0, 0) == -99);
    assertTrue(Double.isNaN(dataSet.getDouble(1, 0)));
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 4 with ContinuousVariable

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

the class TestDM method test2.

@Test
public void test2() {
    // setting seed for debug.
    RandomUtil.getInstance().setSeed(29483818483L);
    Graph graph = emptyGraph(8);
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X2"));
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X3"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X2"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X3"));
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X6"));
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X7"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X6"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X7"));
    graph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("X6"));
    graph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("X7"));
    graph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("X6"));
    graph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("X7"));
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet data = im.simulateData(100000, false);
    DMSearch search = new DMSearch();
    search.setInputs(new int[] { 0, 1, 4, 5 });
    search.setOutputs(new int[] { 2, 3, 6, 7 });
    search.setData(data);
    search.setTrueInputs(search.getInputs());
    Graph foundGraph = search.search();
    print("Test Case 2");
    Graph trueGraph = new EdgeListGraph();
    trueGraph.addNode(new ContinuousVariable("X0"));
    trueGraph.addNode(new ContinuousVariable("X1"));
    trueGraph.addNode(new ContinuousVariable("X2"));
    trueGraph.addNode(new ContinuousVariable("X3"));
    trueGraph.addNode(new ContinuousVariable("X4"));
    trueGraph.addNode(new ContinuousVariable("X5"));
    trueGraph.addNode(new ContinuousVariable("X6"));
    trueGraph.addNode(new ContinuousVariable("X7"));
    trueGraph.addNode(new ContinuousVariable("L0"));
    trueGraph.addNode(new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L0"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L0"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X2"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X3"));
    // trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L1"), new ContinuousVariable("X6"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L1"), new ContinuousVariable("X7"));
    assertTrue(foundGraph.equals(trueGraph));
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) DMSearch(edu.cmu.tetrad.search.DMSearch) Test(org.junit.Test)

Example 5 with ContinuousVariable

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

the class TestDM method test10.

// 
@Test
public void test10() {
    // setting seed for debug.
    RandomUtil.getInstance().setSeed(29483818483L);
    Graph graph = emptyGraph(5);
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X2"));
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X3"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X3"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X4"));
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet data = im.simulateData(100000, false);
    DMSearch search = new DMSearch();
    search.setUseFges(false);
    search.setInputs(new int[] { 0, 1 });
    search.setOutputs(new int[] { 2, 3, 4 });
    search.setData(data);
    search.setTrueInputs(search.getInputs());
    search.search();
    print("Test Case 10");
    // Trying to quiet the output for unit tests.
    if (false) {
        System.out.println(search.getDmStructure());
    }
    assertTrue(true);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) DMSearch(edu.cmu.tetrad.search.DMSearch) Test(org.junit.Test)

Aggregations

ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)91 DataSet (edu.cmu.tetrad.data.DataSet)48 Node (edu.cmu.tetrad.graph.Node)46 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)28 Graph (edu.cmu.tetrad.graph.Graph)22 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)19 SemPm (edu.cmu.tetrad.sem.SemPm)18 SemIm (edu.cmu.tetrad.sem.SemIm)16 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)15 LinkedList (java.util.LinkedList)13 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)12 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)8 DMSearch (edu.cmu.tetrad.search.DMSearch)7 Dag (edu.cmu.tetrad.graph.Dag)6 CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)5 RandomUtil (edu.cmu.tetrad.util.RandomUtil)5 ParseException (java.text.ParseException)4 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)3 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)3