Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/06/09 17:12:37 (15 years ago)
Author:
gkronber
Message:

Improved handling of exceptional cases in data-based modeling evaluators. #688 (SimpleEvaluators should handle exceptional cases more gracefully)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataAnalysis/3.2/Statistics.cs

    r1788 r2136  
    119119
    120120    /// <summary>
    121     /// calculates the sum of all values.
    122     /// </summary>
    123     /// <param name="values"></param>
    124     /// <returns></returns>
    125     public static double Sum(double[] values) {
    126       int n = values.Length;
    127       double sum = 0.0;
    128       for (int i = 0; i < n; i++) {
    129         if (double.IsNaN(values[i])) {
    130           throw new NotFiniteNumberException();
    131         } else {
    132           sum += values[i];
    133         }
    134       }
    135       return sum;
    136     }
    137 
    138     /// <summary>
    139121    /// Calculates the mean of all values.
    140122    /// </summary>
     
    158140    /// <returns></returns>
    159141    public static double Mean(double[] values, int start, int end) {
    160       if (values.Length == 0) throw new InvalidOperationException();
     142      if (values.Length == 0) throw new ArgumentException("Values is empty.");
     143      if(end <=start) throw new ArgumentException("End is smaller or equal start");
    161144      double sum = 0.0;
    162145      int n = 0;
     
    167150        }
    168151      }
    169       if (n == 0) throw new InvalidOperationException();
    170       return sum / n;
     152      if (n > 0)
     153        return sum / n;
     154      else throw new ArgumentException("Only NaN elements in values");
    171155    }
    172156
     
    223207    /// <returns></returns>
    224208    public static double Variance(double[] values, int start, int end) {
     209      if (values.Length == 0) throw new ArgumentException("Values is empty.");
     210      if (end <= start) throw new ArgumentException("End is smaller or equal start");
    225211      if (end - start == 1)
    226212        return 0.0;
     
    238224      }
    239225      if (n < 2) {
    240         throw new InvalidOperationException();
     226        throw new ArgumentException("Only one non-NaN element in values");
    241227      }
    242228      return squaredErrorsSum / (n - 1);
Note: See TracChangeset for help on using the changeset viewer.