class PartialMomentCalculator extends Function1D<double[], Double> {

  @Override
  public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x.length > 0, "x cannot be empty");
    final int n = x.length;
    final double[] copyX = Arrays.copyOf(x, n);
    Arrays.sort(copyX);
    double sum = 0;
    if (_useDownSide) {
      int i = 0;
      if (copyX[i] > _threshold) {
        return 0.;
      }
      while (i < n && copyX[i] < _threshold) {
        sum += (copyX[i] - _threshold) * (copyX[i] - _threshold);
        i++;
      }
      return Math.sqrt(sum / i);
    }
    int i = n - 1;
    int count = 0;
    if (copyX[i] < _threshold) {
      return 0.;
    }
    while (i >= 0 && copyX[i] > _threshold) {
      sum += (copyX[i] - _threshold) * (copyX[i] - _threshold);
      count++;
      i--;
    }
    return Math.sqrt(sum / count);
  }

  public  PartialMomentCalculator();
  public  PartialMomentCalculator(final double threshold, final boolean useDownSide);

}