Changeset 196 for trunk/sources
- Timestamp:
- 04/25/08 16:09:38 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataAnalysis/Dataset.cs
r195 r196 39 39 private double[] samples; 40 40 private int rows; 41 Dictionary<int, Dictionary<int, double>>[] cachedMeans; 42 Dictionary<int, Dictionary<int, double>>[] cachedRanges; 41 43 42 44 public int Rows { … … 50 52 set { columns = value; } 51 53 } 52 private Dictionary<int, double[]>[] ranges;53 private Dictionary<int, double[]>[] means;54 54 55 55 public double GetValue(int i, int j) { … … 94 94 // keep a means and ranges dictionary for each column (possible target variable) of the dataset. 95 95 96 means = new Dictionary<int, double[]>[columns];97 ranges = new Dictionary<int, double[]>[columns];96 cachedMeans = new Dictionary<int, Dictionary<int, double>>[columns]; 97 cachedRanges = new Dictionary<int, Dictionary<int, double>>[columns]; 98 98 99 99 for(int i = 0; i < columns; i++) { 100 means[i] = new Dictionary<int, double[]>();101 ranges[i] = new Dictionary<int, double[]>();100 cachedMeans[i] = new Dictionary<int, Dictionary<int, double>>(); 101 cachedRanges[i] = new Dictionary<int, Dictionary<int, double>>(); 102 102 } 103 103 } … … 201 201 202 202 public double GetMean(int column, int from, int to) { 203 double[] values = new double[to - from + 1]; 204 for(int sample = from; sample <= to; sample++) { 205 values[sample - from] = GetValue(sample, column); 206 } 207 208 return Statistics.Mean(values); 203 if(!cachedMeans[column].ContainsKey(from) || !cachedMeans[column][from].ContainsKey(to)) { 204 double[] values = new double[to - from + 1]; 205 for(int sample = from; sample <= to; sample++) { 206 values[sample - from] = GetValue(sample, column); 207 } 208 double mean = Statistics.Mean(values); 209 if(!cachedMeans[column].ContainsKey(from)) cachedMeans[column][from] = new Dictionary<int, double>(); 210 cachedMeans[column][from][to] = mean; 211 return mean; 212 } else { 213 return cachedMeans[column][from][to]; 214 } 209 215 } 210 216 … … 214 220 215 221 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 221 return Statistics.Range(values); 222 if(!cachedRanges[column].ContainsKey(from) || !cachedRanges[column][from].ContainsKey(to)) { 223 double[] values = new double[to - from + 1]; 224 for(int sample = from; sample <= to; sample++) { 225 values[sample - from] = GetValue(sample, column); 226 } 227 double range = Statistics.Range(values); 228 if(!cachedRanges[column].ContainsKey(from)) cachedRanges[column][from] = new Dictionary<int, double>(); 229 cachedRanges[column][from][to] = range; 230 return range; 231 } else { 232 return cachedRanges[column][from][to]; 233 } 222 234 } 223 235 }
Note: See TracChangeset
for help on using the changeset viewer.