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