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());
}
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();
}
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;
}
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());
}
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);
}
Aggregations