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