Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs @ 14092

Last change on this file since 14092 was 14092, checked in by bwerth, 8 years ago

#1087 removed NormalizedHypervolumeAnalyzer and IMOFrontModel.cs, refactored ScatterPlotAnalyzer ,fixed bug in HypervolumeAnalyzer

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
33  [StorableClass]
34  [Item("HypervolumeAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")]
35  public class HypervolumeAnalyzer : MOTFAnalyzer {
36
37    public ILookupParameter<DoubleArray> ReferencePointParameter {
38      get { return (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"]; }
39    }
40
41    [StorableConstructor]
42    protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) {
43    }
44
45    protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner)
46      : base(original, cloner) {
47    }
48    public override IDeepCloneable Clone(Cloner cloner) {
49      return new HypervolumeAnalyzer(this, cloner);
50    }
51
52    public HypervolumeAnalyzer() {
53      Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
54    }
55
56    public override IOperation Apply() {
57      var results = ResultsParameter.ActualValue;
58      var qualities = QualitiesParameter.ActualValue;
59      var testFunction = TestFunctionParameter.ActualValue;
60      int objectives = qualities[0].Length;
61      var referencePoint = ReferencePointParameter.ActualValue;
62
63      if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", new DoubleValue(0)));
64      if (!results.ContainsKey("Absolute Distance to BestKnownHypervolume")) results.Add(new Result("Absolute Distance to BestKnownHypervolume", new DoubleValue(0)));
65
66      double best = testFunction.OptimalHypervolume(objectives);
67      if (!results.ContainsKey("BestKnownHypervolume")) {
68        results.Add(new Result("BestKnownHypervolume", new DoubleValue(0)));
69      } else {
70        best = Math.Max(best, ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value);
71      }
72
73
74      IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true);
75
76      double hv = Hypervolume.Calculate(front, referencePoint.ToArray(), testFunction.Maximization(objectives));
77
78      if (double.IsNaN(best) || best < hv) {
79        best = hv;
80        BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities.Select(q => q.ToArray()).ToArray()));
81      }
82
83      ((DoubleValue)(results["Hypervolume"].Value)).Value = hv;
84      ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value = best;
85      ((DoubleValue)(results["Absolute Distance to BestKnownHypervolume"].Value)).Value = best - hv;
86
87      return base.Apply();
88    }
89
90  }
91}
Note: See TracBrowser for help on using the repository browser.