use of edu.cmu.tetrad.sem.SemOptimizerPowell in project tetrad by cmu-phil.
the class SemEstimatorEditor method reestimate.
private void reestimate() {
SemOptimizer optimizer;
String type = wrapper.getSemOptimizerType();
switch(type) {
case "Regression":
optimizer = new SemOptimizerRegression();
break;
case "EM":
optimizer = new SemOptimizerEm();
break;
case "Powell":
optimizer = new SemOptimizerPowell();
break;
case "Random Search":
optimizer = new SemOptimizerScattershot();
break;
case "RICF":
optimizer = new SemOptimizerRicf();
break;
default:
throw new IllegalArgumentException("Unexpected optimizer type: " + type);
}
int numRestarts = wrapper.getNumRestarts();
optimizer.setNumRestarts(numRestarts);
java.util.List<SemEstimator> estimators = wrapper.getMultipleResultList();
java.util.List<SemEstimator> newEstimators = new ArrayList<>();
estimators.forEach(estimator -> {
SemPm semPm = estimator.getSemPm();
DataSet dataSet = estimator.getDataSet();
ICovarianceMatrix covMatrix = estimator.getCovMatrix();
SemEstimator newEstimator;
if (dataSet != null) {
newEstimator = new SemEstimator(dataSet, semPm, optimizer);
newEstimator.setNumRestarts(numRestarts);
newEstimator.setScoreType(wrapper.getScoreType());
} else if (covMatrix != null) {
newEstimator = new SemEstimator(covMatrix, semPm, optimizer);
newEstimator.setNumRestarts(numRestarts);
newEstimator.setScoreType(wrapper.getScoreType());
} else {
throw new IllegalStateException("Only continuous rectangular" + " data sets and covariance matrices can be processed.");
}
newEstimator.estimate();
newEstimators.add(newEstimator);
});
wrapper.setSemEstimator(newEstimators.get(0));
wrapper.setMultipleResultList(newEstimators);
resetSemImEditor();
}
use of edu.cmu.tetrad.sem.SemOptimizerPowell in project tetrad by cmu-phil.
the class SemEstimatorWrapper method getDefaultOptimization.
private SemOptimizer getDefaultOptimization() {
if (semPm == null) {
throw new NullPointerException("Sorry, I didn't see a SEM PM as parent to the estimator; perhaps the parents are wrong.");
}
boolean containsLatent = false;
for (Node node : semPm.getGraph().getNodes()) {
if (node.getNodeType() == NodeType.LATENT) {
containsLatent = true;
break;
}
}
SemOptimizer optimizer;
if (containsFixedParam(semPm) || semPm.getGraph().existsDirectedCycle() || containsCovarParam(semPm)) {
optimizer = new SemOptimizerPowell();
} else if (containsLatent) {
optimizer = new SemOptimizerEm();
} else {
optimizer = new SemOptimizerRegression();
}
optimizer.setNumRestarts(getParams().getInt("numRestarts", 1));
return optimizer;
// optimizer.optimize(semIm);
// this.semOptimizer = optimizer;
}
use of edu.cmu.tetrad.sem.SemOptimizerPowell in project tetrad by cmu-phil.
the class SemEstimatorWrapper method getOptimizer.
private SemOptimizer getOptimizer() {
SemOptimizer optimizer;
String type = getParams().getString("semOptimizerType", "Regression");
if ("Regression".equals(type)) {
SemOptimizer defaultOptimization = getDefaultOptimization();
if (!(defaultOptimization instanceof SemOptimizerRegression)) {
optimizer = defaultOptimization;
type = getType(defaultOptimization);
getParams().set("semOptimizerType", type);
} else {
optimizer = new SemOptimizerRegression();
}
} else if ("EM".equals(type)) {
optimizer = new SemOptimizerEm();
} else if ("Powell".equals(type)) {
optimizer = new SemOptimizerPowell();
} else if ("Random Search".equals(type)) {
optimizer = new SemOptimizerScattershot();
} else if ("RICF".equals(type)) {
optimizer = new SemOptimizerRicf();
} else if ("Powell".equals(type)) {
optimizer = new SemOptimizerPowell();
} else {
if (semPm != null) {
optimizer = getDefaultOptimization();
String _type = getType(optimizer);
if (_type != null) {
getParams().set("semOptimizerType", _type);
}
} else {
optimizer = null;
}
}
return optimizer;
}
Aggregations