use of edu.cmu.tetrad.util.DepthChoiceGenerator in project tetrad by cmu-phil.
the class Fask method bidirected.
private boolean bidirected(double[] x, double[] y, Graph G0, Node X, Node Y) {
Set<Node> adjSet = new HashSet<Node>(G0.getAdjacentNodes(X));
adjSet.addAll(G0.getAdjacentNodes(Y));
List<Node> adj = new ArrayList<>(adjSet);
adj.remove(X);
adj.remove(Y);
DepthChoiceGenerator gen = new DepthChoiceGenerator(adj.size(), Math.min(depth, adj.size()));
int[] choice;
while ((choice = gen.next()) != null) {
List<Node> _adj = GraphUtils.asList(choice, adj);
double[][] _Z = new double[_adj.size()][];
for (int f = 0; f < _adj.size(); f++) {
Node _z = _adj.get(f);
int column = dataSet.getColumn(_z);
_Z[f] = data[column];
}
double pc = partialCorrelation(x, y, _Z, x, Double.NEGATIVE_INFINITY, +1);
double pc1 = partialCorrelation(x, y, _Z, x, 0, +1);
double pc2 = partialCorrelation(x, y, _Z, y, 0, +1);
int nc = StatUtils.getRows(x, x, Double.NEGATIVE_INFINITY, +1).size();
int nc1 = StatUtils.getRows(x, x, 0, +1).size();
int nc2 = StatUtils.getRows(y, y, 0, +1).size();
double z = 0.5 * (log(1.0 + pc) - log(1.0 - pc));
double z1 = 0.5 * (log(1.0 + pc1) - log(1.0 - pc1));
double z2 = 0.5 * (log(1.0 + pc2) - log(1.0 - pc2));
double zv1 = (z - z1) / sqrt((1.0 / ((double) nc - 3) + 1.0 / ((double) nc1 - 3)));
double zv2 = (z - z2) / sqrt((1.0 / ((double) nc - 3) + 1.0 / ((double) nc2 - 3)));
boolean rejected1 = abs(zv1) > cutoff;
boolean rejected2 = abs(zv2) > cutoff;
boolean possibleTwoCycle = false;
if (zv1 < 0 && zv2 > 0 && rejected1) {
possibleTwoCycle = true;
} else if (zv1 > 0 && zv2 < 0 && rejected2) {
possibleTwoCycle = true;
} else if (rejected1 && rejected2) {
possibleTwoCycle = true;
}
if (!possibleTwoCycle) {
return false;
}
}
return true;
}
Aggregations