Search in sources :

Example 16 with SemEstimator

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

the class SemEstimatorWrapper method setParams.

private boolean setParams(SemPmWrapper semPmWrapper, DataModelList dataModel) {
    for (DataModel model : dataModel) {
        if (model instanceof DataSet) {
            DataSet dataSet = (DataSet) model;
            SemPm semPm = semPmWrapper.getSemPm();
            this.semPm = semPm;
            SemEstimator estimator = new SemEstimator(dataSet, semPm, getOptimizer());
            estimator.setNumRestarts(getParams().getInt("numRestarts", 1));
            estimator.setScoreType((ScoreType) getParams().get("scoreType", ScoreType.Fgls));
            if (!degreesOfFreedomCheck(semPm)) {
                return true;
            }
            estimator.estimate();
            getMultipleResultList().add(estimator);
        } else if (model instanceof ICovarianceMatrix) {
            ICovarianceMatrix covMatrix = new CovarianceMatrix((ICovarianceMatrix) model);
            SemPm semPm = semPmWrapper.getSemPm();
            this.semPm = semPm;
            SemEstimator estimator = new SemEstimator(covMatrix, semPm, getOptimizer());
            estimator.setNumRestarts(getParams().getInt("numRestarts", 1));
            estimator.setScoreType((ScoreType) getParams().get("scoreType", ScoreType.Fgls));
            if (!degreesOfFreedomCheck(semPm)) {
                return true;
            }
            estimator.estimate();
            getMultipleResultList().add(estimator);
        } else {
            throw new IllegalArgumentException("Data must consist of continuous data sets or covariance matrices.");
        }
    }
    return false;
}
Also used : ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) ScoreType(edu.cmu.tetrad.sem.ScoreType) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix)

Example 17 with SemEstimator

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

the class TestStandardizedSem method test1.

// Test the code that standardizes a data set.
@Test
public void test1() {
    List<Node> nodes = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        nodes.add(new ContinuousVariable("X" + (i + 1)));
    }
    SemGraph graph = new SemGraph(new Dag(GraphUtils.randomGraph(nodes, 0, 5, 30, 15, 15, false)));
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet dataSet = im.simulateData(1000, false);
    TetradMatrix _dataSet = dataSet.getDoubleData();
    _dataSet = DataUtils.standardizeData(_dataSet);
    DataSet dataSetStandardized = ColtDataSet.makeData(dataSet.getVariables(), _dataSet);
    DataUtils.cov(_dataSet);
    DataUtils.mean(_dataSet);
    SemEstimator estimator = new SemEstimator(dataSetStandardized, pm);
    SemIm imStandardized = estimator.estimate();
    imStandardized.getEdgeCoef();
    imStandardized.getErrCovar();
    new TetradVector(imStandardized.getMeans());
    imStandardized.getEdgeCoef();
    imStandardized.getErrCovar();
    StandardizedSemIm sem = new StandardizedSemIm(im);
    imStandardized.getEdgeCoef();
    imStandardized.getErrCovar();
    assertTrue(isStandardized(sem));
}
Also used : ArrayList(java.util.ArrayList) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm) TetradVector(edu.cmu.tetrad.util.TetradVector) SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) StandardizedSemIm(edu.cmu.tetrad.sem.StandardizedSemIm) Test(org.junit.Test)

Example 18 with SemEstimator

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

the class GraphWithParameters method regress.

/**
 * creates a PatternWithParameters by running a regression, given a graph and data
 */
public static GraphWithParameters regress(DataSet dataSet, Graph graph) {
    SemPm semPmEstDag = new SemPm(graph);
    SemEstimator estimatorEstDag = new SemEstimator(dataSet, semPmEstDag);
    estimatorEstDag.estimate();
    SemIm semImEstDag = estimatorEstDag.getEstimatedSem();
    GraphWithParameters estimatedGraph = new GraphWithParameters(semImEstDag, graph);
    return estimatedGraph;
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm)

Aggregations

SemEstimator (edu.cmu.tetrad.sem.SemEstimator)18 SemPm (edu.cmu.tetrad.sem.SemPm)16 SemIm (edu.cmu.tetrad.sem.SemIm)15 DataSet (edu.cmu.tetrad.data.DataSet)6 Test (org.junit.Test)6 Graph (edu.cmu.tetrad.graph.Graph)4 Node (edu.cmu.tetrad.graph.Node)4 StandardizedSemIm (edu.cmu.tetrad.sem.StandardizedSemIm)4 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)3 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)3 GraphNode (edu.cmu.tetrad.graph.GraphNode)3 Parameter (edu.cmu.tetrad.sem.Parameter)3 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)3 NumberFormat (java.text.NumberFormat)3 ArrayList (java.util.ArrayList)2 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)1 CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)1 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)1 DataModel (edu.cmu.tetrad.data.DataModel)1 Dag (edu.cmu.tetrad.graph.Dag)1