Changeset 13725 for branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs
- Timestamp:
- 03/24/16 12:30:32 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs
r13672 r13725 23 23 using System.Collections.Generic; 24 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Optimization; 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 30 28 31 namespace 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() { 31 37 } 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) { } 34 41 public override IDeepCloneable Clone(Cloner cloner) { 35 42 return new HypervolumeAnalyzer(this, cloner); 36 43 } 37 44 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) { 39 74 if (qualities == null || qualities.Length < 2) return; 40 75 int objectives = qualities[0].Length; 41 double best = TestFunction.BestKnownHypervolume(objectives);76 double best = BestKnownHyperVolumeParameter.Value.Value; 42 77 43 78 double diff; 44 79 45 80 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); 47 82 if (!results.ContainsKey("BestKnownHypervolume")) results.Add(new Result("BestKnownHypervolume", typeof(DoubleValue))); 48 83 else { … … 55 90 try { 56 91 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); 60 95 } 61 96 } 62 97 catch (ArgumentException) { 63 //TODO 98 64 99 } 65 100 … … 71 106 best = hv; 72 107 diff = 0; 108 BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities)); 73 109 } 74 110
Note: See TracChangeset
for help on using the changeset viewer.