use of edu.cmu.tetrad.data.Knowledge2 in project tetrad by cmu-phil.
the class FciCcdSearchEditor method layoutByKnowledge.
public void layoutByKnowledge() {
GraphWorkbench resultWorkbench = getWorkbench();
Graph graph = resultWorkbench.getGraph();
IKnowledge knowledge = (IKnowledge) getAlgorithmRunner().getParams().get("knowledge", new Knowledge2());
SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
}
use of edu.cmu.tetrad.data.Knowledge2 in project tetrad by cmu-phil.
the class TestKnowledge method test1.
@Test
public final void test1() {
List<Node> nodes1 = new ArrayList<>();
for (int i1 = 0; i1 < 10; i1++) {
nodes1.add(new ContinuousVariable("X" + (i1 + 1)));
}
Graph g = GraphUtils.randomGraph(nodes1, 0, 10, 3, 3, 3, false);
g.getNode("X1").setName("X1.1");
g.getNode("X2").setName("X2-1");
List<Node> nodes = g.getNodes();
List<String> varNames = new ArrayList<>();
for (Node node : nodes) {
varNames.add(node.getName());
}
IKnowledge knowledge = new Knowledge2(varNames);
knowledge.addToTier(0, "X1.*1");
knowledge.addToTier(0, "X2-1");
knowledge.addToTier(1, "X3");
knowledge.setForbidden("X4", "X5");
knowledge.setRequired("X6", "X7");
knowledge.setRequired("X7", "X8");
assertTrue(knowledge.isForbidden("X4", "X5"));
assertFalse(knowledge.isForbidden("X1.1", "X2-1"));
assertTrue(knowledge.isForbidden("X3", "X2-1"));
assertTrue(knowledge.isRequired("X6", "X7"));
IKnowledge copy = knowledge.copy();
assertTrue(copy.isForbidden("X4", "X5"));
assertFalse(copy.isForbidden("X1", "X2-1"));
assertTrue(copy.isForbidden("X3", "X2-1"));
knowledge.setTierForbiddenWithin(0, true);
assertTrue(knowledge.isForbidden("X1.1", "X2-1"));
assertTrue(knowledge.isForbidden("X2-1", "X1.1"));
assertFalse(knowledge.isForbidden("X1.1", "X1.1"));
boolean found = false;
for (Iterator i = knowledge.forbiddenEdgesIterator(); i.hasNext(); ) {
KnowledgeEdge edge = (KnowledgeEdge) i.next();
if (edge.getFrom().equals("X1.1") && edge.getTo().equals("X2-1")) {
found = true;
}
}
assertTrue(found);
knowledge.setTierForbiddenWithin(0, false);
assertFalse(knowledge.isForbidden("X1.1", "X2-1"));
assertFalse(knowledge.isForbidden("X2-1", "X1.1"));
assertFalse(knowledge.isForbidden("X1.1", "X1.1"));
}
use of edu.cmu.tetrad.data.Knowledge2 in project tetrad by cmu-phil.
the class TestKnowledge method test3.
@Test
public final void test3() {
List<String> vars = new ArrayList<>();
final int numVars = 1000;
for (int i = 0; i < numVars; i++) {
vars.add("X" + i);
}
IKnowledge knowledge = new Knowledge2(vars);
knowledge.setForbidden("X1*", "X2*");
knowledge.setForbidden("X3*", "X4*");
knowledge.setForbidden("X5*", "X6*");
knowledge.addToTier(0, "X7*");
knowledge.addToTier(1, "X8*");
knowledge.addToTier(2, "X9*");
for (int i = 0; i < numVars; i++) {
assertTrue(knowledge.isForbidden("X11", "X22"));
}
}
use of edu.cmu.tetrad.data.Knowledge2 in project tetrad by cmu-phil.
the class TestPcd method testSearch3.
/**
* This will fail if the orientation loop doesn't continue after the first orientation.
*/
// @Test
public void testSearch3() {
IKnowledge knowledge = new Knowledge2();
knowledge.setForbidden("B", "D");
knowledge.setForbidden("D", "B");
checkWithKnowledge("A-->B,C-->B,B-->D", "A-->B,C-->B,D", knowledge);
}
use of edu.cmu.tetrad.data.Knowledge2 in project tetrad by cmu-phil.
the class TimeLagGraphWrapper method getKnowledge.
public IKnowledge getKnowledge() {
// need to fix this!
int numLags = 1;
List<Node> variables = graph.getNodes();
List<Integer> laglist = new ArrayList<>();
IKnowledge knowledge1 = new Knowledge2();
int lag;
for (Node node : variables) {
String varName = node.getName();
String tmp;
if (varName.indexOf(':') == -1) {
lag = 0;
laglist.add(lag);
} else {
tmp = varName.substring(varName.indexOf(':') + 1, varName.length());
lag = Integer.parseInt(tmp);
laglist.add(lag);
}
}
numLags = Collections.max(laglist);
for (Node node : variables) {
String varName = node.getName();
String tmp;
if (varName.indexOf(':') == -1) {
lag = 0;
laglist.add(lag);
} else {
tmp = varName.substring(varName.indexOf(':') + 1, varName.length());
lag = Integer.parseInt(tmp);
laglist.add(lag);
}
knowledge1.addToTier(numLags - lag, node.getName());
}
System.out.println("Knowledge in graph = " + knowledge1);
return knowledge1;
}
Aggregations