use of edu.cmu.tetrad.data.IKnowledge 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.IKnowledge 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.IKnowledge 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