Search in sources :

Example 61 with DataSet

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

the class SemSimulation method createData.

@Override
public void createData(Parameters parameters) {
    Graph graph = randomGraph.createGraph(parameters);
    dataSets = new ArrayList<>();
    graphs = new ArrayList<>();
    ims = new ArrayList<>();
    for (int i = 0; i < parameters.getInt("numRuns"); i++) {
        System.out.println("Simulating dataset #" + (i + 1));
        if (parameters.getBoolean("differentGraphs") && i > 0) {
            graph = randomGraph.createGraph(parameters);
        }
        graphs.add(graph);
        DataSet dataSet = simulate(graph, parameters);
        if (parameters.getBoolean("standardize")) {
            dataSet = DataUtils.standardizeData(dataSet);
        }
        double variance = parameters.getDouble("measurementVariance");
        if (variance > 0) {
            for (int k = 0; k < dataSet.getNumRows(); k++) {
                for (int j = 0; j < dataSet.getNumColumns(); j++) {
                    double d = dataSet.getDouble(k, j);
                    double norm = RandomUtil.getInstance().nextNormal(0, Math.sqrt(variance));
                    dataSet.setDouble(k, j, d + norm);
                }
            }
        }
        if (parameters.getBoolean("randomizeColumns")) {
            dataSet = DataUtils.reorderColumns(dataSet);
        }
        dataSet.setName("" + (i + 1));
        dataSets.add(dataSet);
    }
}
Also used : SemGraph(edu.cmu.tetrad.graph.SemGraph) Graph(edu.cmu.tetrad.graph.Graph) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) SingleGraph(edu.cmu.tetrad.algcomparison.graph.SingleGraph) DataSet(edu.cmu.tetrad.data.DataSet)

Example 62 with DataSet

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

the class BayesNetSimulation method createData.

@Override
public void createData(Parameters parameters) {
    Graph graph = randomGraph.createGraph(parameters);
    dataSets = new ArrayList<>();
    graphs = new ArrayList<>();
    for (int i = 0; i < parameters.getInt("numRuns"); i++) {
        System.out.println("Simulating dataset #" + (i + 1));
        if (parameters.getBoolean("differentGraphs") && i > 0) {
            graph = randomGraph.createGraph(parameters);
        }
        graphs.add(graph);
        DataSet dataSet = simulate(graph, parameters);
        dataSet.setName("" + (i + 1));
        dataSets.add(dataSet);
    }
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) SingleGraph(edu.cmu.tetrad.algcomparison.graph.SingleGraph) DataSet(edu.cmu.tetrad.data.DataSet)

Example 63 with DataSet

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

the class SemThenDiscretize method createData.

@Override
public void createData(Parameters parameters) {
    double percentDiscrete = parameters.getDouble("percentDiscrete");
    boolean discrete = parameters.getString("dataType").equals("discrete");
    boolean continuous = parameters.getString("dataType").equals("continuous");
    if (discrete && percentDiscrete != 100.0) {
        throw new IllegalArgumentException("To simulate discrete data, 'percentDiscrete' must be set to 0.0.");
    } else if (continuous && percentDiscrete != 0.0) {
        throw new IllegalArgumentException("To simulate continuoue data, 'percentDiscrete' must be set to 100.0.");
    }
    if (discrete)
        this.dataType = DataType.Discrete;
    if (continuous)
        this.dataType = DataType.Continuous;
    dataSets = new ArrayList<>();
    shuffledOrder = null;
    Graph graph = randomGraph.createGraph(parameters);
    dataSets = new ArrayList<>();
    graphs = new ArrayList<>();
    for (int i = 0; i < parameters.getInt("numRuns"); i++) {
        System.out.println("Simulating dataset #" + (i + 1));
        if (parameters.getBoolean("differentGraphs") && i > 0) {
            graph = randomGraph.createGraph(parameters);
        }
        graphs.add(graph);
        DataSet dataSet = simulate(graph, parameters);
        dataSet.setName("" + (i + 1));
        dataSets.add(dataSet);
    }
}
Also used : Graph(edu.cmu.tetrad.graph.Graph) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) DataSet(edu.cmu.tetrad.data.DataSet)

Example 64 with DataSet

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

the class BuildPureClustersParamsEditor method setup.

