Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/13/09 15:38:26 (15 years ago)
Author:
gkronber
Message:

fixed calculation of range of a variable (to ignore NaNs) and fixed calculation of maxPunishment in the BakedTreeEvaluator. #615 (Evaluation of HL3 function trees should be equivalent to evaluation in HL2)

File:
1 edited

Legend:

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

    r1529 r1786  
    4141      T minimum = enumerator.Current;
    4242
    43       while(enumerator.MoveNext()) {
     43      while (enumerator.MoveNext()) {
    4444        T current = enumerator.Current;
    45         if(current.CompareTo(minimum) < 0) {
     45        if (current.CompareTo(minimum) < 0) {
    4646          minimum = current;
    4747        }
     
    6565      T maximum = enumerator.Current;
    6666
    67       while(enumerator.MoveNext()) {
     67      while (enumerator.MoveNext()) {
    6868        T current = enumerator.Current;
    69         if(current.CompareTo(maximum) > 0) {
     69        if (current.CompareTo(maximum) > 0) {
    7070          maximum = current;
    7171        }
     
    9999    /// <returns></returns>
    100100    public static double Range(double[] values, int start, int end) {
    101       if(start < 0 || start > values.Length || end < 0 || end > values.Length || start > end) {
     101      if (start < 0 || start > values.Length || end < 0 || end > values.Length || start > end) {
    102102        throw new InvalidOperationException();
    103103      }
     
    105105      double minimum = values[start];
    106106      double maximum = minimum;
    107       for(int i = start; i < end; i++) {
    108         if(values[i] > maximum) {
    109           maximum = values[i];
    110         }
    111         if(values[i] < minimum) {
    112           minimum = values[i];
     107      for (int i = start; i < end; i++) {
     108        if (!double.IsNaN(values[i])) {
     109          if (values[i] > maximum) {
     110            maximum = values[i];
     111          }
     112          if (values[i] < minimum) {
     113            minimum = values[i];
     114          }
    113115        }
    114116      }
     
    124126      int n = values.Length;
    125127      double sum = 0.0;
    126       for(int i = 0; i < n; i++) {
    127         if(double.IsNaN(values[i])) {
     128      for (int i = 0; i < n; i++) {
     129        if (double.IsNaN(values[i])) {
    128130          throw new NotFiniteNumberException();
    129131        } else {
     
    156158    /// <returns></returns>
    157159    public static double Mean(double[] values, int start, int end) {
    158       if(values.Length == 0) throw new InvalidOperationException();
     160      if (values.Length == 0) throw new InvalidOperationException();
    159161      double sum = 0.0;
    160162      int n = 0;
    161       for(int i = start; i < end; i++) {
    162         if(!double.IsNaN(values[i])) {
     163      for (int i = start; i < end; i++) {
     164        if (!double.IsNaN(values[i])) {
    163165          sum += values[i];
    164166          n++;
     
    175177    /// <returns></returns>
    176178    public static double Median(double[] values) {
    177       if(values.Length == 0) throw new InvalidOperationException();
     179      if (values.Length == 0) throw new InvalidOperationException();
    178180      int n = values.Length;
    179       if(n == 0)
     181      if (n == 0)
    180182        return 0;
    181183
     
    186188
    187189      // return the middle element (if n is uneven) or the average of the two middle elements if n is even.
    188       if(n % 2 == 1) {
     190      if (n % 2 == 1) {
    189191        return sortedValues[n / 2];
    190192      } else {
Note: See TracChangeset for help on using the changeset viewer.