use of edu.cmu.tetrad.util.ChoiceGenerator in project tetrad by cmu-phil.
the class SepsetsConservativeMajority method getSepset.
/**
* Pick out the sepset from among adj(i) or adj(k) with the highest p value.
*/
public List<Node> getSepset(Node i, Node k) {
double _p = 0.0;
List<Node> _v = null;
if (extraSepsets != null) {
final List<Node> possibleDsep = extraSepsets.get(i, k);
if (possibleDsep != null) {
independenceTest.isIndependent(i, k, possibleDsep);
_p = independenceTest.getPValue();
_v = possibleDsep;
}
}
List<Node> adji = graph.getAdjacentNodes(i);
List<Node> adjk = graph.getAdjacentNodes(k);
adji.remove(k);
adjk.remove(i);
for (int d = 0; d <= Math.min((depth == -1 ? 1000 : depth), Math.max(adji.size(), adjk.size())); d++) {
if (d <= adji.size()) {
ChoiceGenerator gen = new ChoiceGenerator(adji.size(), d);
int[] choice;
while ((choice = gen.next()) != null) {
List<Node> v = GraphUtils.asList(choice, adji);
if (getIndependenceTest().isIndependent(i, k, v)) {
double pValue = getIndependenceTest().getPValue();
if (pValue > _p) {
_p = pValue;
_v = v;
}
}
}
}
if (d <= adjk.size()) {
ChoiceGenerator gen = new ChoiceGenerator(adjk.size(), d);
int[] choice;
while ((choice = gen.next()) != null) {
List<Node> v = GraphUtils.asList(choice, adjk);
if (getIndependenceTest().isIndependent(i, k, v)) {
double pValue = getIndependenceTest().getPValue();
if (pValue > _p) {
_p = pValue;
_v = v;
}
}
}
}
}
return _v;
}
use of edu.cmu.tetrad.util.ChoiceGenerator in project tetrad by cmu-phil.
the class SepsetsMaxPValue method getMaxSepset.
private List<Node> getMaxSepset(Node i, Node k) {
double _p = 0.0;
List<Node> _v = null;
if (extraSepsets != null) {
final List<Node> sepset = extraSepsets.get(i, k);
if (sepset != null) {
independenceTest.isIndependent(i, k, sepset);
double p = independenceTest.getPValue();
if (p > _p) {
_p = p;
_v = sepset;
}
}
}
List<Node> adji = graph.getAdjacentNodes(i);
List<Node> adjk = graph.getAdjacentNodes(k);
adji.remove(k);
adjk.remove(i);
for (int d = 0; d <= Math.min((depth == -1 ? 1000 : depth), Math.max(adji.size(), adjk.size())); d++) {
if (d <= adji.size()) {
ChoiceGenerator gen = new ChoiceGenerator(adji.size(), d);
int[] choice;
while ((choice = gen.next()) != null) {
List<Node> v = GraphUtils.asList(choice, adji);
getIndependenceTest().isIndependent(i, k, v);
double p = getIndependenceTest().getPValue();
if (p > _p) {
_p = p;
_v = v;
}
}
}
if (d <= adjk.size()) {
ChoiceGenerator gen = new ChoiceGenerator(adjk.size(), d);
int[] choice;
while ((choice = gen.next()) != null) {
List<Node> v = GraphUtils.asList(choice, adjk);
getIndependenceTest().isIndependent(i, k, v);
double p = getIndependenceTest().getPValue();
if (p > _p) {
_p = p;
_v = v;
}
}
}
}
this.p = _p;
return _v;
}
use of edu.cmu.tetrad.util.ChoiceGenerator in project tetrad by cmu-phil.
the class SepsetsConservative method getSepset.
/**
* Pick out the sepset from among adj(i) or adj(k) with the highest p value.
*/
public List<Node> getSepset(Node i, Node k) {
double _p = 0.0;
List<Node> _v = null;
if (extraSepsets != null) {
final List<Node> possibleDsep = extraSepsets.get(i, k);
if (possibleDsep != null) {
independenceTest.isIndependent(i, k, possibleDsep);
_p = independenceTest.getPValue();
_v = possibleDsep;
}
}
List<Node> adji = graph.getAdjacentNodes(i);
List<Node> adjk = graph.getAdjacentNodes(k);
adji.remove(k);
adjk.remove(i);
for (int d = 0; d <= Math.min((depth == -1 ? 1000 : depth), Math.max(adji.size(), adjk.size())); d++) {
if (d <= adji.size()) {
ChoiceGenerator gen = new ChoiceGenerator(adji.size(), d);
int[] choice;
while ((choice = gen.next()) != null) {
List<Node> v = GraphUtils.asList(choice, adji);
if (getIndependenceTest().isIndependent(i, k, v)) {
double pValue = getIndependenceTest().getPValue();
if (pValue > _p) {
_p = pValue;
_v = v;
}
}
}
}
if (d <= adjk.size()) {
ChoiceGenerator gen = new ChoiceGenerator(adjk.size(), d);
int[] choice;
while ((choice = gen.next()) != null) {
List<Node> v = GraphUtils.asList(choice, adjk);
if (getIndependenceTest().isIndependent(i, k, v)) {
double pValue = getIndependenceTest().getPValue();
if (pValue > _p) {
_p = pValue;
_v = v;
}
}
}
}
}
return _v;
}
use of edu.cmu.tetrad.util.ChoiceGenerator in project tetrad by cmu-phil.
the class SepsetsConservative method getSepsetsLists.
// The published version.
public List<List<List<Node>>> getSepsetsLists(Node x, Node y, Node z, IndependenceTest test, int depth, boolean verbose) {
List<List<Node>> sepsetsContainingY = new ArrayList<>();
List<List<Node>> sepsetsNotContainingY = new ArrayList<>();
List<Node> _nodes = graph.getAdjacentNodes(x);
_nodes.remove(z);
int _depth = depth;
if (_depth == -1) {
_depth = 1000;
}
_depth = Math.min(_depth, _nodes.size());
for (int d = 0; d <= _depth; d++) {
ChoiceGenerator cg = new ChoiceGenerator(_nodes.size(), d);
int[] choice;
while ((choice = cg.next()) != null) {
List<Node> cond = GraphUtils.asList(choice, _nodes);
if (test.isIndependent(x, z, cond)) {
if (verbose) {
System.out.println("Indep: " + x + " _||_ " + z + " | " + cond);
}
if (cond.contains(y)) {
sepsetsContainingY.add(cond);
} else {
sepsetsNotContainingY.add(cond);
}
}
}
}
_nodes = graph.getAdjacentNodes(z);
_nodes.remove(x);
_depth = depth;
if (_depth == -1) {
_depth = 1000;
}
_depth = Math.min(_depth, _nodes.size());
for (int d = 0; d <= _depth; d++) {
ChoiceGenerator cg = new ChoiceGenerator(_nodes.size(), d);
int[] choice;
while ((choice = cg.next()) != null) {
List<Node> cond = GraphUtils.asList(choice, _nodes);
if (test.isIndependent(x, z, cond)) {
if (cond.contains(y)) {
sepsetsContainingY.add(cond);
} else {
sepsetsNotContainingY.add(cond);
}
}
}
}
List<List<List<Node>>> ret = new ArrayList<>();
ret.add(sepsetsContainingY);
ret.add(sepsetsNotContainingY);
return ret;
}
use of edu.cmu.tetrad.util.ChoiceGenerator in project tetrad by cmu-phil.
the class SepsetsMinPValue method getMaxSepset.
private List<Node> getMaxSepset(Node i, Node k) {
double _p = 0.0;
List<Node> _v = null;
if (extraSepsets != null) {
final List<Node> possibleDsep = extraSepsets.get(i, k);
if (possibleDsep != null) {
independenceTest.isIndependent(i, k, possibleDsep);
double p = independenceTest.getPValue();
if (p < _p) {
_p = p;
_v = possibleDsep;
}
}
}
List<Node> adji = graph.getAdjacentNodes(i);
List<Node> adjk = graph.getAdjacentNodes(k);
adji.remove(k);
adjk.remove(i);
for (int d = 0; d <= Math.min((depth == -1 ? 1000 : depth), Math.max(adji.size(), adjk.size())); d++) {
if (d <= adji.size()) {
ChoiceGenerator gen = new ChoiceGenerator(adji.size(), d);
int[] choice;
while ((choice = gen.next()) != null) {
List<Node> v = GraphUtils.asList(choice, adji);
getIndependenceTest().isIndependent(i, k, v);
double p = getIndependenceTest().getPValue();
if (p < _p) {
_p = p;
_v = v;
}
}
}
if (d <= adjk.size()) {
ChoiceGenerator gen = new ChoiceGenerator(adjk.size(), d);
int[] choice;
while ((choice = gen.next()) != null) {
List<Node> v = GraphUtils.asList(choice, adjk);
getIndependenceTest().isIndependent(i, k, v);
double p = getIndependenceTest().getPValue();
if (p < _p) {
_p = p;
_v = v;
}
}
}
}
this.p = _p;
return _v;
}
Aggregations