public void setup() {
    DoubleTextField alphaField = new DoubleTextField(params.getDouble("alpha", 0.001), 4, NumberFormatUtil.getInstance().getNumberFormat());
    alphaField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                getParams().set("alpha", 0.001);
                return value;
            } catch (Exception e) {
                return oldValue;
            }
        }
    });
    final TestType[] descriptions = TestType.getTestDescriptions();
    JComboBox testSelector = new JComboBox(descriptions);
    testSelector.setSelectedItem(getParams().get("tetradTestType", TestType.TETRAD_WISHART));
    testSelector.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JComboBox combo = (JComboBox) e.getSource();
            TestType testType = (TestType) combo.getSelectedItem();
            getParams().set("tetradTestType", testType);
        }
    });
    final TestType[] purifyDescriptions = TestType.getPurifyTestDescriptions();
    JComboBox purifySelector = new JComboBox(purifyDescriptions);
    purifySelector.setSelectedItem(getParams().get("purifyTestType", TestType.NONE));
    purifySelector.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JComboBox combo = (JComboBox) e.getSource();
            TestType testType = (TestType) combo.getSelectedItem();
            getParams().set("purifyTestType", testType);
        }
    });
    // Where is it setting the appropriate knowledge for the search?
    DataModel dataModel = null;
    for (Object parentModel : this.parentModels) {
        if (parentModel instanceof DataWrapper) {
            DataWrapper dataWrapper = (DataWrapper) parentModel;
            dataModel = dataWrapper.getSelectedDataModel();
        }
    }
    if (dataModel == null) {
        throw new IllegalStateException("Null data model.");
    }
    List<String> varNames = new ArrayList<>(dataModel.getVariableNames());
    boolean isDiscreteModel;
    if (dataModel instanceof ICovarianceMatrix) {
        isDiscreteModel = false;
    } else {
        DataSet dataSet = (DataSet) dataModel;
        isDiscreteModel = dataSet.isDiscrete();
    // try {
    // new DataSet((DataSet) dataModel);
    // isDiscreteModel = true;
    // }
    // catch (IllegalArgumentException e) {
    // isDiscreteModel = false;
    // }
    }
    params.set("varNames", varNames);
    alphaField.setValue(params.getDouble("alpha", 0.001));
    Box b = Box.createVerticalBox();
    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Alpha:"));
    b1.add(Box.createHorizontalGlue());
    b1.add(alphaField);
    b.add(b1);
    if (!isDiscreteModel) {
        Box b2 = Box.createHorizontalBox();
        b2.add(new JLabel("Statistical Test:"));
        b2.add(Box.createHorizontalGlue());
        b2.add(testSelector);
        b.add(b2);
        Box b3 = Box.createHorizontalBox();
        b3.add(new JLabel("Purify Test:"));
        b3.add(Box.createHorizontalGlue());
        b3.add(purifySelector);
        b.add(b3);
    } else {
        this.params.set("purifyTestType", TestType.DISCRETE_LRT);
        this.params.set("tetradTestType", TestType.DISCRETE);
    }
    setLayout(new BorderLayout());
    add(b, BorderLayout.CENTER);
}
Also used : DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) DataSet(edu.cmu.tetrad.data.DataSet) ActionEvent(java.awt.event.ActionEvent) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) ArrayList(java.util.ArrayList) TestType(edu.cmu.tetrad.search.TestType) DataWrapper(edu.cmu.tetradapp.model.DataWrapper) ActionListener(java.awt.event.ActionListener) DataModel(edu.cmu.tetrad.data.DataModel)

Example 65 with DataSet

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

the class CalculatorEditor method setParentModels.

/**
 * Grabs the data set that the calculator is working on.
 */
public void setParentModels(Object[] parentModels) {
    if (parentModels == null || parentModels.length == 0) {
        throw new IllegalArgumentException("There must be parent model");
    }
    DataWrapper data = null;
    for (Object parent : parentModels) {
        if (parent instanceof DataWrapper) {
            data = (DataWrapper) parent;
        }
    }
    if (data == null) {
        throw new IllegalArgumentException("Should have have a data wrapper as a parent");
    }
    DataModel model = data.getSelectedDataModel();
    if (!(model instanceof DataSet)) {
        throw new IllegalArgumentException("The data must be tabular");
    }
    this.dataSet = (DataSet) model;
}
Also used : DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel)

Aggregations

DataSet (edu.cmu.tetrad.data.DataSet)216 Test (org.junit.Test)65 Graph (edu.cmu.tetrad.graph.Graph)64 Node (edu.cmu.tetrad.graph.Node)60 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)48 ArrayList (java.util.ArrayList)45 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)36 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)32 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)29 SemIm (edu.cmu.tetrad.sem.SemIm)28 SemPm (edu.cmu.tetrad.sem.SemPm)28 BootstrapEdgeEnsemble (edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble)26 DataModel (edu.cmu.tetrad.data.DataModel)22 Parameters (edu.cmu.tetrad.util.Parameters)22 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)20 File (java.io.File)16 ParseException (java.text.ParseException)16 LinkedList (java.util.LinkedList)14 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)13 DMSearch (edu.cmu.tetrad.search.DMSearch)10