use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.
the class RegressionRunner 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() {
if (regressorNames.size() == 0 || targetName == null) {
outGraph = new EdgeListGraph();
return;
}
if (regressorNames.contains(targetName)) {
outGraph = new EdgeListGraph();
return;
}
Regression regression;
Node target;
List<Node> regressors;
if (getDataModel() instanceof DataSet) {
DataSet _dataSet = (DataSet) getDataModel();
regression = new RegressionDataset(_dataSet);
target = _dataSet.getVariable(targetName);
regressors = new LinkedList<>();
for (String regressorName : regressorNames) {
regressors.add(_dataSet.getVariable(regressorName));
}
double alpha = params.getDouble("alpha", 0.001);
regression.setAlpha(alpha);
result = regression.regress(target, regressors);
outGraph = regression.getGraph();
} else if (getDataModel() instanceof ICovarianceMatrix) {
ICovarianceMatrix covariances = (ICovarianceMatrix) getDataModel();
regression = new RegressionCovariance(covariances);
target = covariances.getVariable(targetName);
regressors = new LinkedList<>();
for (String regressorName : regressorNames) {
regressors.add(covariances.getVariable(regressorName));
}
double alpha = params.getDouble("alpha", 0.001);
regression.setAlpha(alpha);
result = regression.regress(target, regressors);
outGraph = regression.getGraph();
}
setResultGraph(outGraph);
}
use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.
the class DagIterator method next.
/**
* Successive calls to this method return successive DAGs in the pattern, in a more or less natural enumeration of
* them in which an arbitrary undirected edge is picked, oriented one way, Meek rules applied, then a remaining
* unoriented edge is picked, oriented one way, and so on, until a DAG is obtained, and then by backtracking the
* other orientation of each chosen edge is tried. Nonrecursive, obviously.
* <p>
*
* @return a Graph instead of a DAG because sometimes, due to faulty patterns, a cyclic graph is produced, and the
* end-user may need to decide what to do with it. The simplest thing is to construct a DAG (Dag(graph)) and catch
* an exception.
*/
public Graph next() {
if (storedDag != null) {
Graph temp = storedDag;
storedDag = null;
return temp;
}
if (decoratedGraphs.isEmpty()) {
return null;
}
// If it's a DAG
if (!decoratedGraphs.getLast().hasUndirectedEdge()) {
// oriented right, and add a graph with that oriented left.
while (true) {
if (decoratedGraphs.isEmpty()) {
return null;
}
DecoratedGraph graph = decoratedGraphs.removeLast();
if (graph.hasUndirectedEdge() && !graph.wasDirectedRight()) {
throw new IllegalStateException();
}
if (decoratedGraphs.isEmpty() && !graph.hasUndirectedEdge()) {
return new EdgeListGraph(graph.getGraph());
}
if (graph.wasDirectedRight() && !graph.wasDirectedLeft()) {
decoratedGraphs.add(graph);
DecoratedGraph graph1 = graph.directLeft();
if (graph1 == null) {
continue;
}
decoratedGraphs.add(graph1);
break;
}
}
}
// Apply right orientations and Meek orientations until there's a DAG.
while (decoratedGraphs.getLast().hasUndirectedEdge()) {
DecoratedGraph graph = decoratedGraphs.getLast().directRight();
if (graph == null) {
continue;
}
decoratedGraphs.add(graph);
}
// Return the DAG.
return new EdgeListGraph(decoratedGraphs.getLast().getGraph());
}
use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.
the class TestSem method constructGraph2.
private Graph constructGraph2() {
Graph graph = new EdgeListGraph();
Node x1 = new GraphNode("X1");
Node x2 = new GraphNode("X2");
Node x3 = new GraphNode("X3");
Node x4 = new GraphNode("X4");
Node x5 = new GraphNode("X5");
Node x6 = new GraphNode("X6");
Node x7 = new GraphNode("X7");
Node x8 = new GraphNode("X8");
graph.addNode(x1);
graph.addNode(x2);
graph.addNode(x3);
graph.addNode(x4);
graph.addNode(x5);
graph.addNode(x6);
graph.addNode(x7);
graph.addNode(x8);
graph.addDirectedEdge(x1, x2);
graph.addDirectedEdge(x2, x3);
graph.addDirectedEdge(x2, x6);
graph.addDirectedEdge(x3, x7);
graph.addDirectedEdge(x4, x5);
graph.addDirectedEdge(x4, x6);
graph.addDirectedEdge(x5, x3);
graph.addDirectedEdge(x6, x8);
graph.addDirectedEdge(x6, x7);
return graph;
}
use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.
the class TestSem method constructGraph1.
private Graph constructGraph1() {
Graph graph = new EdgeListGraph();
Node x1 = new GraphNode("X1");
Node x2 = new GraphNode("X2");
Node x3 = new GraphNode("X3");
Node x4 = new GraphNode("X4");
Node x5 = new GraphNode("X5");
graph.addNode(x1);
graph.addNode(x2);
graph.addNode(x3);
graph.addNode(x4);
graph.addNode(x5);
graph.addDirectedEdge(x1, x2);
graph.addDirectedEdge(x2, x3);
graph.addDirectedEdge(x3, x4);
graph.addDirectedEdge(x1, x4);
graph.addDirectedEdge(x4, x5);
return graph;
}
use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.
the class TestSemUpdater method constructGraph1.
private Graph constructGraph1() {
Graph graph = new EdgeListGraph();
Node x1 = new GraphNode("X1");
Node x2 = new GraphNode("X2");
Node x3 = new GraphNode("X3");
Node x4 = new GraphNode("X4");
Node x5 = new GraphNode("X5");
graph.addNode(x1);
graph.addNode(x2);
graph.addNode(x3);
graph.addNode(x4);
graph.addNode(x5);
graph.addDirectedEdge(x1, x2);
graph.addDirectedEdge(x2, x3);
graph.addDirectedEdge(x3, x4);
graph.addDirectedEdge(x1, x4);
graph.addDirectedEdge(x4, x5);
return graph;
}
Aggregations