- Timestamp:
- 07/15/16 14:14:50 (8 years ago)
- Location:
- branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/CrowdingAnalyzer.cs
r14044 r14085 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Optimization; 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 29 … … 31 32 [Item("CrowdingAnalyzer", "The mean crowding distance for each point of the Front (see Multi-Objective Performance Metrics - Shodhganga for more information)")] 32 33 public class CrowdingAnalyzer : MOTFAnalyzer { 34 35 public ILookupParameter<DoubleMatrix> BoundsParameter { 36 get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 37 } 33 38 34 39 [StorableConstructor] … … 41 46 } 42 47 43 public CrowdingAnalyzer() { } 48 public CrowdingAnalyzer() { 49 Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", 50 "The bounds of the solution given as either one line for all variables or a line for each variable. The first column specifies lower bound, the second upper bound.")); 51 } 44 52 45 53 public override IOperation Apply() { 46 54 var results = ResultsParameter.ActualValue; 47 55 var qualities = QualitiesParameter.ActualValue; 48 var testFunction = TestFunctionParameter.ActualValue; 49 int objectives = qualities[0].Length; 56 var bounds = BoundsParameter.ActualValue; 50 57 51 58 if (!results.ContainsKey("Crowding")) results.Add(new Result("Crowding", new DoubleValue())); 52 59 var resultValue = (DoubleValue)results["Crowding"].Value; 53 60 54 var crowdingDistance = Crowding.Calculate(qualities.Select(x => x.ToArray()), testFunction.Bounds(objectives));61 var crowdingDistance = Crowding.Calculate(qualities.Select(x => x.ToArray()), bounds.CloneAsMatrix()); 55 62 resultValue.Value = crowdingDistance; 56 63 -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/GenerationalDistanceAnalyzer.cs
r14044 r14085 65 65 var resultValue = (DoubleValue)results["GenerationalDistance"].Value; 66 66 67 var distance = GenerationalDistance.Calculate(qualities.Select(x => x. ToArray()), optimalfront, Dampening);67 var distance = GenerationalDistance.Calculate(qualities.Select(x => x.CloneAsArray()), optimalfront, Dampening); 68 68 resultValue.Value = distance; 69 69 -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs
r14081 r14085 34 34 public class HypervolumeAnalyzer : MOTFAnalyzer { 35 35 36 public I ValueParameter<DoubleArray> ReferencePointParameter {37 get { return (I ValueParameter<DoubleArray>)Parameters["ReferencePoint"]; }36 public ILookupParameter<DoubleArray> ReferencePointParameter { 37 get { return (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"]; } 38 38 } 39 39 … … 49 49 [StorableConstructor] 50 50 protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) { } 51 [StorableHook(HookType.AfterDeserialization)]52 private void AfterDeserialization() {53 RegisterEventHandlers();54 }55 51 56 52 protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) 57 53 : base(original, cloner) { 58 RegisterEventHandlers();59 54 } 60 55 public override IDeepCloneable Clone(Cloner cloner) { … … 63 58 64 59 public HypervolumeAnalyzer() { 65 Parameters.Add(new ValueParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));60 Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation")); 66 61 Parameters.Add(new FixedValueParameter<DoubleValue>("BestKnownHyperVolume", "The currently best known hypervolume", new DoubleValue(0))); 67 68 RegisterEventHandlers();69 }70 71 private void RegisterEventHandlers() {72 ReferencePointParameter.ValueChanged += (o, e) => BestKnownHyperVolume = 0;73 62 } 74 63 … … 77 66 var qualities = QualitiesParameter.ActualValue; 78 67 var testFunction = TestFunctionParameter.ActualValue; 68 var referencePoint = ReferencePointParameter.ActualValue; 79 69 int objectives = qualities[0].Length; 70 71 80 72 81 73 if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", typeof(DoubleValue))); … … 93 85 IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true); 94 86 95 double hv = front.Any() ? Hypervolume.Calculate(front, testFunction.ReferencePoint(objectives), testFunction.Maximization(objectives)) : 0;87 double hv = front.Any() ? Hypervolume.Calculate(front, referencePoint.CloneAsArray(), testFunction.Maximization(objectives)) : 0; 96 88 97 89 -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/InvertedGenerationalDistanceAnalyzer.cs
r14044 r14085 60 60 int objectives = qualities[0].Length; 61 61 62 var optimalfront = TestFunctionParameter.ActualValue.OptimalParetoFront(objectives);62 var optimalfront = testFunction.OptimalParetoFront(objectives); 63 63 if (optimalfront == null) return base.Apply(); 64 64 -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Interfaces/IMultiObjectiveTestFunction.cs
r14065 r14085 31 31 bool[] Maximization(int objectives); 32 32 double[,] Bounds(int objectives); 33 33 34 IEnumerable<double[]> OptimalParetoFront(int objectives); 35 double OptimalHypervolume(int objectives); 34 36 double[] ReferencePoint(int objectives); 35 double BestKnownHypervolume(int objectives);36 37 37 38 int MinimumSolutionLength { get; } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/MultiObjectiveTestFunctionProblem.cs
r14073 r14085 65 65 public override bool[] Maximization { 66 66 get { 67 //necessary because of virtual member call in base ctor to this property 68 if (!Parameters.ContainsKey("TestFunction")) return new bool[2]; 69 return TestFunction.Maximization(Objectives); 67 if (!Parameters.ContainsKey("Maximization")) return new bool[2]; 68 return MaximizationParameter.Value.ToArray(); 70 69 } 71 70 } … … 87 86 set { TestFunctionParameter.Value = value; } 88 87 } 89 public IEnumerable<double[]> BestKnownFront { 90 get { return Parameters.ContainsKey("BestKnownFront") ? TestFunction.OptimalParetoFront(Objectives) : null; } 88 public DoubleArray ReferencePoint { 89 get { return ReferencePointParameter.Value; } 90 set { ReferencePointParameter.Value = value; } 91 } 92 public DoubleMatrix BestKnownFront { 93 get { return BestKnownFrontParameter.Value; } 94 set { BestKnownFrontParameter.Value = value; } 91 95 } 92 96 #endregion … … 112 116 Parameters.Add(new FixedValueParameter<IntValue>("Objectives", "The dimensionality of the solution vector (number of objectives).", new IntValue(2))); 113 117 Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The bounds of the solution given as either one line for all variables or a line for each variable. The first column specifies lower bound, the second upper bound.", new DoubleMatrix(new double[,] { { -4, 4 } }))); 118 Parameters.Add(new ValueParameter<DoubleArray>("ReferencePoint", "The reference point used for hypervolume calculation.")); 114 119 Parameters.Add(new ValueParameter<IMultiObjectiveTestFunction>("TestFunction", "The function that is to be optimized.", new Fonseca())); 115 120 Parameters.Add(new ValueParameter<DoubleMatrix>("BestKnownFront", "The currently best known Pareto front")); … … 165 170 #region Events 166 171 private void UpdateParameterValues() { 167 MaximizationParameter.ActualValue = (BoolArray)new BoolArray(Maximization).AsReadOnly(); 168 var front = BestKnownFront; 169 if (front != null) { BestKnownFrontParameter.Value = (DoubleMatrix)new DoubleMatrix(To2D(front.ToArray())).AsReadOnly(); } 170 172 MaximizationParameter.Value = (BoolArray)new BoolArray(TestFunction.Maximization(Objectives)).AsReadOnly(); 173 174 var front = TestFunction.OptimalParetoFront(Objectives); 175 if (front != null) { 176 BestKnownFrontParameter.Value = (DoubleMatrix)new DoubleMatrix(To2D(front.ToArray())).AsReadOnly(); 177 } else BestKnownFrontParameter.Value = null; 178 179 180 BoundsParameter.Value = new DoubleMatrix(TestFunction.Bounds(Objectives)); 181 ReferencePointParameter.Value = new DoubleArray(TestFunction.ReferencePoint(Objectives)); 171 182 } 172 183 … … 186 197 Objectives = Math.Max(TestFunction.MinimumObjectives, Math.Min(Objectives, TestFunction.MaximumObjectives)); 187 198 188 Bounds = (DoubleMatrix)new DoubleMatrix(TestFunction.Bounds(Objectives)).Clone();189 199 ParameterizeAnalyzers(); 190 200 UpdateParameterValues(); … … 228 238 analyzer.BestKnownFrontParameter.ActualName = BestKnownFrontParameter.Name; 229 239 240 var crowdingAnalyzer = analyzer as CrowdingAnalyzer; 241 if (crowdingAnalyzer != null) { 242 crowdingAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name; 243 } 244 230 245 var hyperVolumeAnalyzer = analyzer as HypervolumeAnalyzer; 231 246 if (hyperVolumeAnalyzer != null) { 232 hyperVolumeAnalyzer.ReferencePointParameter. Value = new DoubleArray(TestFunction.ReferencePoint(Objectives));233 hyperVolumeAnalyzer.BestKnownHyperVolume = TestFunction. BestKnownHypervolume(Objectives);247 hyperVolumeAnalyzer.ReferencePointParameter.ActualName = ReferencePointParameter.Name; 248 hyperVolumeAnalyzer.BestKnownHyperVolume = TestFunction.OptimalHypervolume(Objectives); 234 249 } 235 250 -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/NonDominatedSelect.cs
r14081 r14085 24 24 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { 25 25 26 public class NonDominatedSelect {26 public static class NonDominatedSelect { 27 27 public enum DominationResult { Dominates, IsDominated, IsNonDominated }; 28 28 -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/MultiObjectiveTestFunction.cs
r14068 r14085 105 105 /// returns the best known Hypervolume for this test function (default=-1) 106 106 /// </summary> 107 public virtual double BestKnownHypervolume(int objectives) {107 public virtual double OptimalHypervolume(int objectives) { 108 108 CheckObjectives(objectives); 109 109 return GetBestKnownHypervolume(objectives);
Note: See TracChangeset
for help on using the changeset viewer.