Free cookie consent management tool by TermsFeed Policy Generator

Changeset 195


Ignore:
Timestamp:
04/25/08 15:30:02 (16 years ago)
Author:
gkronber
Message:

removed silly bug-ridden code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataAnalysis/Dataset.cs

    r132 r195  
    200200    }
    201201
    202     // return value of GetMean should be memoized because it is called repeatedly in Evaluators
    203202    public double GetMean(int column, int from, int to) {
    204       Dictionary<int, double[]> columnMeans = means[column];
    205       if(columnMeans.ContainsKey(from)) {
    206         double[] fromMeans = columnMeans[from];
    207         if(fromMeans[to-from] >= 0.0) {
    208           // already calculated
    209           return fromMeans[to-from];
    210         } else {
    211           // not yet calculated => calculate
    212           fromMeans[to-from] = CalculateMean(column, from, to);
    213           return fromMeans[to-from];
    214         }
    215       } else {
    216         // never saw this from-index => create a new array, initialize and recalculate for to-index
    217         double[] fromMeans = new double[rows - from];
    218         // fill with negative values to indicate which means have already been calculated
    219         for(int i=0;i<fromMeans.Length;i++) {fromMeans[i] = -1.0;}
    220         // store new array in the dictionary
    221         columnMeans[from] = fromMeans;
    222         // calculate for specific to-index
    223         fromMeans[to-from] = CalculateMean(column, from, to);
    224         return fromMeans[to-from];
    225       }
    226     }
    227 
    228     private double CalculateMean(int column, int from, int to) {
    229       double[] values = new double[to - from +1];
    230       for(int sample = from; sample <= to; sample++) {
    231         values[sample - from] = GetValue(sample, column);
    232       }
    233 
    234       return Statistics.Mean(values);
    235     }
    236 
    237     public double GetRange(int column) {
    238       return GetRange(column, 0, Rows-1);
    239     }
    240 
    241     // return value of GetRange should be memoized because it is called repeatedly in Evaluators
    242     public double GetRange(int column, int from, int to) {
    243       Dictionary<int, double[]> columnRanges = ranges[column];
    244       if(columnRanges.ContainsKey(from)) {
    245         double[] fromRanges = columnRanges[from];
    246         if(fromRanges[to-from] >= 0.0) {
    247           // already calculated
    248           return fromRanges[to-from];
    249         } else {
    250           // not yet calculated => calculate
    251           fromRanges[to-from] = CalculateRange(column, from, to);
    252           return fromRanges[to-from];
    253         }
    254       } else {
    255         // never saw this from-index => create a new array, initialize and recalculate for to-index
    256         double[] fromRanges = new double[rows - from];
    257         // fill with negative values to indicate which means have already been calculated
    258         for(int i = 0; i < fromRanges.Length; i++) { fromRanges[i] = -1.0; }
    259         // store in dictionary
    260         columnRanges[from] = fromRanges;
    261         // calculate for specific to-index
    262         fromRanges[to-from] = CalculateRange(column, from, to);
    263         return fromRanges[to-from];
    264       }
    265     }
    266 
    267     private double CalculateRange(int column, int from, int to) {
    268203      double[] values = new double[to - from + 1];
    269204      for(int sample = from; sample <= to; sample++) {
     
    271206      }
    272207
     208      return Statistics.Mean(values);
     209    }
     210
     211    public double GetRange(int column) {
     212      return GetRange(column, 0, Rows-1);
     213    }
     214
     215    public double GetRange(int column, int from, int to) {
     216      double[] values = new double[to - from + 1];
     217      for(int sample = from; sample <= to; sample++) {
     218        values[sample - from] = GetValue(sample, column);
     219      }
     220
    273221      return Statistics.Range(values);
    274222    }
Note: See TracChangeset for help on using the changeset viewer.