Search in sources :

Example 66 with ContinuousVariable

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

the class TestIndTestTimeSeries method setUp.

private void setUp() {
    List<Node> vars = new ArrayList<>();
    for (String varName : varNames) {
        vars.add(new ContinuousVariable(varName));
    }
    TetradMatrix _data = new TetradMatrix(data.length, data[0].length);
    for (int i = 0; i < data.length; i++) {
        for (int j = 0; j < data[0].length; j++) {
            _data.set(i, j, data[i][j]);
        }
    }
    test = new IndTestTimeSeries(_data, vars);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) IndTestTimeSeries(edu.cmu.tetrad.search.IndTestTimeSeries) Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix)

Example 67 with ContinuousVariable

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

the class TestDeltaTetradTest method getBollenExample2Data.

private CovarianceMatrix getBollenExample2Data() {
    // Union sentiment.
    double[][] d = new double[][] { { 14.610 }, { -5.250, 11.017 }, { -8.057, 11.087, 31.971 }, { -0.482, 0.677, 1.559, 1.021 }, { -18.857, 17.861, 28.250, 7.139, 215.662 } };
    Node y1 = new ContinuousVariable("y1");
    Node y2 = new ContinuousVariable("y2");
    Node y3 = new ContinuousVariable("y3");
    Node x1 = new ContinuousVariable("x1");
    Node x2 = new ContinuousVariable("x2");
    List<Node> nodes = new ArrayList<>();
    nodes.add(y1);
    nodes.add(y2);
    nodes.add(y3);
    nodes.add(x1);
    nodes.add(x2);
    TetradMatrix matrix = new TetradMatrix(5, 5);
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j <= i; j++) {
            matrix.set(i, j, d[i][j]);
            matrix.set(j, i, d[i][j]);
        }
    }
    return new CovarianceMatrix(nodes, matrix, 173);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ArrayList(java.util.ArrayList) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix)

Example 68 with ContinuousVariable

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

the class TestDeltaTetradTest method getBollenExample1Data.

private CovarianceMatrix getBollenExample1Data() {
    // Sympathy and anger, p. 164.
    double[][] d = new double[][] { { 6.982 }, { 4.686, 6.047 }, { 4.335, 3.307, 5.037 }, { -2.294, -1.453, -1.979, 5.569 }, { -2.209, -1.262, -1.738, 3.931, 5.328 }, { -1.671, -1.401, -1.564, 3.915, 3.601, 4.977 } };
    Node v1 = new ContinuousVariable("v1");
    Node v2 = new ContinuousVariable("v2");
    Node v3 = new ContinuousVariable("v3");
    Node v4 = new ContinuousVariable("v4");
    Node v5 = new ContinuousVariable("v5");
    Node v6 = new ContinuousVariable("v6");
    List<Node> nodes = new ArrayList<>();
    nodes.add(v1);
    nodes.add(v2);
    nodes.add(v3);
    nodes.add(v4);
    nodes.add(v5);
    nodes.add(v6);
    TetradMatrix matrix = new TetradMatrix(6, 6);
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j <= i; j++) {
            matrix.set(i, j, d[i][j]);
            matrix.set(j, i, d[i][j]);
        }
    }
    return new CovarianceMatrix(nodes, matrix, 138);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ArrayList(java.util.ArrayList) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix)

Example 69 with ContinuousVariable

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

the class TestTransform method testTransformWithNewColumnVariable.

@Test
public void testTransformWithNewColumnVariable() {
    List<Node> list = Arrays.asList((Node) new ContinuousVariable("x"), new ContinuousVariable("y"));
    DataSet data = new ColtDataSet(1, list);
    data.setDouble(0, 0, 1);
    data.setDouble(1, 0, 1);
    data.setDouble(0, 1, 1);
    data.setDouble(1, 1, 1);
    try {
        String eq = "w = (x + y) * x";
        Transformation.transform(data, eq);
        assertTrue(data.getDouble(0, 2) == 2.0);
        assertTrue(data.getDouble(0, 2) == 2.0);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) Node(edu.cmu.tetrad.graph.Node) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 70 with ContinuousVariable

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

the class TestTransform method testSingleTransforms.

@Test
public void testSingleTransforms() {
    // build a dataset.
    List<Node> list = Arrays.asList((Node) new ContinuousVariable("x"), new ContinuousVariable("y"), new ContinuousVariable("z"));
    DataSet data = new ColtDataSet(2, list);
    data.setDouble(0, 0, 2);
    data.setDouble(1, 0, 3);
    data.setDouble(2, 0, 4);
    data.setDouble(0, 1, 1);
    data.setDouble(1, 1, 6);
    data.setDouble(2, 1, 5);
    data.setDouble(0, 2, 8);
    data.setDouble(1, 2, 8);
    data.setDouble(2, 2, 8);
    DataSet copy = new ColtDataSet((ColtDataSet) data);
    // test transforms on it.
    try {
        String eq = "z = (x + y)";
        Transformation.transform(copy, eq);
        assertTrue(copy.getDouble(0, 2) == 3.0);
        assertTrue(copy.getDouble(1, 2) == 9.0);
        assertTrue(copy.getDouble(2, 2) == 9.0);
        copy = new ColtDataSet((ColtDataSet) data);
        eq = "x = x + 3";
        Transformation.transform(copy, eq);
        assertTrue(copy.getDouble(0, 0) == 5.0);
        assertTrue(copy.getDouble(1, 0) == 6.0);
        assertTrue(copy.getDouble(2, 0) == 7.0);
        copy = new ColtDataSet((ColtDataSet) data);
        eq = "x = pow(x, 2) + y + z";
        Transformation.transform(copy, eq);
        assertTrue(copy.getDouble(0, 0) == 13.0);
        assertTrue(copy.getDouble(1, 0) == 23.0);
        assertTrue(copy.getDouble(2, 0) == 29.0);
    } catch (ParseException ex) {
        fail(ex.getMessage());
    }
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) Node(edu.cmu.tetrad.graph.Node) ParseException(java.text.ParseException) 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