示例#1
0
 private double calcTrimmedMean(PrimitiveDoubleArray vals, int halfTrim) {
   final int trimSize = halfTrim * 2;
   final int numElements = vals.size();
   if (numElements <= trimSize)
     throw new IllegalArgumentException(
         "number of samples must be greater than number of trimmed values");
   final int top = numElements - halfTrim;
   double sum = 0;
   for (int i = halfTrim; i < top; i++) {
     sum += vals.get(i);
   }
   return sum / (numElements - trimSize);
 }
示例#2
0
  /**
   * Computes the median upon the current region of the current function. Note that this method uses
   * memory to make a copy of the input values. Larger input regions might require a lot of memory.
   *
   * @return The measured value
   */
  public double median() {
    T tmp = func.createOutput();
    values.clear();
    iter.reset();
    while (iter.hasNext()) {
      long[] pos = iter.next();
      func.compute(pos, tmp);
      values.add(tmp.getRealDouble());
    }
    final int numElements = values.size();
    if (numElements <= 0)
      throw new IllegalArgumentException("number of samples must be greater than 0");

    values.sortValues();

    // odd number of elements
    if ((numElements % 2) == 1) return values.get(numElements / 2);

    // else an even number of elements
    double value1 = values.get((numElements / 2) - 1);
    double value2 = values.get((numElements / 2));
    return (value1 + value2) / 2;
  }