Search in sources :

Example 86 with DataSet

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

the class TestLingamPattern method test1.

@Test
public void test1() {
    RandomUtil.getInstance().setSeed(4938492L);
    int sampleSize = 1000;
    List<Node> nodes = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
        nodes.add(new ContinuousVariable("X" + (i + 1)));
    }
    Graph graph = new Dag(GraphUtils.randomGraph(nodes, 0, 6, 4, 4, 4, false));
    List<Distribution> variableDistributions = new ArrayList<>();
    variableDistributions.add(new Normal(0, 1));
    variableDistributions.add(new Normal(0, 1));
    variableDistributions.add(new Normal(0, 1));
    variableDistributions.add(new Uniform(-1, 1));
    variableDistributions.add(new Normal(0, 1));
    variableDistributions.add(new Normal(0, 1));
    SemPm semPm = new SemPm(graph);
    SemIm semIm = new SemIm(semPm);
    DataSet dataSet = simulateDataNonNormal(semIm, sampleSize, variableDistributions);
    Score score = new SemBicScore(new CovarianceMatrixOnTheFly(dataSet));
    Graph estPattern = new Fges(score).search();
    LingamPattern lingam = new LingamPattern(estPattern, dataSet);
    lingam.search();
    double[] pvals = lingam.getPValues();
    double[] expectedPVals = { 0.18, 0.29, 0.88, 0.00, 0.01, 0.58 };
    for (int i = 0; i < pvals.length; i++) {
        assertEquals(expectedPVals[i], pvals[i], 0.01);
    }
}
Also used : ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Uniform(edu.cmu.tetrad.util.dist.Uniform) Normal(edu.cmu.tetrad.util.dist.Normal) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) Distribution(edu.cmu.tetrad.util.dist.Distribution) SemPm(edu.cmu.tetrad.sem.SemPm) CovarianceMatrixOnTheFly(edu.cmu.tetrad.data.CovarianceMatrixOnTheFly) SemIm(edu.cmu.tetrad.sem.SemIm) Test(org.junit.Test)

Example 87 with DataSet

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

the class TestSemIm method test5.

@Test
public void test5() {
    Graph graph = new EdgeListGraph();
    Node x = new GraphNode("X");
    Node y = new GraphNode("Y");
    Node z = new GraphNode("Z");
    graph.addNode(x);
    graph.addNode(y);
    graph.addNode(z);
    Node lx = new GraphNode("LX");
    lx.setNodeType(NodeType.LATENT);
    Node ly = new GraphNode("LY");
    ly.setNodeType(NodeType.LATENT);
    Node lz = new GraphNode("LZ");
    lz.setNodeType(NodeType.LATENT);
    graph.addNode(lx);
    graph.addNode(ly);
    graph.addNode(lz);
    graph.addDirectedEdge(lx, x);
    graph.addDirectedEdge(ly, y);
    graph.addDirectedEdge(lz, z);
    graph.addDirectedEdge(lx, ly);
    graph.addDirectedEdge(ly, lz);
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    // DataSet data = im.simulateDataCholesky(1000, true);
    DataSet data = im.simulateDataReducedForm(1000, true);
    // DataSet data = im.simulateDataRecursive(1000, true);
    data.getCovarianceMatrix();
    im.getImplCovar(true);
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) Test(org.junit.Test)

Example 88 with DataSet

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

the class TestSemIm method testCovariancesOfSimulated.

@Test
public void testCovariancesOfSimulated() {
    List<Node> nodes = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        nodes.add(new ContinuousVariable("X" + (i + 1)));
    }
    Graph randomGraph = new Dag(GraphUtils.randomGraph(nodes, 0, 8, 30, 15, 15, false));
    SemPm semPm1 = new SemPm(randomGraph);
    SemIm semIm1 = new SemIm(semPm1);
    TetradMatrix implCovarC = semIm1.getImplCovar(true);
    implCovarC.toArray();
    DataSet dataSet = semIm1.simulateDataRecursive(1000, false);
    new CovarianceMatrix(dataSet);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) DataSet(edu.cmu.tetrad.data.DataSet) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) Test(org.junit.Test)

Example 89 with DataSet

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

the class LogisticRegressionRunner method execute.

// =================PUBLIC METHODS OVERRIDING ABSTRACT=================//
/**
 * Executes the algorithm, producing (at least) a result workbench. Must be
 * implemented in the extending class.
 */
public void execute() {
    outGraph = new EdgeListGraph();
    if (regressorNames == null || regressorNames.isEmpty() || targetName == null) {
        report = "Response and predictor variables not set.";
        return;
    }
    if (regressorNames.contains(targetName)) {
        report = "Response must not be a predictor.";
        return;
    }
    DataSet regressorsDataSet = dataSets.get(getModelIndex()).copy();
    Node target = regressorsDataSet.getVariable(targetName);
    regressorsDataSet.removeColumn(target);
    List<String> names = regressorsDataSet.getVariableNames();
    // Get the list of regressors selected by the user
    List<Node> regressorNodes = new ArrayList<>();
    for (String s : regressorNames) {
        regressorNodes.add(dataSets.get(getModelIndex()).getVariable(s));
    }
    // If the user selected none, use them all
    if (regressorNames.size() > 0) {
        for (String name1 : names) {
            Node regressorVar = regressorsDataSet.getVariable(name1);
            if (!regressorNames.contains(regressorVar.getName())) {
                regressorsDataSet.removeColumn(regressorVar);
            }
        }
    }
    int ncases = regressorsDataSet.getNumRows();
    int nvars = regressorsDataSet.getNumColumns();
    double[][] regressors = new double[nvars][ncases];
    for (int i = 0; i < nvars; i++) {
        for (int j = 0; j < ncases; j++) {
            regressors[i][j] = regressorsDataSet.getDouble(j, i);
        }
    }
    LogisticRegression logRegression = new LogisticRegression(dataSets.get(getModelIndex()));
    logRegression.setAlpha(alpha);
    this.result = logRegression.regress((DiscreteVariable) target, regressorNodes);
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) ArrayList(java.util.ArrayList) LogisticRegression(edu.cmu.tetrad.regression.LogisticRegression)

Example 90 with DataSet

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

the class ConcatenateDatasetsWrapper method construct.

private void construct(DataWrapper... dataWrappers) {
    for (DataWrapper wrapper : dataWrappers) {
        if (wrapper == null) {
            throw new NullPointerException("The given data must not be null");
        }
    }
    List<DataSet> dataSets = new ArrayList<>();
    for (DataWrapper wrapper : dataWrappers) {
        for (DataModel model : wrapper.getDataModelList()) {
            if (!(model instanceof DataSet)) {
                throw new IllegalArgumentException("Sorry, I am only willing to concatenate tabular datasets.");
            }
            DataSet dataSet = (DataSet) model;
            dataSets.add(dataSet);
        }
    }
    DataSet concatenated = DataUtils.concatenate(dataSets);
    concatenated.setName("Concatenated");
    this.setDataModel(concatenated);
    LogDataUtils.logDataModelList("Parent data in which constant columns have been removed.", getDataModelList());
}
Also used : DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) ArrayList(java.util.ArrayList)

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