Search in sources :

Example 1 with StandardizedSemIm

use of edu.cmu.tetrad.sem.StandardizedSemIm in project tetrad by cmu-phil.

the class StandardizedSemSimulation method simulate.

private DataSet simulate(Graph graph, Parameters parameters) {
    if (standardizedIm == null) {
        SemPm pm = this.pm;
        if (pm == null) {
            pm = new SemPm(graph);
        }
        standardizedIm = new StandardizedSemIm(new SemIm(pm));
    }
    return standardizedIm.simulateData(parameters.getInt("sampleSize"), false);
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm)

Example 2 with StandardizedSemIm

use of edu.cmu.tetrad.sem.StandardizedSemIm in project tetrad by cmu-phil.

the class TestStandardizedSem method rtest8.

public void rtest8() {
    // RandomUtil.getInstance().setSeed(2958442283L);
    SemGraph graph = new SemGraph();
    Node x = new ContinuousVariable("X");
    Node y = new ContinuousVariable("Y");
    Node z = new ContinuousVariable("Z");
    graph.addNode(x);
    graph.addNode(y);
    graph.addNode(z);
    graph.addDirectedEdge(x, y);
    graph.addBidirectedEdge(x, y);
    graph.addDirectedEdge(x, z);
    graph.addDirectedEdge(y, z);
    graph.setShowErrorTerms(true);
    SemPm semPm = new SemPm(graph);
    SemIm semIm = new SemIm(semPm);
    StandardizedSemIm sem = new StandardizedSemIm(semIm, StandardizedSemIm.Initialization.CALCULATE_FROM_SEM);
    DataSet data = semIm.simulateDataCholesky(1000, false);
    data = ColtDataSet.makeContinuousData(data.getVariables(), DataUtils.standardizeData(data.getDoubleData()));
    SemEstimator estimator = new SemEstimator(data, semPm);
    semIm = estimator.estimate();
    DataSet data2 = semIm.simulateDataReducedForm(1000, false);
    DataSet data3 = sem.simulateDataReducedForm(1000, false);
    StandardizedSemIm.ParameterRange range2 = sem.getCovarianceRange(x, y);
    double high = range2.getHigh();
    double low = range2.getLow();
    if (high == Double.POSITIVE_INFINITY)
        high = 1000;
    if (low == Double.NEGATIVE_INFINITY)
        low = -1000;
    double coef = low + RandomUtil.getInstance().nextDouble() * (high - low);
    assertTrue(sem.setErrorCovariance(x, y, coef));
    assertTrue(isStandardized(sem));
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm)

Example 3 with StandardizedSemIm

use of edu.cmu.tetrad.sem.StandardizedSemIm in project tetrad by cmu-phil.

the class TestStandardizedSem method test5.

@Test
public void test5() {
    RandomUtil.getInstance().setSeed(582374923L);
    SemGraph graph = new SemGraph();
    graph.setShowErrorTerms(true);
    Node x1 = new ContinuousVariable("X1");
    Node x2 = new ContinuousVariable("X2");
    Node x3 = new ContinuousVariable("X3");
    graph.addNode(x1);
    graph.addNode(x2);
    graph.addNode(x3);
    graph.setShowErrorTerms(true);
    Node ex1 = graph.getExogenous(x1);
    Node ex2 = graph.getExogenous(x2);
    Node ex3 = graph.getExogenous(x3);
    graph.addDirectedEdge(x1, x3);
    graph.addDirectedEdge(x2, x3);
    // graph.addDirectedEdge(x1, x2);
    // graph.addBidirectedEdge(ex1, ex2);
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet dataSet = im.simulateDataRecursive(1000, false);
    TetradMatrix _dataSet = dataSet.getDoubleData();
    _dataSet = DataUtils.standardizeData(_dataSet);
    DataSet dataSetStandardized = ColtDataSet.makeData(dataSet.getVariables(), _dataSet);
    SemEstimator estimator = new SemEstimator(dataSetStandardized, im.getSemPm());
    SemIm imStandardized = estimator.estimate();
    StandardizedSemIm sem = new StandardizedSemIm(im);
    // sem.setErrorCovariance(ex1, ex2, -.24);
    assertTrue(isStandardized(sem));
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm) Test(org.junit.Test)

