Search in sources :

Example 1 with Ling

use of edu.cmu.tetrad.search.Ling 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);
    }
}
Also used : Ling(edu.cmu.tetrad.search.Ling) Parameters(edu.cmu.tetrad.util.Parameters) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel)

Aggregations

DataModel (edu.cmu.tetrad.data.DataModel)1 DataSet (edu.cmu.tetrad.data.DataSet)1 Ling (edu.cmu.tetrad.search.Ling)1 Parameters (edu.cmu.tetrad.util.Parameters)1