use of edu.cmu.tetrad.graph.IndependenceFact in project tetrad by cmu-phil.
the class IndTestProbabilisticVerbose method isIndependent.
@Override
public boolean isIndependent(Node x, Node y, Node... z) {
IndependenceFact key = new IndependenceFact(x, y, z);
if (!H.containsKey(key)) {
double pInd = probConstraint(BCInference.OP.independent, x, y, z);
H.put(key, pInd);
}
double pInd = H.get(key);
double p = probOp(BCInference.OP.independent, pInd);
this.posterior = p;
// boolean ind = RandomUtil.getInstance().nextDouble() < p;
boolean dsep = dsepTest.isIndependent(x, y, z);
out.print((nodes.indexOf(x) + 1) + " ");
out.print((nodes.indexOf(y) + 1) + (z.length > 0 ? " " : ""));
for (int i = 0; i < z.length; i++) {
out.print(nodes.indexOf(z[i]) + 1);
if (i < z.length - 1) {
out.print(" ");
}
}
out.print(",");
out.print((dsep ? 1 : 0) + ",");
out.print(p);
out.println();
if (dsep) {
return true;
} else {
return false;
}
}
use of edu.cmu.tetrad.graph.IndependenceFact in project tetrad by cmu-phil.
the class IndTestProbabilistic method isIndependent.
@Override
public boolean isIndependent(Node x, Node y, Node... z) {
IndependenceFact key = new IndependenceFact(x, y, z);
if (!H.containsKey(key)) {
double pInd = probConstraint(BCInference.OP.independent, x, y, z);
H.put(key, pInd);
}
double pInd = H.get(key);
double p = probOp(BCInference.OP.independent, pInd);
this.posterior = p;
boolean ind = RandomUtil.getInstance().nextDouble() < p;
System.out.print((nodes.indexOf(x) + 1) + " ");
System.out.print((nodes.indexOf(y) + 1) + (z.length > 0 ? " " : ""));
for (int i = 0; i < z.length; i++) {
System.out.print(nodes.indexOf(z[i]) + 1);
if (i < z.length - 1) {
System.out.print(" ");
}
}
System.out.print(",");
System.out.print(ind ? 1 : 0 + ",");
System.out.print(p);
System.out.println();
if (ind) {
return true;
} else {
return false;
}
}
use of edu.cmu.tetrad.graph.IndependenceFact in project tetrad by cmu-phil.
the class IndependenceFacts method getVariables.
public List<Node> getVariables() {
Set<Node> variables = new HashSet<>();
for (IndependenceFact fact : unsortedFacts) {
variables.add(fact.getX());
variables.add(fact.getY());
for (Node z : fact.getZ()) {
variables.add(z);
}
}
return new ArrayList<>(variables);
}
use of edu.cmu.tetrad.graph.IndependenceFact in project tetrad by cmu-phil.
the class IndependenceFacts method isIndependent.
public boolean isIndependent(Node x, Node y, List<Node> z) {
IndependenceFact fact = new IndependenceFact(x, y, z);
System.out.println("Looking up " + fact + " in " + unsortedFacts);
return unsortedFacts.contains(fact);
}
use of edu.cmu.tetrad.graph.IndependenceFact in project tetrad by cmu-phil.
the class TestIndependenceFacts method test1.
@Test
public void test1() {
IndependenceFactsModel facts = new IndependenceFactsModel();
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");
facts.add(new IndependenceFact(x1, x2, x3));
facts.add(new IndependenceFact(x2, x3));
facts.add(new IndependenceFact(x2, x4, x1, x2));
facts.add(new IndependenceFact(x2, x4, x1, x3, x5));
facts.add(new IndependenceFact(x2, x4, x3));
facts.add(new IndependenceFact(x2, x4, x3, x6));
facts.remove(new IndependenceFact(x1, x2, x3));
IndependenceFacts _facts = new IndependenceFacts(facts.getFacts());
assertTrue(_facts.isIndependent(x4, x2, x1, x2));
assertTrue(_facts.isIndependent(x4, x2, x5, x3, x1));
List<Node> l = new ArrayList<>();
l.add(x1);
l.add(x2);
assertTrue(_facts.isIndependent(x4, x2, l));
}
Aggregations