public boolean isIndependent(Node x, Node y, List<Node> z) { int[] all = new int[z.size() + 2]; all[0] = variablesMap.get(x); all[1] = variablesMap.get(y); for (int i = 0; i < z.size(); i++) { all[i + 2] = variablesMap.get(z.get(i)); } int sampleSize = data.get(0).rows(); List<Double> pValues = new ArrayList<Double>(); for (int m = 0; m < ncov.size(); m++) { TetradMatrix _ncov = ncov.get(m).getSelection(all, all); TetradMatrix inv = _ncov.inverse(); double r = -inv.get(0, 1) / sqrt(inv.get(0, 0) * inv.get(1, 1)); double fisherZ = sqrt(sampleSize - z.size() - 3.0) * 0.5 * (Math.log(1.0 + r) - Math.log(1.0 - r)); double pValue; if (Double.isInfinite(fisherZ)) { pValue = 0; } else { pValue = 2.0 * (1.0 - RandomUtil.getInstance().normalCdf(0, 1, abs(fisherZ))); } pValues.add(pValue); } double _cutoff = alpha; if (fdr) { _cutoff = StatUtils.fdrCutoff(alpha, pValues, false); } Collections.sort(pValues); int index = (int) round((1.0 - percent) * pValues.size()); this.pValue = pValues.get(index); // if (this.pValue == 0) { // System.out.println("Zero pvalue "+ SearchLogUtils.independenceFactMsg(x, y, z, // getPValue())); // } boolean independent = this.pValue > _cutoff; if (verbose) { if (independent) { TetradLogger.getInstance() .log("independencies", SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); // System.out.println(SearchLogUtils.independenceFactMsg(x, y, z, getPValue())); } else { TetradLogger.getInstance() .log("dependencies", SearchLogUtils.dependenceFactMsg(x, y, z, getPValue())); } } return independent; }
/*Generates a random exponential distribution random time difference vs. timeIn based on the frequency lambda */ private double nextRandomTime(double lambda) { double timeLag = 0; /*System.out.println("I am computing nextRandomTime"); System.out.println("When I am getting timeIn of " +timeIn+" and lambda of "+lambda);*/ double random = Math.random(); timeLag = -Math.log(random) / (lambda / (LENGTHOFADAY * 1000)); /*System.out.println("I am returning a time difference of "+timeLag);*/ return timeLag; }
/** * Calculates the binary logarithm. * * @param x a <code>double</code> value * @return log2(x) */ private double log2(double x) { return Math.log(x) / Math.log(2); }
/** poprawka szerokosci dla w/h >= 1/(2ă) */ private double FDW2(double epf, double w, double h) { DWType = "DW2"; /* slad - ktory wzor byl ostatni */ return 1.25 / pi * t * (1 + Math.log(2 * h / t)); }
/** wyliczenie Z0 dla w/h >= 1 */ private double FZ2(double epf, double we, double h) { FZType = "FZ2"; /* slad - ktory wzor byl ostatni */ return 376.7 / (Math.sqrt(epf) * (we / h + 1.393 + 0.667 * Math.log(we / h + 1.444))); }
/** wyliczenie Z0 dla w/h <= 1 */ private double FZ1(double epf, double we, double h) { FZType = "FZ1"; /* slad - ktory wzor byl ostatni */ return 60 / Math.sqrt(epf) * Math.log(8 * h / we + 0.25 * we / h); }