Search in sources :

Example 1 with FindTwoFactorClusters

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

the class Ftfc method search.

@Override
public Graph search(DataModel dataSet, Parameters parameters) {
    if (parameters.getInt("bootstrapSampleSize") < 1) {
        ICovarianceMatrix cov = null;
        if (dataSet instanceof DataSet) {
            cov = DataUtils.getCovMatrix(dataSet);
        } else if (dataSet instanceof ICovarianceMatrix) {
            cov = (ICovarianceMatrix) dataSet;
        } else {
            throw new IllegalArgumentException("Expected a dataset or a covariance matrix.");
        }
        double alpha = parameters.getDouble("alpha");
        boolean gap = parameters.getBoolean("useGap", true);
        FindTwoFactorClusters.Algorithm algorithm;
        if (gap) {
            algorithm = FindTwoFactorClusters.Algorithm.GAP;
        } else {
            algorithm = FindTwoFactorClusters.Algorithm.SAG;
        }
        FindTwoFactorClusters search = new FindTwoFactorClusters(cov, algorithm, alpha);
        search.setVerbose(parameters.getBoolean("verbose"));
        return search.search();
    } else {
        Ftfc algorithm = new Ftfc();
        // algorithm.setKnowledge(knowledge);
        // if (initialGraph != null) {
        // algorithm.setInitialGraph(initialGraph);
        // }
        DataSet data = (DataSet) dataSet;
        GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
        search.setKnowledge(knowledge);
        BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
        switch(parameters.getInt("bootstrapEnsemble", 1)) {
            case 0:
                edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
                break;
            case 1:
                edgeEnsemble = BootstrapEdgeEnsemble.Highest;
                break;
            case 2:
                edgeEnsemble = BootstrapEdgeEnsemble.Majority;
        }
        search.setEdgeEnsemble(edgeEnsemble);
        search.setParameters(parameters);
        search.setVerbose(parameters.getBoolean("verbose"));
        return search.search();
    }
}
Also used : GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) BootstrapEdgeEnsemble(edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble) FindTwoFactorClusters(edu.cmu.tetrad.search.FindTwoFactorClusters)

Example 2 with FindTwoFactorClusters

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

the class FtfcRunner 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;
    FindTwoFactorClusters ftfc;
    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);
    }
    FindTwoFactorClusters.Algorithm algorithm = (FindTwoFactorClusters.Algorithm) getParams().get("ftfcAlgorithm", FindTwoFactorClusters.Algorithm.GAP);
    if (source instanceof DataSet) {
        ftfc = new FindTwoFactorClusters((DataSet) source, algorithm, getParams().getDouble("alpha", 0.001));
        ftfc.setVerbose(true);
        searchGraph = ftfc.search();
    } else if (source instanceof CovarianceMatrix) {
        ftfc = new FindTwoFactorClusters((CovarianceMatrix) source, algorithm, getParams().getDouble("alpha", 0.001));
        ftfc.setVerbose(true);
        searchGraph = ftfc.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) MarshalledObject(java.rmi.MarshalledObject) ArrayList(java.util.ArrayList) List(java.util.List) FindTwoFactorClusters(edu.cmu.tetrad.search.FindTwoFactorClusters)

Aggregations

FindTwoFactorClusters (edu.cmu.tetrad.search.FindTwoFactorClusters)2 Graph (edu.cmu.tetrad.graph.Graph)1 Node (edu.cmu.tetrad.graph.Node)1 TestType (edu.cmu.tetrad.search.TestType)1 BootstrapEdgeEnsemble (edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble)1 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)1 MarshalledObject (java.rmi.MarshalledObject)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1