use of edu.cmu.tetrad.data.ColtDataSet in project tetrad by cmu-phil.
the class DirichletBayesIm method simulateDataHelper.
/**
* Simulates a sample with the given sample size.
*
* @param sampleSize the sample size.
* @param randomUtil optional random number generator to use when
* creating the data
* @param latentDataSaved true iff data for latent variables should be
* saved.
* @return the simulated sample as a DataSet.
*/
private DataSet simulateDataHelper(int sampleSize, RandomUtil randomUtil, boolean latentDataSaved) {
int numMeasured = 0;
int[] map = new int[nodes.length];
List<Node> variables = new LinkedList<>();
for (int j = 0; j < nodes.length; j++) {
if (!latentDataSaved && nodes[j].getNodeType() != NodeType.MEASURED) {
continue;
}
int numCategories = bayesPm.getNumCategories(nodes[j]);
List<String> categories = new LinkedList<>();
for (int k = 0; k < numCategories; k++) {
categories.add(bayesPm.getCategory(nodes[j], k));
}
DiscreteVariable var = new DiscreteVariable(nodes[j].getName(), categories);
variables.add(var);
int index = ++numMeasured - 1;
map[index] = j;
}
DataSet dataSet = new ColtDataSet(sampleSize, variables);
constructSample(sampleSize, randomUtil, numMeasured, dataSet, map);
return dataSet;
}
use of edu.cmu.tetrad.data.ColtDataSet in project tetrad by cmu-phil.
the class GraphComparisonParams method newExecution.
// ==========================PUBLIC METHODS===========================//
public final void newExecution() {
ContinuousVariable adjCorrect = new ContinuousVariable("ADJ_COR");
ContinuousVariable adjFn = new ContinuousVariable("ADJ_FN");
ContinuousVariable adjFp = new ContinuousVariable("ADJ_FP");
ContinuousVariable arrowptCorrect = new ContinuousVariable("AHD_COR");
ContinuousVariable arrowptFn = new ContinuousVariable("AHD_FN");
ContinuousVariable arrowptFp = new ContinuousVariable("AHD_FP");
ContinuousVariable adjPrec = new ContinuousVariable("ADJ_PREC");
ContinuousVariable adjRec = new ContinuousVariable("ADJ_REC");
ContinuousVariable arrowptPrec = new ContinuousVariable("ARROWPT_PREC");
ContinuousVariable arrowptRec = new ContinuousVariable("ARROWPT_REC");
ContinuousVariable shd = new ContinuousVariable("SHD");
// ContinuousVariable twoCycleCorrect = new ContinuousVariable("TC_COR");
// ContinuousVariable twoCycleFn = new ContinuousVariable("TC_FN");
// ContinuousVariable twoCycleFp = new ContinuousVariable("TC_FP");
List<Node> variables = new LinkedList<>();
variables.add(adjCorrect);
variables.add(adjFn);
variables.add(adjFp);
variables.add(arrowptCorrect);
variables.add(arrowptFn);
variables.add(arrowptFp);
variables.add(adjPrec);
variables.add(adjRec);
variables.add(arrowptPrec);
variables.add(arrowptRec);
variables.add(shd);
// variables.add(twoCycleCorrect);
// variables.add(twoCycleFn);
// variables.add(twoCycleFp);
dataSet = new ColtDataSet(0, variables);
dataSet.setNumberFormat(new DecimalFormat("0"));
}
use of edu.cmu.tetrad.data.ColtDataSet in project tetrad by cmu-phil.
the class TestDataWrapper method testDataModelList.
@Test
public void testDataModelList() {
DataModelList modelList = new DataModelList();
List<Node> variables1 = new ArrayList<>();
for (int i = 0; i < 10; i++) {
variables1.add(new ContinuousVariable("X" + i));
}
List<Node> variables2 = new ArrayList<>();
for (int i = 0; i < 10; i++) {
variables2.add(new ContinuousVariable("X" + i));
}
DataSet first = new ColtDataSet(10, variables1);
first.setName("first");
DataSet second = new ColtDataSet(10, variables2);
second.setName("second");
modelList.add(first);
modelList.add(second);
assertTrue(modelList.contains(first));
assertTrue(modelList.contains(second));
modelList.setSelectedModel(second);
try {
DataModelList modelList2 = new MarshalledObject<>(modelList).get();
assertEquals("second", modelList2.getSelectedModel().getName());
} catch (Exception e) {
e.printStackTrace();
}
}
use of edu.cmu.tetrad.data.ColtDataSet in project tetrad by cmu-phil.
the class LogisticRegressionRunner method serializableInstance.
/**
* Generates a simple exemplar of this class to test serialization.
*
* @see TetradSerializableUtils
*/
public static LogisticRegressionRunner serializableInstance() {
List<Node> variables = new LinkedList<>();
ContinuousVariable var1 = new ContinuousVariable("X");
ContinuousVariable var2 = new ContinuousVariable("Y");
variables.add(var1);
variables.add(var2);
DataSet dataSet = new ColtDataSet(3, variables);
double[] col1data = new double[] { 0.0, 1.0, 2.0 };
double[] col2data = new double[] { 2.3, 4.3, 2.5 };
for (int i = 0; i < 3; i++) {
dataSet.setDouble(i, 0, col1data[i]);
dataSet.setDouble(i, 1, col2data[i]);
}
DataWrapper dataWrapper = new DataWrapper(dataSet);
return new LogisticRegressionRunner(dataWrapper, new Parameters());
}
use of edu.cmu.tetrad.data.ColtDataSet 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());
}
}
Aggregations