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);
}
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);
}
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);
}
Aggregations