@Test
  public void testResults() throws InterruptedException {
    TaskUtil.run(d_model.getActivityTask());

    assertTrue(d_model.isReady());

    final InconsistencyParameter w =
        new InconsistencyParameter(Arrays.asList(d_ta, d_tb, d_tc, d_ta));
    assertEquals(Collections.singletonList(w), d_model.getInconsistencyFactors());

    double[] dAB =
        ResultsUtil.getSamples(d_model.getResults(), d_model.getRelativeEffect(d_ta, d_tb), 3);
    double[] dBC =
        ResultsUtil.getSamples(d_model.getResults(), d_model.getRelativeEffect(d_tb, d_tc), 3);
    double[] wABC = ResultsUtil.getSamples(d_model.getResults(), w, 3);

    // Values below obtained via a run through regular JAGS with 30k/20k
    // iterations. Taking .15 sd as acceptable margin (same as JAGS does
    // for testing against WinBUGS results).
    double mAB = 0.4713884;
    double sAB = 0.4838365;
    assertEquals(mAB, d_mean.evaluate(dAB), FACTOR * sAB);
    assertEquals(sAB, d_stdDev.evaluate(dAB), FACTOR * sAB);
    double mBC = -0.4645146;
    double sBC = 0.6111192;
    assertEquals(mBC, d_mean.evaluate(dBC), FACTOR * sBC);
    assertEquals(sBC, d_stdDev.evaluate(dBC), FACTOR * sBC);
    double mABC = -0.1466253;
    double sABC = 0.4568596;
    assertEquals(mABC, d_mean.evaluate(wABC), FACTOR * sABC);
    assertEquals(sABC, d_stdDev.evaluate(wABC), FACTOR * sABC);

    double[] dBA =
        ResultsUtil.getSamples(d_model.getResults(), d_model.getRelativeEffect(d_tb, d_ta), 3);
    assertEquals(-mAB, d_mean.evaluate(dBA), FACTOR * sAB);
    assertEquals(sAB, d_stdDev.evaluate(dBA), FACTOR * sAB);

    double[] dAC =
        ResultsUtil.getSamples(d_model.getResults(), d_model.getRelativeEffect(d_ta, d_tc), 3);
    double mAC = 0.1534991;
    double sAC = 0.5514409;
    assertEquals(mAC, d_mean.evaluate(dAC), FACTOR * sAC);
    assertEquals(sAC, d_stdDev.evaluate(dAC), FACTOR * sAC);
  }
예제 #2
0
  private void setFactor() {
    double[] array = new double[mappingReads.size()];
    int i = 0;
    for (Long l : mappingReads.values()) {
      array[i++] = l;
    }
    double meanReads = mean.evaluate(array);

    for (Map.Entry<String, Long> entry : mappingReads.entrySet()) {
      factor.put(entry.getKey(), meanReads / entry.getValue());
    }
  }
예제 #3
0
 private void addControlSamples(String result, Sample sample) {
   List<Double> list = new LinkedList<>();
   for (String s : controlSamples) {
     for (Map.Entry<String, Map<String, Sample>> entry : samples.entrySet()) {
       list.add(entry.getValue().get(s).getNorm1b());
     }
   }
   if (!list.isEmpty()) {
     double meanVal = mean.evaluate(toDoubleArray(list));
     StringBuilder builder = new StringBuilder(result);
     builder
         .append("\t")
         .append(
             String.format(
                 "%.3f%n", meanVal == 0 ? sample.getNorm1b() / meanVal / log.value(2) : 0));
   }
 }
예제 #4
0
 /**
  * Computes the covariance between the two arrays.
  *
  * <p>Array lengths must match and the common length must be at least 2.
  *
  * @param xArray first data array
  * @param yArray second data array
  * @param biasCorrected if true, returned value will be bias-corrected
  * @return returns the covariance for the two arrays
  * @throws MathIllegalArgumentException if the arrays lengths do not match or there is
  *     insufficient data
  */
 public double covariance(final double[] xArray, final double[] yArray, boolean biasCorrected)
     throws MathIllegalArgumentException {
   Mean mean = new Mean();
   double result = 0d;
   int length = xArray.length;
   if (length != yArray.length) {
     throw new MathIllegalArgumentException(
         LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, length, yArray.length);
   } else if (length < 2) {
     throw new MathIllegalArgumentException(
         LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, length, 2);
   } else {
     double xMean = mean.evaluate(xArray);
     double yMean = mean.evaluate(yArray);
     for (int i = 0; i < length; i++) {
       double xDev = xArray[i] - xMean;
       double yDev = yArray[i] - yMean;
       result += (xDev * yDev - result) / (i + 1);
     }
   }
   return biasCorrected ? result * ((double) length / (double) (length - 1)) : result;
 }
예제 #5
0
 public static Double mean(double[] values) {
   Mean meanCalculator = new Mean();
   return meanCalculator.evaluate(values);
 }