Search in sources :

Example 16 with ColtDataSet

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;
}
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) Node(edu.cmu.tetrad.graph.Node)

Example 17 with ColtDataSet

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"));
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) Node(edu.cmu.tetrad.graph.Node) DecimalFormat(java.text.DecimalFormat) LinkedList(java.util.LinkedList)

Example 18 with ColtDataSet

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();
    }
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataModelList(edu.cmu.tetrad.data.DataModelList) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 19 with ColtDataSet

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());
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) Parameters(edu.cmu.tetrad.util.Parameters) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) LinkedList(java.util.LinkedList)

Example 20 with ColtDataSet

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

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