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