Search in sources :

Example 26 with ColtDataSet

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

the class TestColtDataSet method testRemoveColumn.

@Test
public void testRemoveColumn() {
    int rows = 10;
    int cols = 5;
    List<Node> variables = new LinkedList<>();
    for (int i = 0; i < cols; i++) {
        variables.add(new ContinuousVariable("X" + i));
    }
    DataSet dataSet = new ColtDataSet(rows, variables);
    RandomUtil randomUtil = RandomUtil.getInstance();
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            dataSet.setDouble(i, j, randomUtil.nextDouble());
        }
    }
    int[] _cols = new int[2];
    _cols[0] = 1;
    _cols[1] = 2;
    dataSet.removeCols(_cols);
    List<Node> _variables = new LinkedList<>(variables);
    _variables.remove(2);
    _variables.remove(1);
    assertEquals(dataSet.getVariables(), _variables);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) RandomUtil(edu.cmu.tetrad.util.RandomUtil) 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 27 with ColtDataSet

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

the class TestColtDataSet method testDiscrete.

@Test
public void testDiscrete() {
    int rows = 10;
    int cols = 5;
    List<Node> variables = new LinkedList<>();
    for (int i = 0; i < cols; i++) {
        DiscreteVariable variable = new DiscreteVariable("X" + (i + 1), 3);
        variables.add(variable);
    }
    DataSet dataSet = new ColtDataSet(rows, variables);
    RandomUtil randomUtil = RandomUtil.getInstance();
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            dataSet.setInt(i, j, randomUtil.nextInt(3));
        }
    }
    ColtDataSet _dataSet = new ColtDataSet((ColtDataSet) dataSet);
    assertEquals(dataSet, _dataSet);
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) RandomUtil(edu.cmu.tetrad.util.RandomUtil) 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 28 with ColtDataSet

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

the class TestColtDataSet method testRowSubset.

@Test
public void testRowSubset() {
    int rows = 10;
    int cols = 5;
    List<Node> variables = new LinkedList<>();
    for (int i = 0; i < cols; i++) {
        variables.add(new ContinuousVariable("X" + i));
    }
    DataSet dataSet = new ColtDataSet(rows, variables);
    RandomUtil randomUtil = RandomUtil.getInstance();
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            dataSet.setDouble(i, j, randomUtil.nextDouble());
        }
    }
    double d = dataSet.getDouble(2, 0);
    DataSet _dataSet = dataSet.subsetRows(new int[] { 2, 3, 4 });
    assertEquals(3, _dataSet.getNumRows());
    assertEquals(d, _dataSet.getDouble(0, 0), 0.001);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) RandomUtil(edu.cmu.tetrad.util.RandomUtil) 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)

Aggregations

ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)28 DataSet (edu.cmu.tetrad.data.DataSet)24 Node (edu.cmu.tetrad.graph.Node)21 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)17 LinkedList (java.util.LinkedList)13 Test (org.junit.Test)12 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)9 RandomUtil (edu.cmu.tetrad.util.RandomUtil)6 Parameters (edu.cmu.tetrad.util.Parameters)3 ArrayList (java.util.ArrayList)3 KernelGaussian (edu.cmu.tetrad.search.kernel.KernelGaussian)2 DecimalFormat (java.text.DecimalFormat)2 ParseException (java.text.ParseException)2 KMeans (edu.cmu.tetrad.cluster.KMeans)1 CellTable (edu.cmu.tetrad.data.CellTable)1 DataModelList (edu.cmu.tetrad.data.DataModelList)1 TimeSeriesData (edu.cmu.tetrad.data.TimeSeriesData)1 Dag (edu.cmu.tetrad.graph.Dag)1 RegressionDataset (edu.cmu.tetrad.regression.RegressionDataset)1 RegressionResult (edu.cmu.tetrad.regression.RegressionResult)1