use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.
the class SpecialGraphClark method createGraph.
@Override
public Graph createGraph(Parameters parameters) {
Node x = new ContinuousVariable("X");
Node y = new ContinuousVariable("Y");
Node z = new ContinuousVariable("Z");
Graph g = new EdgeListGraph();
g.addNode(x);
g.addNode(y);
g.addNode(z);
// g.addDirectedEdge(x, y);
// g.addDirectedEdge(z, x);
// g.addDirectedEdge(z, y);
g.addDirectedEdge(x, y);
g.addDirectedEdge(x, z);
g.addDirectedEdge(y, z);
//
return g;
}
use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.
the class TestDM method test2.
@Test
public void test2() {
// setting seed for debug.
RandomUtil.getInstance().setSeed(29483818483L);
Graph graph = emptyGraph(8);
graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X2"));
graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X3"));
graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X2"));
graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X3"));
graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X6"));
graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X7"));
graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X6"));
graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X7"));
graph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("X6"));
graph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("X7"));
graph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("X6"));
graph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("X7"));
SemPm pm = new SemPm(graph);
SemIm im = new SemIm(pm);
DataSet data = im.simulateData(100000, false);
DMSearch search = new DMSearch();
search.setInputs(new int[] { 0, 1, 4, 5 });
search.setOutputs(new int[] { 2, 3, 6, 7 });
search.setData(data);
search.setTrueInputs(search.getInputs());
Graph foundGraph = search.search();
print("Test Case 2");
Graph trueGraph = new EdgeListGraph();
trueGraph.addNode(new ContinuousVariable("X0"));
trueGraph.addNode(new ContinuousVariable("X1"));
trueGraph.addNode(new ContinuousVariable("X2"));
trueGraph.addNode(new ContinuousVariable("X3"));
trueGraph.addNode(new ContinuousVariable("X4"));
trueGraph.addNode(new ContinuousVariable("X5"));
trueGraph.addNode(new ContinuousVariable("X6"));
trueGraph.addNode(new ContinuousVariable("X7"));
trueGraph.addNode(new ContinuousVariable("L0"));
trueGraph.addNode(new ContinuousVariable("L1"));
trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L0"));
trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L0"));
trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X2"));
trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X3"));
// trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X1"));
trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L1"));
trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L1"));
trueGraph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("L1"));
trueGraph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("L1"));
trueGraph.addDirectedEdge(new ContinuousVariable("L1"), new ContinuousVariable("X6"));
trueGraph.addDirectedEdge(new ContinuousVariable("L1"), new ContinuousVariable("X7"));
assertTrue(foundGraph.equals(trueGraph));
}
use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.
the class GlassoRunner method execute.
// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
Object dataModel = getDataModel();
Parameters params = getParams();
if (dataModel instanceof DataSet) {
DataSet dataSet = (DataSet) dataModel;
DoubleMatrix2D cov = new DenseDoubleMatrix2D(dataSet.getCovarianceMatrix().toArray());
Glasso glasso = new Glasso(cov);
glasso.setMaxit((int) params.get("maxit", 10000));
glasso.setIa(params.getBoolean("ia", false));
glasso.setIs(params.getBoolean("is", false));
glasso.setItr(params.getBoolean("itr", false));
glasso.setIpen(params.getBoolean("ipen", false));
glasso.setThr(params.getDouble("thr", 1e-4));
glasso.setRhoAllEqual(1.0);
Glasso.Result result = glasso.search();
TetradMatrix wwi = new TetradMatrix(result.getWwi().toArray());
List<Node> variables = dataSet.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));
}
}
}
setResultGraph(resultGraph);
}
}
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();
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);
}
}
use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.
the class WGfci method search.
public Graph search() {
test.setAlpha(alpha);
Graph g = gfci.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;
}
Aggregations