Search in sources :

Example 46 with EdgeListGraph

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

the class LoadContinuousDataSmithSim method readGraph.

public Graph readGraph(File file) {
    try {
        DataReader reader = new DataReader();
        reader.setVariablesSupplied(false);
        reader.setDelimiter(DelimiterType.COMMA);
        DataSet data = reader.parseTabular(file);
        List<Node> variables = data.getVariables();
        List<Node> _variables = new ArrayList<>();
        for (int i = 0; i < variables.size(); i++) {
            _variables.add(new ContinuousVariable(variables.get(i).getName()));
        }
        Graph graph = new EdgeListGraph(_variables);
        for (int i = 0; i < _variables.size(); i++) {
            for (int j = 0; j < _variables.size(); j++) {
                if (i == j)
                    continue;
                if (data.getDouble(i, j) != 0) {
                    graph.addDirectedEdge(_variables.get(i), _variables.get(j));
                }
            }
        }
        return graph;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) IOException(java.io.IOException)

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