use of edu.cmu.tetrad.sem.SemOptimizerScattershot 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.SemOptimizerScattershot 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