Search in sources :

Example 1 with FindOneFactorClusters

use of edu.cmu.tetrad.search.FindOneFactorClusters in project tetrad by cmu-phil.

the class FofcRunner method execute.

// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
/**
 * Executes the algorithm, producing (at least) a result workbench. Must be
 * implemented in the extending class.
 */
public void execute() {
    Graph searchGraph;
    FindOneFactorClusters fofc;
    Object source = getData();
    TestType tetradTestType = (TestType) getParams().get("tetradTestType", TestType.TETRAD_WISHART);
    if (tetradTestType == null || (!(tetradTestType == TestType.TETRAD_DELTA || tetradTestType == TestType.TETRAD_WISHART))) {
        tetradTestType = TestType.TETRAD_DELTA;
        getParams().set("tetradTestType", tetradTestType);
    }
    FindOneFactorClusters.Algorithm algorithm = (FindOneFactorClusters.Algorithm) getParams().get("fofcAlgorithm", FindOneFactorClusters.Algorithm.GAP);
    if (source instanceof DataSet) {
        fofc = new FindOneFactorClusters((DataSet) source, tetradTestType, algorithm, getParams().getDouble("alpha", 0.001));
        searchGraph = fofc.search();
    } else if (source instanceof CovarianceMatrix) {
        fofc = new FindOneFactorClusters((CovarianceMatrix) source, tetradTestType, algorithm, getParams().getDouble("alpha", 0.001));
        searchGraph = fofc.search();
    } else {
        throw new IllegalArgumentException("Unrecognized data type.");
    }
    if (semIm != null) {
        List<List<Node>> partition = MimUtils.convertToClusters2(searchGraph);
        List<String> variableNames = ReidentifyVariables.reidentifyVariables2(partition, trueGraph, (DataSet) getData());
        rename(searchGraph, partition, variableNames);
    // searchGraph = reidentifyVariables2(searchGraph, semIm);
    } else if (trueGraph != null) {
        List<List<Node>> partition = MimUtils.convertToClusters2(searchGraph);
        List<String> variableNames = ReidentifyVariables.reidentifyVariables1(partition, trueGraph);
        rename(searchGraph, partition, variableNames);
    // searchGraph = reidentifyVariables(searchGraph, trueGraph);
    }
    System.out.println("Search Graph " + searchGraph);
    try {
        Graph graph = new MarshalledObject<>(searchGraph).get();
        GraphUtils.circleLayout(graph, 200, 200, 150);
        GraphUtils.fruchtermanReingoldLayout(graph);
        setResultGraph(graph);
        setClusters(MimUtils.convertToClusters(graph, getData().getVariables()));
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : Node(edu.cmu.tetrad.graph.Node) TestType(edu.cmu.tetrad.search.TestType) Graph(edu.cmu.tetrad.graph.Graph) FindOneFactorClusters(edu.cmu.tetrad.search.FindOneFactorClusters) MarshalledObject(java.rmi.MarshalledObject) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Graph (edu.cmu.tetrad.graph.Graph)1 Node (edu.cmu.tetrad.graph.Node)1 FindOneFactorClusters (edu.cmu.tetrad.search.FindOneFactorClusters)1 TestType (edu.cmu.tetrad.search.TestType)1 MarshalledObject (java.rmi.MarshalledObject)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1