Changeset 195 for trunk/sources/HeuristicLab.DataAnalysis
- Timestamp:
- 04/25/08 15:30:02 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataAnalysis/Dataset.cs
r132 r195 200 200 } 201 201 202 // return value of GetMean should be memoized because it is called repeatedly in Evaluators203 202 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 calculated209 return fromMeans[to-from];210 } else {211 // not yet calculated => calculate212 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-index217 double[] fromMeans = new double[rows - from];218 // fill with negative values to indicate which means have already been calculated219 for(int i=0;i<fromMeans.Length;i++) {fromMeans[i] = -1.0;}220 // store new array in the dictionary221 columnMeans[from] = fromMeans;222 // calculate for specific to-index223 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 Evaluators242 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 calculated248 return fromRanges[to-from];249 } else {250 // not yet calculated => calculate251 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-index256 double[] fromRanges = new double[rows - from];257 // fill with negative values to indicate which means have already been calculated258 for(int i = 0; i < fromRanges.Length; i++) { fromRanges[i] = -1.0; }259 // store in dictionary260 columnRanges[from] = fromRanges;261 // calculate for specific to-index262 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) {268 203 double[] values = new double[to - from + 1]; 269 204 for(int sample = from; sample <= to; sample++) { … … 271 206 } 272 207 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 273 221 return Statistics.Range(values); 274 222 }
Note: See TracChangeset
for help on using the changeset viewer.