Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7996 for trunk/sources


Ignore:
Timestamp:
06/13/12 09:09:36 (12 years ago)
Author:
mkommend
Message:

#1871: Improved performance of ProportionalSelector.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Selection/3.3/ProportionalSelector.cs

    r7995 r7996  
    6969      // prepare qualities for proportional selection
    7070      var qualities = QualityParameter.ActualValue.Select(x => x.Value);
    71       //check if list with indexes is as long as the original scope list
    72       //otherwise invalid quality values were filtered
    73       if (!qualities.All(IsValidQuality)) {
    74         throw new ArgumentException("The scopes contain invalid quality values (either infinity or double.NaN) on which the selector cannot operate.");
     71      double minQuality = double.MaxValue;
     72      double maxQuality = double.MinValue;
     73      foreach (var quality in qualities) {
     74        if (!IsValidQuality(quality)) throw new ArgumentException("The scopes contain invalid quality values (either infinity or double.NaN) on which the selector cannot operate.");
     75        if (quality < minQuality) minQuality = quality;
     76        if (quality > maxQuality) maxQuality = quality;
    7577      }
    7678
    77       double minQuality = qualities.Min();
    78       double maxQuality = qualities.Max();
    7979      if (minQuality == maxQuality) {  // all quality values are equal
    8080        qualities = qualities.Select(x => 1.0);
     
    9595
    9696      List<double> list = qualities.ToList();
    97       double qualitySum = qualities.Sum();
     97      double qualitySum = list.Sum();
    9898      for (int i = 0; i < count; i++) {
    9999        double selectedQuality = random.NextDouble() * qualitySum;
Note: See TracChangeset for help on using the changeset viewer.