Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3868


Ignore:
Timestamp:
05/28/10 15:12:21 (14 years ago)
Author:
abeham
Message:

#1022

  • Changed WeightedParentsQualityComparator to allow ComparisonFactor values smaller than 0 or greater than 1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/WeightedParentsQualityComparator.cs

    r3659 r3868  
    6262      if (rightQualities.Length < 1) throw new InvalidOperationException(Name + ": No subscopes found.");
    6363      double compFact = ComparisonFactorParameter.ActualValue.Value;
    64       if (compFact < 0 || compFact > 1) throw new InvalidOperationException(Name + ": Comparison Factor is outside the range [0;1]");
    6564      bool maximization = MaximizationParameter.ActualValue.Value;
    6665      double leftQuality = LeftSideParameter.ActualValue.Value;
     
    7069      #region Calculate threshold
    7170      if (rightQualities.Length == 2) { // this case will probably be used most often
    72         threshold = (maximization ?
    73         (Math.Max(rightQualities[0].Value, rightQualities[1].Value) * compFact + Math.Min(rightQualities[0].Value, rightQualities[1].Value) * (1 - compFact)) :
    74         (Math.Min(rightQualities[0].Value, rightQualities[1].Value) * compFact + Math.Max(rightQualities[0].Value, rightQualities[1].Value) * (1 - compFact)));
     71        double minQuality = Math.Min(rightQualities[0].Value, rightQualities[1].Value);
     72        double maxQuality = Math.Max(rightQualities[0].Value, rightQualities[1].Value);
     73        if (maximization)
     74          threshold = minQuality + (maxQuality - minQuality) * compFact;
     75        else
     76          threshold = maxQuality - (maxQuality - minQuality) * compFact;
    7577      } else if (rightQualities.Length == 1) { // case for just one parent
    7678        threshold = rightQualities[0].Value;
     
    7880        List<double> sortedQualities = rightQualities.Select(x => x.Value).ToList();
    7981        sortedQualities.Sort();
    80         double min = sortedQualities.First() * -1; // min is used to pull the qualities to the 0 line
     82        double minimumQuality = sortedQualities.First();
    8183
    82         double sum = min * sortedQualities.Count;
     84        double integral = 0;
    8385        for (int i = 0; i < sortedQualities.Count - 1; i++) {
    84           sum += (sortedQualities[i] + sortedQualities[i + 1]) / 2.0; // sum of the trapezoid
     86          integral += (sortedQualities[i] + sortedQualities[i + 1]) / 2.0; // sum of the trapezoid
    8587        }
    86         if (sum == 0) threshold = sortedQualities[0]; // all qualities are equal
     88        integral -= minimumQuality * sortedQualities.Count;
     89        if (integral == 0) threshold = sortedQualities[0]; // all qualities are equal
    8790        else {
    88           double area = sum * (maximization ? compFact : (1 - compFact)); // the qualities are sorted ascending so in minimization a high comp factor (close to 1) means small area
    89           sum = 0;
     91          double selectedArea = integral * (maximization ? compFact : (1 - compFact));
     92          integral = 0;
    9093          for (int i = 0; i < sortedQualities.Count - 1; i++) {
    91             double currentArea = (sortedQualities[i] + sortedQualities[i + 1]) / 2.0;
    92             if (min + currentArea == 0) continue; // skip the first few consecutive 0s
    93             sum += min + currentArea;
    94             if (sum >= area) {
    95               double factor = 1 - ((sum - area) / (min + currentArea));
     94            double currentSliceArea = (sortedQualities[i] + sortedQualities[i + 1]) / 2.0;
     95            double windowedSliceArea = currentSliceArea - minimumQuality;
     96            if (windowedSliceArea == 0) continue;
     97            integral += windowedSliceArea;
     98            if (integral >= selectedArea) {
     99              double factor = 1 - ((integral - selectedArea) / (windowedSliceArea));
    96100              threshold = sortedQualities[i] + (sortedQualities[i + 1] - sortedQualities[i]) * factor;
    97101              break;
Note: See TracChangeset for help on using the changeset viewer.