Search in sources :

Example 1 with ICovarianceMatrix

use of edu.cmu.tetrad.data.ICovarianceMatrix in project tetrad by cmu-phil.

the class MimbuildEditor method getIndTestParamBox.

/**
 * Factory to return the correct param editor for independence test params.
 * This will go in a little box in the search editor.
 */
private JComponent getIndTestParamBox(Parameters params) {
    if (params == null) {
        throw new NullPointerException();
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        DataModel dataModel = runner.getData();
        if (dataModel instanceof DataSet) {
            DataSet data = (DataSet) runner.getData();
            boolean discrete = data.isDiscrete();
            return new BuildPureClustersIndTestParamsEditor2(params, discrete);
        } else if (dataModel instanceof ICovarianceMatrix) {
            return new BuildPureClustersIndTestParamsEditor2(params, false);
        }
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        boolean discreteData = false;
        if (runner.getData() instanceof DataSet) {
            discreteData = ((DataSet) runner.getData()).isDiscrete();
        }
        return new PurifyIndTestParamsEditor(params, discreteData);
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        return new MimBuildIndTestParamsEditor(params);
    }
    throw new IllegalArgumentException("Unrecognized Parameters: " + params.getClass());
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) MimRunner(edu.cmu.tetradapp.model.MimRunner)

Example 2 with ICovarianceMatrix

use of edu.cmu.tetrad.data.ICovarianceMatrix 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 3 with ICovarianceMatrix

use of edu.cmu.tetrad.data.ICovarianceMatrix in project tetrad by cmu-phil.

the class PurifyParamsEditor method setVarNames.

private boolean setVarNames(Object[] parentModels, Parameters params) {
    DataModel dataModel = null;
    for (Object parentModel : parentModels) {
        if (parentModel instanceof DataWrapper) {
            DataWrapper dataWrapper = (DataWrapper) parentModel;
            dataModel = dataWrapper.getSelectedDataModel();
        }
    }
    boolean discreteModel;
    if (dataModel instanceof ICovarianceMatrix) {
        discreteModel = false;
    } else {
        DataSet dataSet = (DataSet) dataModel;
        assert dataSet != null;
        discreteModel = dataSet.isDiscrete();
    // try {
    // new DataSet((DataSet) dataModel);
    // discreteModel = true;
    // }
    // catch (IllegalArgumentException e) {
    // discreteModel = false;
    // }
    }
    getParams().set("varNames", params.get("varNames", null));
    return discreteModel;
}
Also used : DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix)

Example 4 with ICovarianceMatrix

use of edu.cmu.tetrad.data.ICovarianceMatrix in project tetrad by cmu-phil.

the class MimSearchEditor2 method getIndTestParamBox.

/**
 * Factory to return the correct param editor for independence test params.
 * This will go in a little box in the search editor.
 */
private JComponent getIndTestParamBox(Parameters params) {
    if (params == null) {
        throw new NullPointerException();
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        DataModel dataModel = runner.getData();
        if (dataModel instanceof DataSet) {
            DataSet data = (DataSet) runner.getData();
            boolean discrete = data.isDiscrete();
            return new BuildPureClustersIndTestParamsEditor2(params, discrete);
        } else if (dataModel instanceof ICovarianceMatrix) {
            return new BuildPureClustersIndTestParamsEditor2(params, false);
        }
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        boolean discreteData = false;
        if (runner.getData() instanceof DataSet) {
            discreteData = ((DataSet) runner.getData()).isDiscrete();
        }
        return new PurifyIndTestParamsEditor(params, discreteData);
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        return new MimBuildIndTestParamsEditor(params);
    }
    throw new IllegalArgumentException("Unrecognized Parameters: " + params.getClass());
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) MimRunner(edu.cmu.tetradapp.model.MimRunner)

Example 5 with ICovarianceMatrix

use of edu.cmu.tetrad.data.ICovarianceMatrix in project tetrad by cmu-phil.

the class IndTestCramerT method indTestSubset.

// ==========================PUBLIC METHODS=============================//
/**
 * Creates a new IndTestCramerT instance for a subset of the variables.
 */
public IndependenceTest indTestSubset(List<Node> vars) {
    if (vars.isEmpty()) {
        throw new IllegalArgumentException("Subset may not be empty.");
    }
    for (Node var : vars) {
        if (!variables.contains(var)) {
            throw new IllegalArgumentException("All vars must be original vars");
        }
    }
    int[] indices = new int[vars.size()];
    for (int i = 0; i < indices.length; i++) {
        indices[i] = variables.indexOf(vars.get(i));
    }
    ICovarianceMatrix newCorrMatrix = covMatrix.getSubmatrix(indices);
    double alphaNew = getAlpha();
    return new IndTestCramerT(newCorrMatrix, alphaNew);
}
Also used : ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) Node(edu.cmu.tetrad.graph.Node)

Aggregations

ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)30 DataSet (edu.cmu.tetrad.data.DataSet)12 CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)10 ArrayList (java.util.ArrayList)9 DataModel (edu.cmu.tetrad.data.DataModel)8 Node (edu.cmu.tetrad.graph.Node)8 Graph (edu.cmu.tetrad.graph.Graph)7 SemPm (edu.cmu.tetrad.sem.SemPm)5 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)5 Test (org.junit.Test)5 Parameters (edu.cmu.tetrad.util.Parameters)4 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)3 SemIm (edu.cmu.tetrad.sem.SemIm)3 DoubleFactory2D (cern.colt.matrix.DoubleFactory2D)2 DoubleMatrix1D (cern.colt.matrix.DoubleMatrix1D)2 DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)2 DenseDoubleMatrix1D (cern.colt.matrix.impl.DenseDoubleMatrix1D)2 DenseDoubleMatrix2D (cern.colt.matrix.impl.DenseDoubleMatrix2D)2 Algebra (cern.colt.matrix.linalg.Algebra)2 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)2