Changeset 8152 for trunk/sources
- Timestamp:
- 06/28/12 16:15:16 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs
r8151 r8152 56 56 57 57 [Storable] 58 private Dictionary<IRegressionModel, IntRange> trainingPartitions;58 private readonly Dictionary<IRegressionModel, IntRange> trainingPartitions; 59 59 [Storable] 60 private Dictionary<IRegressionModel, IntRange> testPartitions;60 private readonly Dictionary<IRegressionModel, IntRange> testPartitions; 61 61 62 62 [StorableConstructor] … … 156 156 #region Evaluation 157 157 public override IEnumerable<double> EstimatedTrainingValues { 158 get { return GetEstimatedValues(ProblemData.TrainingIndices, (r, m) => RowIsTrainingForModel(r, m) && !RowIsTestForModel(r, m)); } 158 get { 159 var rows = ProblemData.TrainingIndices; 160 var rowsToEvaluate = rows.Except(trainingEstimatedValuesCache.Keys); 161 var rowsEnumerator = rowsToEvaluate.GetEnumerator(); 162 var valuesEnumerator = GetEstimatedValues(rowsToEvaluate, (r, m) => RowIsTrainingForModel(r, m) && !RowIsTestForModel(r, m)).GetEnumerator(); 163 164 while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) { 165 trainingEstimatedValuesCache.Add(rowsEnumerator.Current, valuesEnumerator.Current); 166 } 167 168 return rows.Select(row => trainingEstimatedValuesCache[row]); 169 } 159 170 } 160 171 161 172 public override IEnumerable<double> EstimatedTestValues { 162 get { return GetEstimatedValues(ProblemData.TestIndices, RowIsTestForModel); } 173 get { 174 var rows = ProblemData.TestIndices; 175 var rowsToEvaluate = rows.Except(testEstimatedValuesCache.Keys); 176 var rowsEnumerator = rowsToEvaluate.GetEnumerator(); 177 var valuesEnumerator = GetEstimatedValues(rowsToEvaluate, RowIsTestForModel).GetEnumerator(); 178 179 while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) { 180 testEstimatedValuesCache.Add(rowsEnumerator.Current, valuesEnumerator.Current); 181 } 182 183 return rows.Select(row => testEstimatedValuesCache[row]); 184 } 163 185 } 164 186 … … 191 213 192 214 public override IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) { 193 return from xs in GetEstimatedValueVectors(ProblemData.Dataset, rows) 194 select AggregateEstimatedValues(xs); 215 var rowsToEvaluate = rows.Except(estimatedValuesCache.Keys); 216 var rowsEnumerator = rowsToEvaluate.GetEnumerator(); 217 var valuesEnumerator = (from xs in GetEstimatedValueVectors(ProblemData.Dataset, rowsToEvaluate) 218 select AggregateEstimatedValues(xs)) 219 .GetEnumerator(); 220 221 while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) { 222 estimatedValuesCache.Add(rowsEnumerator.Current, valuesEnumerator.Current); 223 } 224 225 return rows.Select(row => estimatedValuesCache[row]); 195 226 } 196 227 … … 213 244 214 245 protected override void OnProblemDataChanged() { 246 trainingEstimatedValuesCache.Clear(); 247 testEstimatedValuesCache.Clear(); 248 estimatedValuesCache.Clear(); 215 249 IRegressionProblemData problemData = new RegressionProblemData(ProblemData.Dataset, 216 250 ProblemData.AllowedInputVariables, … … 241 275 public void AddRegressionSolutions(IEnumerable<IRegressionSolution> solutions) { 242 276 regressionSolutions.AddRange(solutions); 277 278 trainingEstimatedValuesCache.Clear(); 279 testEstimatedValuesCache.Clear(); 280 estimatedValuesCache.Clear(); 243 281 } 244 282 public void RemoveRegressionSolutions(IEnumerable<IRegressionSolution> solutions) { 245 283 regressionSolutions.RemoveRange(solutions); 284 285 trainingEstimatedValuesCache.Clear(); 286 testEstimatedValuesCache.Clear(); 287 estimatedValuesCache.Clear(); 246 288 } 247 289 … … 265 307 trainingPartitions[solution.Model] = solution.ProblemData.TrainingPartition; 266 308 testPartitions[solution.Model] = solution.ProblemData.TestPartition; 309 310 trainingEstimatedValuesCache.Clear(); 311 testEstimatedValuesCache.Clear(); 312 estimatedValuesCache.Clear(); 267 313 } 268 314 … … 272 318 trainingPartitions.Remove(solution.Model); 273 319 testPartitions.Remove(solution.Model); 320 321 trainingEstimatedValuesCache.Clear(); 322 testEstimatedValuesCache.Clear(); 323 estimatedValuesCache.Clear(); 274 324 } 275 325 }
Note: See TracChangeset
for help on using the changeset viewer.