Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6254


Ignore:
Timestamp:
05/23/11 16:12:38 (14 years ago)
Author:
gkronber
Message:

#1450: fixed bugs in calculation of estimated values in ensemble solutions for regression and classification.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs

    r6239 r6254  
    106106
    107107          var selectedEnumerators = from pair in estimatedValuesEnumerators
    108                                     where trainingPartitions == null || !trainingPartitions.ContainsKey(pair.Model) ||
    109                                          (trainingPartitions[pair.Model].Start <= currentRow && currentRow < trainingPartitions[pair.Model].End)
     108                                    where RowIsTrainingForModel(currentRow, pair.Model) && !RowIsTestForModel(currentRow, pair.Model)
    110109                                    select pair.EstimatedValuesEnumerator;
    111110          yield return AggregateEstimatedClassValues(selectedEnumerators.Select(x => x.Current));
     
    126125
    127126          var selectedEnumerators = from pair in estimatedValuesEnumerators
    128                                     where testPartitions == null || !testPartitions.ContainsKey(pair.Model) ||
    129                                       (testPartitions[pair.Model].Start <= currentRow && currentRow < testPartitions[pair.Model].End)
     127                                    where RowIsTestForModel(currentRow, pair.Model)
    130128                                    select pair.EstimatedValuesEnumerator;
    131129
     
    133131        }
    134132      }
     133    }
     134
     135    private bool RowIsTrainingForModel(int currentRow, IClassificationModel model) {
     136      return trainingPartitions == null || !trainingPartitions.ContainsKey(model) ||
     137              (trainingPartitions[model].Start <= currentRow && currentRow < trainingPartitions[model].End);
     138    }
     139
     140    private bool RowIsTestForModel(int currentRow, IClassificationModel model) {
     141      return testPartitions == null || !testPartitions.ContainsKey(model) ||
     142              (testPartitions[model].Start <= currentRow && currentRow < testPartitions[model].End);
    135143    }
    136144
     
    156164      .OrderBy(g => -g.Count())
    157165      .Select(g => g.Key)
     166      .DefaultIfEmpty(double.NaN)
    158167      .First();
    159168    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs

    r6239 r6254  
    101101
    102102          var selectedEnumerators = from pair in estimatedValuesEnumerators
    103                                     where trainingPartitions == null || !trainingPartitions.ContainsKey(pair.Model) ||
    104                                          (trainingPartitions[pair.Model].Start <= currentRow && currentRow < trainingPartitions[pair.Model].End)
     103                                    where RowIsTrainingForModel(currentRow, pair.Model) && !RowIsTestForModel(currentRow, pair.Model)
    105104                                    select pair.EstimatedValuesEnumerator;
    106105          yield return AggregateEstimatedValues(selectedEnumerators.Select(x => x.Current));
     
    121120
    122121          var selectedEnumerators = from pair in estimatedValuesEnumerators
    123                                     where testPartitions == null || !testPartitions.ContainsKey(pair.Model) ||
    124                                       (testPartitions[pair.Model].Start <= currentRow && currentRow < testPartitions[pair.Model].End)
     122                                    where RowIsTestForModel(currentRow, pair.Model)
    125123                                    select pair.EstimatedValuesEnumerator;
    126124
     
    128126        }
    129127      }
     128    }
     129
     130    private bool RowIsTrainingForModel(int currentRow, IRegressionModel model) {
     131      return trainingPartitions == null || !trainingPartitions.ContainsKey(model) ||
     132              (trainingPartitions[model].Start <= currentRow && currentRow < trainingPartitions[model].End);
     133    }
     134
     135    private bool RowIsTestForModel(int currentRow, IRegressionModel model) {
     136      return testPartitions == null || !testPartitions.ContainsKey(model) ||
     137              (testPartitions[model].Start <= currentRow && currentRow < testPartitions[model].End);
    130138    }
    131139
     
    148156    private double AggregateEstimatedValues(IEnumerable<double> estimatedValues) {
    149157      return estimatedValues.DefaultIfEmpty(double.NaN).Average();
    150     }   
     158    }
    151159  }
    152160}
Note: See TracChangeset for help on using the changeset viewer.