Search in sources :

Example 1 with SemOptimizer

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

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

Example 3 with SemOptimizer

use of edu.cmu.tetrad.sem.SemOptimizer 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)3 SemOptimizerEm (edu.cmu.tetrad.sem.SemOptimizerEm)3 SemOptimizerPowell (edu.cmu.tetrad.sem.SemOptimizerPowell)3 SemOptimizerRegression (edu.cmu.tetrad.sem.SemOptimizerRegression)3 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 Node (edu.cmu.tetrad.graph.Node)1 SemEstimator (edu.cmu.tetrad.sem.SemEstimator)1 SemPm (edu.cmu.tetrad.sem.SemPm)1 ArrayList (java.util.ArrayList)1