Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/12/16 18:20:50 (8 years ago)
Author:
mkommend
Message:

#1087: Refactored and improved analyzers for multi-objective test functions.

File:
1 edited

Legend:

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

    r14030 r14044  
    3232namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
    3333  [StorableClass]
    34   [Item("GenerationalDistanceAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")]
     34  [Item("NormalizedHypervolumeAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")]
    3535  public class NormalizedHypervolumeAnalyzer : MOTFAnalyzer {
    36     [StorableHook(HookType.AfterDeserialization)]
    37     private void AfterDeserialization() {
    38     }
    39     [StorableConstructor]
    40     protected NormalizedHypervolumeAnalyzer(bool deserializing) : base(deserializing) { }
    41     public NormalizedHypervolumeAnalyzer(NormalizedHypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) { }
    42     public override IDeepCloneable Clone(Cloner cloner) {
    43       return new NormalizedHypervolumeAnalyzer(this, cloner);
    44     }
    45 
    46 
    47     #region Names
    4836    private const string bestKnownFront = "BestKnownFront Zitzler";
    4937    private const string resultsHV = "NormalizedHypervolume";
     
    5139
    5240    private const string bestknownHV = "NormalizedBestKnownHyperVolume";
    53     #endregion
    5441
    55     #region parameters
    5642    public IValueParameter<DoubleMatrix> OptimalFrontParameter {
    57       get {
    58         return (IValueParameter<DoubleMatrix>)Parameters[bestKnownFront];
    59       }
     43      get { return (IValueParameter<DoubleMatrix>)Parameters[bestKnownFront]; }
    6044    }
    6145
    6246    public IValueParameter<DoubleValue> BestKnownHyperVolumeParameter {
    63       get {
    64         return (IValueParameter<DoubleValue>)Parameters[bestknownHV];
    65       }
    66       set {
    67         Parameters[bestknownHV].ActualValue = value;
    68       }
     47      get { return (IValueParameter<DoubleValue>)Parameters[bestknownHV]; }
    6948    }
    70     #endregion
    7149
    72     public NormalizedHypervolumeAnalyzer() {
    73       if (!Parameters.ContainsKey(bestKnownFront)) Parameters.Add(new ValueParameter<DoubleMatrix>(bestKnownFront, "The true / best known pareto front"));
    74       if (!Parameters.ContainsKey(bestknownHV)) Parameters.Add(new ValueParameter<DoubleValue>(bestknownHV, "The currently best known hypervolume"));
     50
     51    public NormalizedHypervolumeAnalyzer()
     52      : base() {
     53      Parameters.Add(new ValueParameter<DoubleMatrix>(bestKnownFront, "The true / best known pareto front"));
     54      Parameters.Add(new ValueParameter<DoubleValue>(bestknownHV, "The currently best known hypervolume"));
    7555    }
     56
     57    [StorableConstructor]
     58    protected NormalizedHypervolumeAnalyzer(bool deserializing) : base(deserializing) { }
     59    protected NormalizedHypervolumeAnalyzer(NormalizedHypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) { }
     60    public override IDeepCloneable Clone(Cloner cloner) {
     61      return new NormalizedHypervolumeAnalyzer(this, cloner);
     62    }
     63
    7664
    7765    private void RegisterEventHandlers() {
     
    8371    }
    8472
    85     public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) {
    86       if (qualities == null || qualities.Length < 1) return;
     73    public override IOperation Apply() {
     74      var results = ResultsParameter.ActualValue;
     75      var qualities = QualitiesParameter.ActualValue;
     76      var testFunction = TestFunctionParameter.ActualValue;
    8777      int objectives = qualities[0].Length;
     78
    8879      double best = BestKnownHyperVolumeParameter.Value.Value;
    8980      if (OptimalFrontParameter.Value == null || OptimalFrontParameter.Value.Rows < 1 || OptimalFrontParameter.Value.Columns != qualities[0].Length) {
    90         return; // too pareto front nonexistant or with wrong number of dimensions
     81        return base.Apply(); // too pareto front nonexistant or with wrong number of dimensions
    9182      }
    9283
    93       IEnumerable<double[]> front = NonDominatedSelect.selectNonDominatedVectors(qualities, TestFunctionParameter.ActualValue.Maximization(objectives), true);
     84      IEnumerable<double[]> front = NonDominatedSelect.selectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true);
    9485
    9586      if (!results.ContainsKey(resultsHV)) results.Add(new Result(resultsHV, typeof(DoubleValue)));
     
    10192      }
    10293
    103       bool[] maximization = TestFunctionParameter.ActualValue.Maximization(objectives);
     94      bool[] maximization = testFunction.Maximization(objectives);
    10495      double[] invPoint = GetBestPoint(OptimalFrontParameter.Value, maximization);
    10596      double[] refPoint = GetWorstPoint(OptimalFrontParameter.Value, maximization);
     
    10798      double hv = front.Any() ? Hypervolume.Calculate(front, refPoint, maximization) / normalization : 0;
    10899
    109       if (Double.IsNaN(best)) best = hv; else best = Math.Max(best, hv);
    110       double diff;
    111       diff = best - hv;
    112       if (diff == 0) {
    113         BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities));
     100      if (double.IsNaN(best) || best < hv) {
     101        best = hv;
     102        BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities.Select(q => q.ToArray()).ToArray()));
    114103      }
    115104
    116105      results[resultsHV].Value = new DoubleValue(hv);
    117       results[resultsDist].Value = new DoubleValue(diff);
    118106      results[bestknownHV].Value = new DoubleValue(best);
     107      results[resultsDist].Value = new DoubleValue(best - hv);
    119108
     109      return base.Apply();
    120110    }
    121111
    122     private double[] GetWorstPoint(DoubleMatrix value, bool[] maximization) {
     112
     113    private static double[] GetWorstPoint(DoubleMatrix value, bool[] maximization) {
    123114      bool[] invMax = new bool[maximization.Length];
    124115      int i = 0;
     
    129120    }
    130121
    131     private double[] GetBestPoint(DoubleMatrix value, bool[] maximization) {
     122    private static double[] GetBestPoint(DoubleMatrix value, bool[] maximization) {
    132123      double[] res = new double[maximization.Length];
    133124      for (int i = 0; i < maximization.Length; i++) {
Note: See TracChangeset for help on using the changeset viewer.