public static double Calculate(IEnumerable <double> originalValues, IEnumerable <double> estimatedValues, double lowerBound, double upperBound, out OnlineCalculatorError errorState)
        {
            IEnumerator <double> originalEnumerator  = originalValues.GetEnumerator();
            IEnumerator <double> estimatedEnumerator = estimatedValues.GetEnumerator();
            OnlineBoundedMeanSquaredErrorCalculator boundedMseCalculator = new OnlineBoundedMeanSquaredErrorCalculator(lowerBound, upperBound);

            // always move forward both enumerators (do not use short-circuit evaluation!)
            while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext())
            {
                double original  = originalEnumerator.Current;
                double estimated = estimatedEnumerator.Current;
                boundedMseCalculator.Add(original, estimated);
                if (boundedMseCalculator.ErrorState != OnlineCalculatorError.None)
                {
                    break;
                }
            }

            // check if both enumerators are at the end to make sure both enumerations have the same length
            if (boundedMseCalculator.ErrorState == OnlineCalculatorError.None &&
                (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()))
            {
                throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match.");
            }
            else
            {
                errorState = boundedMseCalculator.ErrorState;
                return(boundedMseCalculator.BoundedMeanSquaredError);
            }
        }
 protected OnlineBoundedMeanSquaredErrorCalculator(OnlineBoundedMeanSquaredErrorCalculator original, Cloner cloner)
     : base(original, cloner)
 {
     LowerBound = original.LowerBound;
     UpperBound = original.UpperBound;
     n          = original.n;
     errorSum   = original.errorSum;
     errorState = original.ErrorState;
 }
    public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, double lowerBound, double upperBound, out OnlineCalculatorError errorState) {
      IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
      IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
      OnlineBoundedMeanSquaredErrorCalculator boundedMseCalculator = new OnlineBoundedMeanSquaredErrorCalculator(lowerBound, upperBound);

      // always move forward both enumerators (do not use short-circuit evaluation!)
      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
        double original = originalEnumerator.Current;
        double estimated = estimatedEnumerator.Current;
        boundedMseCalculator.Add(original, estimated);
        if (boundedMseCalculator.ErrorState != OnlineCalculatorError.None) break;
      }

      // check if both enumerators are at the end to make sure both enumerations have the same length
      if (boundedMseCalculator.ErrorState == OnlineCalculatorError.None &&
         (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) {
        throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match.");
      } else {
        errorState = boundedMseCalculator.ErrorState;
        return boundedMseCalculator.BoundedMeanSquaredError;
      }
    }