Search in sources :

Example 1 with SemOptimizerScattershot

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();
}
Also used : SemOptimizerScattershot(edu.cmu.tetrad.sem.SemOptimizerScattershot) SemOptimizerRicf(edu.cmu.tetrad.sem.SemOptimizerRicf) DataSet(edu.cmu.tetrad.data.DataSet) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) SemOptimizerRegression(edu.cmu.tetrad.sem.SemOptimizerRegression) SemOptimizerEm(edu.cmu.tetrad.sem.SemOptimizerEm) ArrayList(java.util.ArrayList) SemOptimizerPowell(edu.cmu.tetrad.sem.SemOptimizerPowell) SemOptimizer(edu.cmu.tetrad.sem.SemOptimizer) SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator)

Example 2 with SemOptimizerScattershot

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;
}
Also used : SemOptimizerPowell(edu.cmu.tetrad.sem.SemOptimizerPowell) SemOptimizer(edu.cmu.tetrad.sem.SemOptimizer) SemOptimizerScattershot(edu.cmu.tetrad.sem.SemOptimizerScattershot) SemOptimizerRicf(edu.cmu.tetrad.sem.SemOptimizerRicf) SemOptimizerRegression(edu.cmu.tetrad.sem.SemOptimizerRegression) SemOptimizerEm(edu.cmu.tetrad.sem.SemOptimizerEm)

Aggregations

SemOptimizer (edu.cmu.tetrad.sem.SemOptimizer)2 SemOptimizerEm (edu.cmu.tetrad.sem.SemOptimizerEm)2 SemOptimizerPowell (edu.cmu.tetrad.sem.SemOptimizerPowell)2 SemOptimizerRegression (edu.cmu.tetrad.sem.SemOptimizerRegression)2 SemOptimizerRicf (edu.cmu.tetrad.sem.SemOptimizerRicf)2 SemOptimizerScattershot (edu.cmu.tetrad.sem.SemOptimizerScattershot)2 DataSet (edu.cmu.tetrad.data.DataSet)1 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)1 SemEstimator (edu.cmu.tetrad.sem.SemEstimator)1 SemPm (edu.cmu.tetrad.sem.SemPm)1 ArrayList (java.util.ArrayList)1