Search in sources :

Example 26 with EdgeListGraph

use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.

the class Glasso method search.

public Graph search(DataModel ds, Parameters parameters) {
    if (parameters.getInt("bootstrapSampleSize") < 1) {
        DoubleMatrix2D cov = new DenseDoubleMatrix2D(DataUtils.getContinuousDataSet(ds).getCovarianceMatrix().toArray());
        edu.cmu.tetrad.search.Glasso glasso = new edu.cmu.tetrad.search.Glasso(cov);
        glasso.setMaxit((int) parameters.getInt("maxit"));
        glasso.setIa(parameters.getBoolean("ia"));
        glasso.setIs(parameters.getBoolean("is"));
        glasso.setItr(parameters.getBoolean("itr"));
        glasso.setIpen(parameters.getBoolean("ipen"));
        glasso.setThr(parameters.getDouble("thr"));
        glasso.setRhoAllEqual(1.0);
        edu.cmu.tetrad.search.Glasso.Result result = glasso.search();
        TetradMatrix wwi = new TetradMatrix(result.getWwi().toArray());
        List<Node> variables = ds.getVariables();
        Graph resultGraph = new EdgeListGraph(variables);
        for (int i = 0; i < variables.size(); i++) {
            for (int j = i + 1; j < variables.size(); j++) {
                if (wwi.get(i, j) != 0.0 && wwi.get(i, j) != 0.0) {
                    resultGraph.addUndirectedEdge(variables.get(i), variables.get(j));
                }
            }
        }
        return resultGraph;
    } else {
        Glasso algorithm = new Glasso();
        DataSet data = (DataSet) ds;
        GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
        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) Node(edu.cmu.tetrad.graph.Node) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D)

Example 27 with EdgeListGraph

use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.

the class MixedFgesDiscretingContinuousVariables method convertBack.

private Graph convertBack(DataSet Dk, Graph p) {
    Graph p2 = new EdgeListGraph(Dk.getVariables());
    for (int i = 0; i < p.getNodes().size(); i++) {
        for (int j = i + 1; j < p.getNodes().size(); j++) {
            Node v1 = p.getNodes().get(i);
            Node v2 = p.getNodes().get(j);
            Edge e = p.getEdge(v1, v2);
            if (e != null) {
                Node w1 = Dk.getVariable(e.getNode1().getName());
                Node w2 = Dk.getVariable(e.getNode2().getName());
                Edge e2 = new Edge(w1, w2, e.getEndpoint1(), e.getEndpoint2());
                p2.addEdge(e2);
            }
        }
    }
    return p2;
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Edge(edu.cmu.tetrad.graph.Edge)

Example 28 with EdgeListGraph

use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.

the class MixedFgesTreatingDiscreteAsContinuous method convertBack.

private Graph convertBack(DataSet Dk, Graph p) {
    Graph p2 = new EdgeListGraph(Dk.getVariables());
    for (int i = 0; i < p.getNodes().size(); i++) {
        for (int j = i + 1; j < p.getNodes().size(); j++) {
            Node v1 = p.getNodes().get(i);
            Node v2 = p.getNodes().get(j);
            Edge e = p.getEdge(v1, v2);
            if (e != null) {
                Node w1 = Dk.getVariable(e.getNode1().getName());
                Node w2 = Dk.getVariable(e.getNode2().getName());
                Edge e2 = new Edge(w1, w2, e.getEndpoint1(), e.getEndpoint2());
                p2.addEdge(e2);
            }
        }
    }
    return p2;
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Edge(edu.cmu.tetrad.graph.Edge)

Example 29 with EdgeListGraph

use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.

the class WFges method search.

public Graph search() {
    score.setPenaltyDiscount(penaltyDiscount);
    Graph g = fges.search();
    Graph out = new EdgeListGraph(searchVariables);
    for (int i = 0; i < searchVariables.size(); i++) {
        for (int j = i + 1; j < searchVariables.size(); j++) {
            Node x = searchVariables.get(i);
            Node y = searchVariables.get(j);
            List<Node> xNodes = variablesPerNode.get(x);
            List<Node> yNodes = variablesPerNode.get(y);
            int left = 0;
            int right = 0;
            int total = 0;
            for (int k = 0; k < xNodes.size(); k++) {
                for (int l = 0; l < yNodes.size(); l++) {
                    Edge e = g.getEdge(xNodes.get(k), yNodes.get(l));
                    if (e != null) {
                        total++;
                        if (e.pointsTowards(xNodes.get(k)))
                            left++;
                        if (e.pointsTowards(yNodes.get(l)))
                            right++;
                    }
                }
            }
            if (total > 0) {
                if (left == total)
                    out.addDirectedEdge(y, x);
                else if (right == total)
                    out.addDirectedEdge(x, y);
                else
                    out.addUndirectedEdge(x, y);
            }
        }
    }
    return out;
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Edge(edu.cmu.tetrad.graph.Edge)

Example 30 with EdgeListGraph

use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.

the class FgesDisplay method setDisplayGraph.

private void setDisplayGraph() {
    int index = getIndexable().getIndex();
    if (topGraphs.size() == 0) {
        workbench.setGraph(new EdgeListGraph());
    } else {
        ScoredGraph scoredGraph = topGraphs.get(index);
        workbench.setGraph(scoredGraph.getGraph());
    }
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) ScoredGraph(edu.cmu.tetrad.search.ScoredGraph)

Aggregations

EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)46 Graph (edu.cmu.tetrad.graph.Graph)36 Node (edu.cmu.tetrad.graph.Node)31 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)11 DataSet (edu.cmu.tetrad.data.DataSet)10 Edge (edu.cmu.tetrad.graph.Edge)8 GraphNode (edu.cmu.tetrad.graph.GraphNode)8 ArrayList (java.util.ArrayList)8 DMSearch (edu.cmu.tetrad.search.DMSearch)6 Test (org.junit.Test)6 SemIm (edu.cmu.tetrad.sem.SemIm)5 SemPm (edu.cmu.tetrad.sem.SemPm)5 List (java.util.List)5 IOException (java.io.IOException)4 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)3 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)3 DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)2 DenseDoubleMatrix2D (cern.colt.matrix.impl.DenseDoubleMatrix2D)2 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)2 TakesInitialGraph (edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph)2