Search in sources :

Example 1 with DiscreteVariable

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

the class TestCellProbabilities method testCreateRandom.

@Test
public void testCreateRandom() {
    RandomUtil.getInstance().setSeed(4828385834L);
    DiscreteVariable x = new DiscreteVariable("X", 3);
    DiscreteVariable y = new DiscreteVariable("Y", 3);
    DiscreteVariable z = new DiscreteVariable("Z", 3);
    DiscreteVariable w = new DiscreteVariable("W", 2);
    List<Node> variables = new LinkedList<>();
    variables.add(x);
    variables.add(y);
    variables.add(z);
    variables.add(w);
    StoredCellProbs cellProbabilities = StoredCellProbs.createRandomCellTable(variables);
    double prob = cellProbabilities.getCellProb(new int[] { 0, 0, 0, 0 });
    assertEquals(0.002, prob, 0.0001);
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) Node(edu.cmu.tetrad.graph.Node) StoredCellProbs(edu.cmu.tetrad.bayes.StoredCellProbs) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with DiscreteVariable

use of edu.cmu.tetrad.data.DiscreteVariable 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 3 with DiscreteVariable

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

the class TestCellTable method setUp.

public final void setUp() {
    this.table = new CellTable(dims);
    // // Add data to table.
    List<Node> variables = new LinkedList<>();
    variables.add(new DiscreteVariable("X1", 2));
    variables.add(new DiscreteVariable("X2", 2));
    variables.add(new DiscreteVariable("X3", 2));
    variables.add(new DiscreteVariable("X4", 2));
    DataSet dataSet = new ColtDataSet(data.length, variables);
    for (int i = 0; i < data.length; i++) {
        for (int j = 0; j < data[0].length; j++) {
            dataSet.setInt(i, j, data[i][j]);
        }
    }
    int[] indices = new int[] { 0, 1, 2, 3 };
    this.table.addToTable(dataSet, indices);
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) CellTable(edu.cmu.tetrad.data.CellTable) DataSet(edu.cmu.tetrad.data.DataSet) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) Node(edu.cmu.tetrad.graph.Node) LinkedList(java.util.LinkedList)

Example 4 with DiscreteVariable

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

the class TestColtDataSet method testDiscreteFromScratch.

@Test
public void testDiscreteFromScratch() {
    DataSet dataSet = new ColtDataSet(0, Collections.EMPTY_LIST);
    DiscreteVariable x1 = new DiscreteVariable("X1");
    dataSet.addVariable(x1);
    dataSet.setInt(0, 0, 0);
    dataSet.setInt(1, 0, 2);
    dataSet.setInt(2, 0, 1);
    DiscreteVariable x2 = new DiscreteVariable("X2");
    dataSet.addVariable(x2);
    dataSet.setInt(0, 1, 0);
    dataSet.setInt(1, 1, 2);
    dataSet.setInt(2, 1, 1);
    ColtDataSet _dataSet = new ColtDataSet((ColtDataSet) dataSet);
    assertEquals(dataSet, _dataSet);
    assertEquals(dataSet.getInt(1, 1), 2);
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Test(org.junit.Test)

Example 5 with DiscreteVariable

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

the class TestDiscreteProbs method testCreateRandom.

public static void testCreateRandom() {
    DiscreteVariable x = new DiscreteVariable("X", 3);
    DiscreteVariable y = new DiscreteVariable("Y", 3);
    DiscreteVariable z = new DiscreteVariable("Z", 3);
    DiscreteVariable w = new DiscreteVariable("W", 2);
    List<Node> variables = new LinkedList<>();
    variables.add(x);
    variables.add(y);
    variables.add(z);
    variables.add(w);
    StoredCellProbs cellProbabilities = StoredCellProbs.createRandomCellTable(variables);
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) Node(edu.cmu.tetrad.graph.Node) LinkedList(java.util.LinkedList)

Aggregations

DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)56 Node (edu.cmu.tetrad.graph.Node)37 DataSet (edu.cmu.tetrad.data.DataSet)18 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)16 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)11 LinkedList (java.util.LinkedList)9 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Dag (edu.cmu.tetrad.graph.Dag)3 NumberFormat (java.text.NumberFormat)3 Element (nu.xom.Element)3 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)2 Graph (edu.cmu.tetrad.graph.Graph)2 LogisticRegression (edu.cmu.tetrad.regression.LogisticRegression)2 List (java.util.List)2 Elements (nu.xom.Elements)2 DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)1 TakesInitialGraph (edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph)1 StoredCellProbs (edu.cmu.tetrad.bayes.StoredCellProbs)1 BoxDataSet (edu.cmu.tetrad.data.BoxDataSet)1