use of edu.cmu.tetrad.data.Knowledge2 in project tetrad by cmu-phil.
the class VcpcAltRunner method execute.
// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
Parameters searchParams = getParams();
Parameters params = searchParams;
VcpcAlt VcpcAlt = new VcpcAlt(getIndependenceTest());
VcpcAlt.setKnowledge(knowledge);
VcpcAlt.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles());
VcpcAlt.setDepth(params.getInt("depth", -1));
Graph graph = VcpcAlt.search();
if (getSourceGraph() != null) {
GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
} else if (knowledge.isDefaultToKnowledgeLayout()) {
SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
} else {
GraphUtils.circleLayout(graph, 200, 200, 150);
}
setResultGraph(graph);
}
use of edu.cmu.tetrad.data.Knowledge2 in project tetrad by cmu-phil.
the class VcpcRunner method execute.
// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
Parameters searchParams = getParams();
Parameters params = searchParams;
Vcpc vcpc = new Vcpc(getIndependenceTest());
vcpc.setKnowledge(knowledge);
vcpc.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles());
vcpc.setDepth(params.getInt("depth", -1));
if (independenceFactsModel != null) {
vcpc.setFacts(independenceFactsModel.getFacts());
}
Graph graph = vcpc.search();
if (getSourceGraph() != null) {
GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
} else if (knowledge.isDefaultToKnowledgeLayout()) {
SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
} else {
GraphUtils.circleLayout(graph, 200, 200, 150);
}
setResultGraph(graph);
setVcpcFields(vcpc);
}
use of edu.cmu.tetrad.data.Knowledge2 in project tetrad by cmu-phil.
the class FasDci method search.
// ==========================PUBLIC METHODS===========================//
/**
* Discovers all adjacencies in data. The procedure is to remove edges in the graph which connect pairs of
* variables which are independent conditional on some other set of variables in the graph (the "sepset"). These are
* removed in tiers. First, edges which are independent conditional on zero other variables are removed, then edges
* which are independent conditional on one other variable are removed, then two, then three, and so on, until no
* more edges can be removed from the graph. The edges which remain in the graph after this procedure are the
* adjacencies in the data.
*
* @return a SepSet, which indicates which variables are independent conditional on which other variables
*/
public SepsetMapDci search() {
this.logger.log("info", "Starting Fast Adjacency Search (DCI).");
// Remove edges forbidden both ways.
Set<Edge> edges = graph.getEdges();
for (Edge _edge : edges) {
String name1 = _edge.getNode1().getName();
String name2 = _edge.getNode2().getName();
if (knowledge.isForbidden(name1, name2) && knowledge.isForbidden(name2, name1)) {
graph.removeEdge(_edge);
this.logger.log("edgeRemoved", "Removed " + _edge + " because it was " + "forbidden by background knowledge.");
}
}
// this.logger.info("Depth = " + ((depth == Integer
// .MAX_VALUE) ? "Unlimited" : Integer.toString(depth)));
SepsetMapDci sepset = new SepsetMapDci();
int _depth = depth;
if (_depth == -1) {
_depth = 1000;
}
for (int d = 0; d <= _depth; d++) {
boolean more = searchAtDepth(graph, independenceTest, new Knowledge2(), sepset, d);
if (!more) {
break;
}
}
// verifySepsetIntegrity(sepset);
this.logger.log("info", "Finishing Fast Adjacency Search.");
return sepset;
}
use of edu.cmu.tetrad.data.Knowledge2 in project tetrad by cmu-phil.
the class TestKnowledge method test2.
@Test
public final void test2() {
List<Node> nodes1 = new ArrayList<>();
for (int i = 0; i < 100; i++) {
nodes1.add(new ContinuousVariable("X" + (i + 1)));
}
Graph g = GraphUtils.randomGraph(nodes1, 0, 100, 3, 3, 3, false);
List<Node> nodes = g.getNodes();
List<String> names = new ArrayList<>();
for (Node node : nodes) names.add(node.getName());
Knowledge2 knowledge = new Knowledge2(names);
knowledge.addToTier(0, "X1*");
knowledge.addToTier(1, "X2*");
knowledge.setRequired("X4*,X6*", "X5*");
knowledge.setRequired("X6*", "X5*");
assertTrue(knowledge.isForbidden("X20", "X10"));
assertTrue(knowledge.isRequired("X6", "X5"));
}
use of edu.cmu.tetrad.data.Knowledge2 in project tetrad by cmu-phil.
the class TestDagInPatternIterator method test5.
@Test
public void test5() {
RandomUtil.getInstance().setSeed(34828384L);
List<Node> nodes1 = new ArrayList<>();
for (int i = 0; i < 3; i++) {
nodes1.add(new ContinuousVariable("X" + (i + 1)));
}
Dag dag1 = new Dag(GraphUtils.randomGraph(nodes1, 0, 3, 30, 15, 15, false));
Graph pattern = SearchGraphUtils.patternForDag(dag1);
List<Node> nodes = pattern.getNodes();
// Make random knowedge.
int numTiers = 6;
IKnowledge knowledge = new Knowledge2();
for (Node node : nodes) {
int tier = RandomUtil.getInstance().nextInt(numTiers);
if (tier < 2)
continue;
knowledge.addToTier(tier, node.getName());
}
if (!knowledge.isViolatedBy(pattern)) {
DagInPatternIterator iterator1 = new DagInPatternIterator(pattern);
Graph dag0 = null;
while (iterator1.hasNext()) {
Graph dag = iterator1.next();
if (!knowledge.isViolatedBy(dag)) {
dag0 = dag;
}
}
if (dag0 == null) {
fail("Inconsistent knowledge.");
}
}
if (!knowledge.isViolatedBy(pattern)) {
DagInPatternIterator iterator2 = new DagInPatternIterator(pattern, knowledge);
while (iterator2.hasNext()) {
Graph dag = iterator2.next();
if (knowledge.isViolatedBy(dag)) {
throw new IllegalArgumentException("Knowledge violated");
}
}
}
DagInPatternIterator iterator3 = new DagInPatternIterator(pattern);
int count = 0;
while (iterator3.hasNext()) {
iterator3.next();
count++;
}
assertEquals(6, count);
}
Aggregations