Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14608


Ignore:
Timestamp:
01/25/17 16:37:11 (7 years ago)
Author:
bburlacu
Message:

#2635: Simplify code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.OSGAEvaluator/HeuristicLab.OSGAEvaluator/SymbolicRegressionSingleObjectiveOSGAEvaluator.cs

    r14585 r14608  
    231231      if (UseFixedEvaluationIntervals) {
    232232        double threshold = parentQuality * RelativeParentChildQualityThreshold;
     233
    233234        if (UseAdaptiveQualityThreshold) {
    234235          var actualSelectionPressure = ActualSelectionPressureParameter.ActualValue;
     
    248249        if (AggregateStatistics) {
    249250          var trainingEnd = problemData.TrainingPartition.End;
    250           var qualityPerInterval = new List<double>();
     251
     252          double quality = -1;
     253          int intervalCount = 0, rejectionInterval = 0;
     254          bool predictedRejected = false;
     255
    251256          while (estimatedEnumerator.MoveNext() & targetEnumerator.MoveNext()) {
    252257            var estimated = estimatedEnumerator.Current;
    253258            var target = targetEnumerator.Current;
    254             rcalc.Add(estimated, target);
     259            rcalc.Add(target, estimated);
    255260            ++calculatedRows;
    256261            if (calculatedRows % interval == 0 || calculatedRows == trainingPartitionSize) {
     262              intervalCount++;
     263              if (predictedRejected) continue;
    257264              var r = rcalc.ErrorState == OnlineCalculatorError.None ? rcalc.R : 0d;
    258               qualityPerInterval.Add(r * r);
    259             }
    260           }
    261           double quality;
    262           {
    263             var r = rcalc.ErrorState != OnlineCalculatorError.None ? 0d : rcalc.R;
    264             var actualQuality = r * r;
    265             quality = actualQuality;
    266             bool predictedRejected = false;
    267 
    268             int i;
    269 
    270             for (i = 0; i < qualityPerInterval.Count; ++i) {
    271               var q = qualityPerInterval[i];
    272               if (double.IsNaN(q) || !(q > threshold)) {
     265              quality = r * r;
     266              if (!(quality > threshold)) {
     267                rejectionInterval = intervalCount - 1;
    273268                predictedRejected = true;
    274                 quality = q;
    275                 break;
    276269              }
    277270            }
    278 
    279             var actuallyRejected = !(actualQuality > parentQuality);
    280 
    281             if (RejectedStats.Rows == 0 || TotalStats.Rows == 0) {
    282               RejectedStats = new IntMatrix(2, qualityPerInterval.Count + 1);
    283               RejectedStats.RowNames = new[] { "Predicted", "Actual" };
    284               RejectedStats.ColumnNames = Enumerable.Range(1, RejectedStats.Columns).Select(x => string.Format("0-{0}", Math.Min(trainingEnd, x * interval)));
    285               TotalStats = new IntMatrix(2, 1);
    286               TotalStats.RowNames = new[] { "Predicted", "Actual" };
    287               TotalStats.ColumnNames = new[] { "Rejected" };
    288             }
    289 
    290             if (actuallyRejected) {
    291               TotalStats[0, 0]++; // prediction true
    292               TotalStats[1, 0]++;
    293               RejectedStats[0, i]++;
    294               RejectedStats[1, i]++;
    295             } else {
    296               if (predictedRejected) {
    297                 RejectedStats[0, i]++;
    298                 TotalStats[0, 0]++;
    299               }
     271          }
     272          var actualQuality = rcalc.ErrorState == OnlineCalculatorError.None ? rcalc.R : 0d;
     273          actualQuality *= actualQuality;
     274
     275          var actuallyRejected = !(actualQuality > parentQuality);
     276
     277          if (RejectedStats.Rows == 0 || TotalStats.Rows == 0) {
     278            RejectedStats = new IntMatrix(2, intervalCount + 1);
     279            RejectedStats.RowNames = new[] { "Predicted", "Actual" };
     280            RejectedStats.ColumnNames = Enumerable.Range(1, RejectedStats.Columns).Select(x => string.Format("0-{0}", Math.Min(trainingEnd, x * interval)));
     281            TotalStats = new IntMatrix(2, 1);
     282            TotalStats.RowNames = new[] { "Predicted", "Actual" };
     283            TotalStats.ColumnNames = new[] { "Rejected" };
     284          }
     285
     286          if (actuallyRejected) {
     287            TotalStats[0, 0]++; // prediction true
     288            TotalStats[1, 0]++;
     289            RejectedStats[0, rejectionInterval]++;
     290            RejectedStats[1, rejectionInterval]++;
     291          } else {
     292            if (predictedRejected) {
     293              RejectedStats[0, rejectionInterval]++;
     294              TotalStats[0, 0]++;
    300295            }
    301296          }
Note: See TracChangeset for help on using the changeset viewer.