use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class LingRunner method execute.
// ============================PUBLIC METHODS==========================//
/**
* Executes the algorithm, producing (at least) a result workbench. Must be
* implemented in the extending class.
*/
// public void execute() {
// DataModel source = getDataModel();
//
// if (!(source instanceof DataSet)) {
// throw new IllegalArgumentException("Expecting a rectangular data set.");
// }
//
// DataSet data = (DataSet) source;
//
// if (!data.isContinuous()) {
// throw new IllegalArgumentException("Expecting a continuous data set.");
// }
//
// Ling ling = new Ling(data);
// Parameters searchParams = (Parameters) getParameters();
// ling.setThreshold(searchParams.getThreshold());
// Ling.StoredGraphs graphs = ling.search();
// Graph graph = null;
//
// for (int i = 0; i < graphs.getNumGraphs(); i++) {
// System.out.println(graphs.getGraph(i));
// System.out.println(graphs.isStable(i));
// }
//
// for (int i = 0; i < graphs.getNumGraphs(); i++) {
// if (graphs.isStable(i)) {
// graph = graphs.getGraph(i);
// break;
// }
// }
//
// if (graph == null) {
// graph = new EdgeListGraph();
// }
//
// setResultGraph(graph);
// setStoredGraphs(graphs);
//
// if (getSourceGraph() != null) {
// DataGraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
// }
// else {
// DataGraphUtils.circleLayout(graph, 200, 200, 150);
// }
//
// }
public void execute() {
DataModel source = getDataModel();
if (!(source instanceof DataSet)) {
throw new IllegalArgumentException("Expecting a rectangular data set.");
}
DataSet data = (DataSet) source;
if (!data.isContinuous()) {
throw new IllegalArgumentException("Expecting a continuous data set.");
}
Ling ling = new Ling(data);
Parameters searchParams = getParams();
ling.setThreshold(searchParams.getDouble("threshold", 0.5));
Ling.StoredGraphs graphs = ling.search();
Graph graph = null;
for (int i = 0; i < graphs.getNumGraphs(); i++) {
System.out.println(graphs.getGraph(i));
System.out.println(graphs.isStable(i));
}
for (int i = 0; i < graphs.getNumGraphs(); i++) {
if (graphs.isStable(i)) {
graph = graphs.getGraph(i);
break;
}
}
if (graph == null) {
graph = new EdgeListGraph();
}
setResultGraph(graph);
setStoredGraphs(graphs);
if (getSourceGraph() != null) {
GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
} else {
GraphUtils.circleLayout(graph, 200, 200, 150);
}
}
use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class LingamRunner method execute.
// ============================PUBLIC METHODS==========================//
/**
* Executes the algorithm, producing (at least) a result workbench. Must be
* implemented in the extending class.
*/
public void execute() {
DataModel source = getDataModel();
if (!(source instanceof DataSet)) {
throw new IllegalArgumentException("Expecting a rectangular data set.");
}
DataSet data = (DataSet) source;
if (!data.isContinuous()) {
throw new IllegalArgumentException("Expecting a continuous data set.");
}
// Lingam_old lingam = new Lingam_old();
// lingam.setAlternativePenalty(getParameters().getAlternativePenalty());
// lingam.setPruningDone(true);
//
// double lingamPruningAlpha = Preferences.userRoot().getDouble("lingamPruningAlpha", 0.05);
//
// lingam.setAlternativePenalty(lingamPruningAlpha);
// Graph graph = lingam.lingam(data).getGraph();
Lingam lingam = new Lingam();
Graph graph = lingam.search(data);
if (getSourceGraph() != null) {
GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
} else {
GraphUtils.circleLayout(graph, 200, 200, 150);
}
setResultGraph(graph);
GraphUtils.arrangeBySourceGraph(getResultGraph(), getSourceGraph());
}
use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class SemEstimatorWrapper method setParams.
private boolean setParams(SemPmWrapper semPmWrapper, DataModelList dataModel) {
for (DataModel model : dataModel) {
if (model instanceof DataSet) {
DataSet dataSet = (DataSet) model;
SemPm semPm = semPmWrapper.getSemPm();
this.semPm = semPm;
SemEstimator estimator = new SemEstimator(dataSet, semPm, getOptimizer());
estimator.setNumRestarts(getParams().getInt("numRestarts", 1));
estimator.setScoreType((ScoreType) getParams().get("scoreType", ScoreType.Fgls));
if (!degreesOfFreedomCheck(semPm)) {
return true;
}
estimator.estimate();
getMultipleResultList().add(estimator);
} else if (model instanceof ICovarianceMatrix) {
ICovarianceMatrix covMatrix = new CovarianceMatrix((ICovarianceMatrix) model);
SemPm semPm = semPmWrapper.getSemPm();
this.semPm = semPm;
SemEstimator estimator = new SemEstimator(covMatrix, semPm, getOptimizer());
estimator.setNumRestarts(getParams().getInt("numRestarts", 1));
estimator.setScoreType((ScoreType) getParams().get("scoreType", ScoreType.Fgls));
if (!degreesOfFreedomCheck(semPm)) {
return true;
}
estimator.estimate();
getMultipleResultList().add(estimator);
} else {
throw new IllegalArgumentException("Data must consist of continuous data sets or covariance matrices.");
}
}
return false;
}
use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class CovMatrixAverageWrapper method calcAverage.
private void calcAverage(List<DataWrapper> wrappers) {
List<TetradMatrix> cov = new ArrayList<>();
for (int i = 0; i < wrappers.size(); i++) {
DataModel selectedDataModel = wrappers.get(i).getSelectedDataModel();
if (!(selectedDataModel instanceof ICovarianceMatrix)) {
throw new IllegalArgumentException("Sorry, this is an average only over covariance matrices.");
}
cov.add(((ICovarianceMatrix) selectedDataModel).getMatrix());
}
TetradMatrix cov3 = new TetradMatrix(cov.get(0).rows(), cov.get(0).rows());
for (int i = 0; i < cov.get(0).rows(); i++) {
for (int j = 0; j < cov.get(0).rows(); j++) {
double c = 0.0;
for (int k = 0; k < cov.size(); k++) {
c += cov.get(k).get(i, j);
}
c /= cov.size();
cov3.set(i, j, c);
cov3.set(j, i, c);
}
}
DataModel m = wrappers.get(0).getSelectedDataModel();
ICovarianceMatrix _cov = (ICovarianceMatrix) m;
List<Node> nodes = _cov.getVariables();
int n = _cov.getSampleSize();
ICovarianceMatrix covWrapper = new CovarianceMatrix(nodes, cov3, n);
setDataModel(covWrapper);
}
Aggregations