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;
  }
 public long pack(ArrayList<Integer> at) {
   Collections.sort(at);
   long a = 0;
   for (int i = 0; i < N; i++) {
     a |= (at.get(i) << (6 * i));
   }
   return a;
 }
Exemple #3
0
 int calc(int cnt) {
   ArrayList<Integer> lst = new ArrayList<Integer>();
   for (int i = 0; i < weight.length; ++i)
     if (weight[i] >= cnt) {
       int r = 0;
       for (int j = list[i].size() - 1, k = 0; k < cnt; --j, ++k) r += list[i].get(j);
       lst.add(r);
     }
   Collections.sort(lst);
   int ret = 0;
   for (int i = lst.size() - 1, j = 0; j < k; ++j, --i) ret += lst.get(i);
   return ret;
 }
  private static Collection<PerformanceProbe> list(long period) {
    if (period == ALL_RECORDERS) {
      Collection<PerformanceProbe> result = new Vector<PerformanceProbe>();
      for (Collection<PerformanceProbe> probes : _perfProbes.values()) {
        result.addAll(probes);
      }
      return result;
    }

    Collection<PerformanceProbe> result = _perfProbes.get(period);
    if (result == null) {
      return Collections.emptySet();
    }
    return result;
  }
Exemple #5
0
 void solve() throws IOException {
   n = ni();
   k = ni();
   w = new int[n];
   c = new int[n];
   for (int i = 0; i < n; ++i) {
     w[i] = ni();
     c[i] = ni();
   }
   for (int i = 0; i < list.length; i++) {
     list[i] = new ArrayList<Integer>();
   }
   for (int i = 0; i < n; ++i) {
     weight[w[i]]++;
     list[w[i]].add(c[i]);
   }
   for (int i = 0; i < list.length; i++) {
     Collections.sort(list[i]);
   }
   int ret = count();
   out.println(ret + " " + calc(ret));
 }
Exemple #6
0
 /*Create an array list of random orders for the available status - this will help put the equipment randomly*/
 private void randomizeOrderRent() {
   for (int counter = 0; counter < RENTCAPACITYX * RENTCAPACITYY; counter++) {
     randomOrder.add(counter);
   }
   Collections.shuffle(randomOrder);
 }