Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/24/16 12:30:32 (8 years ago)
Author:
bwerth
Message:

#1087 minor bugfixes, added Parameters to Analyzers, convenience Tooltips for ScatterPlot

File:
1 edited

Legend:

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

    r13672 r13725  
    2323using System.Collections.Generic;
    2424using HeuristicLab.Common;
     25using HeuristicLab.Core;
    2526using HeuristicLab.Data;
    2627using HeuristicLab.Optimization;
     28using HeuristicLab.Parameters;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2730
    2831namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
    29   class HypervolumeAnalyzer : MOTFAnalyzer {
    30     public HypervolumeAnalyzer() {
     32  [StorableClass]
     33  [Item("GenerationalDistanceAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")]
     34  public class HypervolumeAnalyzer : MOTFAnalyzer {
     35    [StorableHook(HookType.AfterDeserialization)]
     36    private void AfterDeserialization() {
    3137    }
    32 
    33     protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) { }
     38    [StorableConstructor]
     39    protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) { }
     40    public HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) { }
    3441    public override IDeepCloneable Clone(Cloner cloner) {
    3542      return new HypervolumeAnalyzer(this, cloner);
    3643    }
    3744
    38     protected override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) {
     45    public IValueParameter<DoubleArray> ReferencePointParameter {
     46      get {
     47        return (IValueParameter<DoubleArray>)Parameters["ReferencePoint"];
     48      }
     49    }
     50
     51    public IValueParameter<DoubleValue> BestKnownHyperVolumeParameter {
     52      get {
     53        return (IValueParameter<DoubleValue>)Parameters["BestKnownHyperVolume"];
     54      }
     55      set {
     56        Parameters["BestKnownHyperVolume"].ActualValue = value;
     57      }
     58    }
     59
     60    public HypervolumeAnalyzer() {
     61      Parameters.Add(new ValueParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
     62      Parameters.Add(new ValueParameter<DoubleValue>("BestKnownHyperVolume", "The currently best known hypervolume"));
     63    }
     64
     65    private void RegisterEventHandlers() {
     66      ReferencePointParameter.ValueChanged += ReferencePointParameterOnValueChanged;
     67    }
     68
     69    private void ReferencePointParameterOnValueChanged(object sender, EventArgs e) {
     70      BestKnownHyperVolumeParameter.Value = new DoubleValue(0);
     71    }
     72
     73    public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) {
    3974      if (qualities == null || qualities.Length < 2) return;
    4075      int objectives = qualities[0].Length;
    41       double best = TestFunction.BestKnownHypervolume(objectives);
     76      double best = BestKnownHyperVolumeParameter.Value.Value;
    4277
    4378      double diff;
    4479
    4580      if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", typeof(DoubleValue)));
    46       IEnumerable<double[]> front = NonDominatedSelect.selectNonDominatedVectors(qualities, TestFunction.Maximization(objectives), true);
     81      IEnumerable<double[]> front = NonDominatedSelect.selectNonDominatedVectors(qualities, TestFunctionParameter.ActualValue.Maximization(objectives), true);
    4782      if (!results.ContainsKey("BestKnownHypervolume")) results.Add(new Result("BestKnownHypervolume", typeof(DoubleValue)));
    4883      else {
     
    5590      try {
    5691        if (objectives == 2) { //Hypervolume analysis only with 2 objectives for now
    57           hv = Hypervolume.Calculate(front, TestFunction.ReferencePoint(objectives), TestFunction.Maximization(objectives));
    58         } else if (Array.TrueForAll(TestFunction.Maximization(objectives), x => !x)) {
    59           hv = FastHV2.Calculate(front, TestFunction.ReferencePoint(objectives));
     92          hv = Hypervolume.Calculate(front, ReferencePointParameter.Value, TestFunctionParameter.ActualValue.Maximization(objectives));
     93        } else if (Array.TrueForAll(TestFunctionParameter.ActualValue.Maximization(objectives), x => !x)) {
     94          hv = MultiDimensionalHypervolume.Calculate(front, ReferencePointParameter.Value);
    6095        }
    6196      }
    6297      catch (ArgumentException) {
    63         //TODO
     98
    6499      }
    65100
     
    71106        best = hv;
    72107        diff = 0;
     108        BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities));
    73109      }
    74110
Note: See TracChangeset for help on using the changeset viewer.