Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/08/16 15:30:46 (8 years ago)
Author:
bwerth
Message:

#1087 several fixes according to the reviev comments in comment 31

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/NormalizedHypervolumeAnalyzer.cs

    r13771 r14030  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    4546
    4647    #region Names
    47     private const string bestKnownFront = "BestKnownFront_2";
     48    private const string bestKnownFront = "BestKnownFront Zitzler";
    4849    private const string resultsHV = "NormalizedHypervolume";
    4950    private const string resultsDist = "Absolute Distance to Normalized BestKnownHypervolume";
     
    9091      }
    9192
    92       double diff;
     93      IEnumerable<double[]> front = NonDominatedSelect.selectNonDominatedVectors(qualities, TestFunctionParameter.ActualValue.Maximization(objectives), true);
    9394
    9495      if (!results.ContainsKey(resultsHV)) results.Add(new Result(resultsHV, typeof(DoubleValue)));
    95       IEnumerable<double[]> front = NonDominatedSelect.selectNonDominatedVectors(qualities, TestFunctionParameter.ActualValue.Maximization(objectives), true);
     96      if (!results.ContainsKey(resultsDist)) results.Add(new Result(resultsDist, typeof(DoubleValue)));
    9697      if (!results.ContainsKey(bestknownHV)) results.Add(new Result(bestknownHV, typeof(DoubleValue)));
    9798      else {
     
    99100        best = dv.Value;
    100101      }
    101       if (!results.ContainsKey(resultsDist)) results.Add(new Result(resultsDist, typeof(DoubleValue)));
    102 
    103       double hv = Double.NaN;
    104102
    105103      bool[] maximization = TestFunctionParameter.ActualValue.Maximization(objectives);
    106104      double[] invPoint = GetBestPoint(OptimalFrontParameter.Value, maximization);
    107105      double[] refPoint = GetWorstPoint(OptimalFrontParameter.Value, maximization);
    108       double normalization = GetHypervolume(refPoint, invPoint);
     106      double normalization = Hypervolume.Calculate(new double[][] { invPoint }, refPoint, maximization);
     107      double hv = front.Any() ? Hypervolume.Calculate(front, refPoint, maximization) / normalization : 0;
    109108
    110 
    111       try {
    112         if (objectives == 2) { //Hypervolume analysis only with 2 objectives for now
    113           hv = Hypervolume.Calculate(front, refPoint, maximization);
    114         } else if (Array.TrueForAll(maximization, x => !x)) {
    115           hv = MultiDimensionalHypervolume.Calculate(front, refPoint);
    116         }
    117       }
    118       catch (ArgumentException) {
    119 
    120       }
    121 
    122       hv /= normalization;
    123 
    124       if (best < 0) {
    125         best = hv;
    126       }
     109      if (Double.IsNaN(best)) best = hv; else best = Math.Max(best, hv);
     110      double diff;
    127111      diff = best - hv;
    128       if (!Double.IsNaN(hv) && (diff < 0 || best < 0)) {
    129         best = hv;
    130         diff = 0;
     112      if (diff == 0) {
    131113        BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities));
    132114      }
     
    136118      results[bestknownHV].Value = new DoubleValue(best);
    137119
    138     }
    139 
    140     private double GetHypervolume(double[] refPoint, double[] invPoint) {
    141       if (refPoint.Length == 0) return 0;
    142       double hv = 1;
    143       for (int i = 0; i < refPoint.Length; i++) {
    144         hv *= Math.Abs(refPoint[i] - invPoint[i]);
    145       }
    146       return hv;
    147120    }
    148121
Note: See TracChangeset for help on using the changeset viewer.