Example 4 with StandardizedSemIm

use of edu.cmu.tetrad.sem.StandardizedSemIm in project tetrad by cmu-phil.

the class TestStandardizedSem method test2.

@Test
public void test2() {
    RandomUtil.getInstance().setSeed(5729384723L);
    SemGraph graph = new SemGraph();
    Node x1 = new ContinuousVariable("X1");
    Node x2 = new ContinuousVariable("X2");
    Node x3 = new ContinuousVariable("X3");
    Node x4 = new ContinuousVariable("X4");
    Node x5 = new ContinuousVariable("X5");
    graph.addNode(x1);
    graph.addNode(x2);
    graph.addNode(x3);
    graph.addNode(x4);
    graph.addNode(x5);
    graph.setShowErrorTerms(true);
    graph.addDirectedEdge(x1, x2);
    graph.addDirectedEdge(x2, x3);
    graph.addDirectedEdge(x4, x3);
    graph.addDirectedEdge(x2, x4);
    graph.addDirectedEdge(x1, x4);
    graph.addDirectedEdge(x5, x4);
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    StandardizedSemIm sem = new StandardizedSemIm(im);
    assertTrue(isStandardized(sem));
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm) Test(org.junit.Test)

Example 5 with StandardizedSemIm

use of edu.cmu.tetrad.sem.StandardizedSemIm in project tetrad by cmu-phil.

the class TestStandardizedSem method test6.

@Test
public void test6() {
    // RandomUtil.getInstance().setSeed(582374923L);
    SemGraph graph = new SemGraph();
    graph.setShowErrorTerms(true);
    Node x1 = new ContinuousVariable("X1");
    Node x2 = new ContinuousVariable("X2");
    Node x3 = new ContinuousVariable("X3");
    graph.addNode(x1);
    graph.addNode(x2);
    graph.addNode(x3);
    graph.setShowErrorTerms(true);
    Node ex1 = graph.getExogenous(x1);
    Node ex2 = graph.getExogenous(x2);
    Node ex3 = graph.getExogenous(x3);
    graph.addDirectedEdge(x1, x3);
    graph.addDirectedEdge(x2, x3);
    graph.addDirectedEdge(x1, x2);
    graph.addBidirectedEdge(ex1, ex2);
    // List<List<Node>> treks = DataGraphUtils.treksIncludingBidirected(graph, x1, x3);
    // 
    // for (List<Node> trek : treks) {
    // System.out.println(trek);
    // }
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet dataSet = im.simulateDataRecursive(1000, false);
    TetradMatrix _dataSet = dataSet.getDoubleData();
    _dataSet = DataUtils.standardizeData(_dataSet);
    DataSet dataSetStandardized = ColtDataSet.makeData(dataSet.getVariables(), _dataSet);
    SemEstimator estimator = new SemEstimator(dataSetStandardized, im.getSemPm());
    SemIm imStandardized = estimator.estimate();
    StandardizedSemIm sem = new StandardizedSemIm(im);
    assertTrue(isStandardized(sem));
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm) Test(org.junit.Test)

Aggregations

SemIm (edu.cmu.tetrad.sem.SemIm)9 SemPm (edu.cmu.tetrad.sem.SemPm)9 StandardizedSemIm (edu.cmu.tetrad.sem.StandardizedSemIm)9 Test (org.junit.Test)7 SemEstimator (edu.cmu.tetrad.sem.SemEstimator)4 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)3 ArrayList (java.util.ArrayList)3 RandomUtil (edu.cmu.tetrad.util.RandomUtil)2 TetradVector (edu.cmu.tetrad.util.TetradVector)1