- Timestamp:
- 07/12/16 18:20:50 (8 years ago)
- Location:
- branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/CrowdingAnalyzer.cs
r13725 r14044 19 19 */ 20 20 #endregion 21 22 using System.Linq; 21 23 using HeuristicLab.Common; 22 24 using HeuristicLab.Core; … … 29 31 [Item("CrowdingAnalyzer", "The mean crowding distance for each point of the Front (see Multi-Objective Performance Metrics - Shodhganga for more information)")] 30 32 public class CrowdingAnalyzer : MOTFAnalyzer { 31 [StorableHook(HookType.AfterDeserialization)] 32 private void AfterDeserialization() { 33 } 33 34 34 [StorableConstructor] 35 35 protected CrowdingAnalyzer(bool deserializing) : base(deserializing) { } 36 public CrowdingAnalyzer(CrowdingAnalyzer original, Cloner cloner) : base(original, cloner) { 36 public CrowdingAnalyzer(CrowdingAnalyzer original, Cloner cloner) 37 : base(original, cloner) { 37 38 } 38 39 public override IDeepCloneable Clone(Cloner cloner) { … … 40 41 } 41 42 42 43 44 43 public CrowdingAnalyzer() { } 45 44 46 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 45 public override IOperation Apply() { 46 var results = ResultsParameter.ActualValue; 47 var qualities = QualitiesParameter.ActualValue; 48 var testFunction = TestFunctionParameter.ActualValue; 47 49 int objectives = qualities[0].Length; 48 if (!results.ContainsKey("Crowding")) results.Add(new Result("Crowding", typeof(DoubleValue))); 49 results["Crowding"].Value = new DoubleValue(Crowding.Calculate(qualities, TestFunctionParameter.ActualValue.Bounds(objectives))); 50 51 if (!results.ContainsKey("Crowding")) results.Add(new Result("Crowding", new DoubleValue())); 52 var resultValue = (DoubleValue)results["Crowding"].Value; 53 54 var crowdingDistance = Crowding.Calculate(qualities.Select(x => x.ToArray()), testFunction.Bounds(objectives)); 55 resultValue.Value = crowdingDistance; 56 57 return base.Apply(); 50 58 } 59 51 60 } 52 61 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/GenerationalDistanceAnalyzer.cs
r14030 r14044 19 19 */ 20 20 #endregion 21 22 using System.Linq; 21 23 using HeuristicLab.Common; 22 24 using HeuristicLab.Core; … … 30 32 [Item("GenerationalDistanceAnalyzer", "The generational distance between the current and the best known front (see Multi-Objective Performance Metrics - Shodhganga for more information)")] 31 33 public class GenerationalDistanceAnalyzer : MOTFAnalyzer { 32 [StorableHook(HookType.AfterDeserialization)] 33 private void AfterDeserialization() { 34 35 private IFixedValueParameter<DoubleValue> DampeningParameter { 36 get { return (IFixedValueParameter<DoubleValue>)Parameters["Dampening"]; } 37 set { Parameters["Dampening"].ActualValue = value; } 34 38 } 39 40 public double Dampening { 41 get { return DampeningParameter.Value.Value; } 42 set { DampeningParameter.Value.Value = value; } 43 } 44 35 45 [StorableConstructor] 36 46 protected GenerationalDistanceAnalyzer(bool deserializing) : base(deserializing) { } 37 public GenerationalDistanceAnalyzer(GenerationalDistanceAnalyzer original, Cloner cloner) : base(original, cloner) { 38 } 47 protected GenerationalDistanceAnalyzer(GenerationalDistanceAnalyzer original, Cloner cloner) : base(original, cloner) { } 39 48 public override IDeepCloneable Clone(Cloner cloner) { 40 49 return new GenerationalDistanceAnalyzer(this, cloner); 41 50 } 42 51 43 /// <summary> 44 /// </summary> 45 private IValueParameter<DoubleValue> DampeningParameter { 46 get { 47 return (IValueParameter<DoubleValue>)Parameters["Dampening"]; 48 } 49 set { 50 Parameters["Dampening"].ActualValue = value; 51 } 52 public GenerationalDistanceAnalyzer() { 53 Parameters.Add(new FixedValueParameter<DoubleValue>("Dampening", "", new DoubleValue(1))); 52 54 } 53 55 54 public GenerationalDistanceAnalyzer() { 55 Parameters.Add(new ValueParameter<DoubleValue>("Dampening", "", new DoubleValue(1))); 56 } 56 public override IOperation Apply() { 57 var results = ResultsParameter.ActualValue; 58 var qualities = QualitiesParameter.ActualValue; 59 int objectives = qualities[0].Length; 57 60 58 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) {59 int objectives = qualities[0].Length;60 61 var optimalfront = TestFunctionParameter.ActualValue.OptimalParetoFront(objectives); 61 if (optimalfront == null) return; 62 if (!results.ContainsKey("GenerationalDistance")) results.Add(new Result("GenerationalDistance", typeof(DoubleValue))); 63 results["GenerationalDistance"].Value = new DoubleValue(GenerationalDistance.Calculate(qualities, optimalfront, DampeningParameter.Value.Value)); 62 if (optimalfront == null) return base.Apply(); 63 64 if (!results.ContainsKey("GenerationalDistance")) results.Add(new Result("GenerationalDistance", new DoubleValue())); 65 var resultValue = (DoubleValue)results["GenerationalDistance"].Value; 66 67 var distance = GenerationalDistance.Calculate(qualities.Select(x => x.ToArray()), optimalfront, Dampening); 68 resultValue.Value = distance; 69 70 return base.Apply(); 64 71 } 65 72 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs
r14030 r14044 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; … … 32 31 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { 33 32 [StorableClass] 34 [Item(" GenerationalDistanceAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")]33 [Item("HypervolumeAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")] 35 34 public class HypervolumeAnalyzer : MOTFAnalyzer { 35 36 public IValueParameter<DoubleArray> ReferencePointParameter { 37 get { return (IValueParameter<DoubleArray>)Parameters["ReferencePoint"]; } 38 } 39 40 public IFixedValueParameter<DoubleValue> BestKnownHyperVolumeParameter { 41 get { return (IFixedValueParameter<DoubleValue>)Parameters["BestKnownHyperVolume"]; } 42 } 43 44 public double BestKnownHyperVolume { 45 get { return BestKnownHyperVolumeParameter.Value.Value; } 46 set { BestKnownHyperVolumeParameter.Value.Value = value; } 47 } 48 49 [StorableConstructor] 50 protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) { } 36 51 [StorableHook(HookType.AfterDeserialization)] 37 52 private void AfterDeserialization() { 53 RegisterEventHandlers(); 38 54 } 39 [StorableConstructor] 40 protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) { } 41 public HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) { } 55 56 protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) 57 : base(original, cloner) { 58 RegisterEventHandlers(); 59 } 42 60 public override IDeepCloneable Clone(Cloner cloner) { 43 61 return new HypervolumeAnalyzer(this, cloner); 44 62 } 45 63 46 public IValueParameter<DoubleArray> ReferencePointParameter {47 get {48 return (IValueParameter<DoubleArray>)Parameters["ReferencePoint"];49 }50 }51 52 public IValueParameter<DoubleValue> BestKnownHyperVolumeParameter {53 get {54 return (IValueParameter<DoubleValue>)Parameters["BestKnownHyperVolume"];55 }56 set {57 Parameters["BestKnownHyperVolume"].ActualValue = value;58 }59 }60 61 64 public HypervolumeAnalyzer() { 62 65 Parameters.Add(new ValueParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation")); 63 Parameters.Add(new ValueParameter<DoubleValue>("BestKnownHyperVolume", "The currently best known hypervolume")); 66 Parameters.Add(new FixedValueParameter<DoubleValue>("BestKnownHyperVolume", "The currently best known hypervolume", new DoubleValue(0))); 67 68 RegisterEventHandlers(); 64 69 } 65 70 66 71 private void RegisterEventHandlers() { 67 ReferencePointParameter.ValueChanged += ReferencePointParameterOnValueChanged;72 ReferencePointParameter.ValueChanged += (o, e) => BestKnownHyperVolume = 0; 68 73 } 69 74 70 private void ReferencePointParameterOnValueChanged(object sender, EventArgs e) { 71 BestKnownHyperVolumeParameter.Value = new DoubleValue(0); 72 } 73 74 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 75 if (qualities == null || qualities.Length < 1) return; 75 public override IOperation Apply() { 76 var results = ResultsParameter.ActualValue; 77 var qualities = QualitiesParameter.ActualValue; 78 var testFunction = TestFunctionParameter.ActualValue; 76 79 int objectives = qualities[0].Length; 77 80 78 81 if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", typeof(DoubleValue))); 79 82 if (!results.ContainsKey("Absolute Distance to BestKnownHypervolume")) results.Add(new Result("Absolute Distance to BestKnownHypervolume", typeof(DoubleValue))); 80 IEnumerable<double[]> front = NonDominatedSelect.selectNonDominatedVectors(qualities, TestFunctionParameter.ActualValue.Maximization(objectives), true); 81 double hv = front.Any() ? Hypervolume.Calculate(front, TestFunctionParameter.ActualValue.ReferencePoint(objectives), TestFunctionParameter.ActualValue.Maximization(objectives)) : 0; 83 82 84 double best; 83 85 if (!results.ContainsKey("BestKnownHypervolume")) { … … 87 89 best = ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value; 88 90 } 89 if (Double.IsNaN(best)) best = hv; else best = Math.Max(best, hv);90 91 91 double diff = best - hv; 92 if (diff == 0) { 93 BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities)); 92 93 IEnumerable<double[]> front = NonDominatedSelect.selectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true); 94 95 double hv = front.Any() ? Hypervolume.Calculate(front, testFunction.ReferencePoint(objectives), testFunction.Maximization(objectives)) : 0; 96 97 98 if (double.IsNaN(best) || best < hv) { 99 best = hv; 100 BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities.Select(q => q.ToArray()).ToArray())); 94 101 } 95 102 96 103 results["Hypervolume"].Value = new DoubleValue(hv); 97 results["Absolute Distance to BestKnownHypervolume"].Value = new DoubleValue(diff);98 104 results["BestKnownHypervolume"].Value = new DoubleValue(best); 105 results["Absolute Distance to BestKnownHypervolume"].Value = new DoubleValue(best - hv); 99 106 107 return base.Apply(); 100 108 } 109 101 110 } 102 111 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/InvertedGenerationalDistanceAnalyzer.cs
r14030 r14044 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 31 32 [Item("InvertedGenerationalDistanceAnalyzer", "The inverted generational distance between the current and the best known front (see Multi-Objective Performance Metrics - Shodhganga for more information)")] 32 33 public class InvertedGenerationalDistanceAnalyzer : MOTFAnalyzer { 33 [StorableHook(HookType.AfterDeserialization)] 34 private void AfterDeserialization() { 34 35 36 private IFixedValueParameter<DoubleValue> DampeningParameter { 37 get { return (IFixedValueParameter<DoubleValue>)Parameters["Dampening"]; } 35 38 } 39 40 public double Dampening { 41 get { return DampeningParameter.Value.Value; } 42 set { DampeningParameter.Value.Value = value; } 43 } 44 45 public InvertedGenerationalDistanceAnalyzer() { 46 Parameters.Add(new FixedValueParameter<DoubleValue>("Dampening", "", new DoubleValue(1))); 47 } 48 36 49 [StorableConstructor] 37 50 protected InvertedGenerationalDistanceAnalyzer(bool deserializing) : base(deserializing) { } 38 public InvertedGenerationalDistanceAnalyzer(InvertedGenerationalDistanceAnalyzer original, Cloner cloner) : base(original, cloner) { 39 } 40 51 protected InvertedGenerationalDistanceAnalyzer(InvertedGenerationalDistanceAnalyzer original, Cloner cloner) : base(original, cloner) { } 41 52 public override IDeepCloneable Clone(Cloner cloner) { 42 53 return new InvertedGenerationalDistanceAnalyzer(this, cloner); 43 54 } 44 55 45 /// <summary> 46 /// </summary> 47 private IValueParameter<DoubleValue> DampeningParameter { 48 get { 49 return (IValueParameter<DoubleValue>)Parameters["Dampening"]; 50 } 51 set { 52 Parameters["Dampening"].ActualValue = value; 53 } 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 62 var optimalfront = TestFunctionParameter.ActualValue.OptimalParetoFront(objectives); 63 if (optimalfront == null) return base.Apply(); 64 65 if (!results.ContainsKey("InvertedGenerationalDistance")) results.Add(new Result("InvertedGenerationalDistance", new DoubleValue(double.NaN))); 66 var resultValue = (DoubleValue)results["InvertedGenerationalDistance"].Value; 67 68 var invertedGenerationalDistance = InvertedGenerationalDistance.Calculate(qualities.Select(q => q.ToArray()), optimalfront, DampeningParameter.Value.Value); 69 resultValue.Value = invertedGenerationalDistance; 70 71 return base.Apply(); 54 72 } 55 73 56 public InvertedGenerationalDistanceAnalyzer() {57 Parameters.Add(new ValueParameter<DoubleValue>("Dampening", "", new DoubleValue(1)));58 }59 74 60 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) {61 int objectives = qualities[0].Length;62 var optimalfront = TestFunctionParameter.ActualValue.OptimalParetoFront(objectives);63 if (optimalfront == null) return;64 if (!results.ContainsKey("InvertedGenerationalDistance")) results.Add(new Result("InvertedGenerationalDistance", typeof(DoubleValue)));65 results["InvertedGenerationalDistance"].Value = new DoubleValue(InvertedGenerationalDistance.Calculate(qualities, optimalfront, DampeningParameter.Value.Value));66 }67 75 } 68 76 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/MOTFAnalyzer.cs
r14030 r14044 20 20 #endregion 21 21 22 using System.Collections.Generic;23 using System.Linq;24 22 using HeuristicLab.Common; 25 23 using HeuristicLab.Core; … … 35 33 [StorableClass] 36 34 public abstract class MOTFAnalyzer : SingleSuccessorOperator, IMultiObjectiveTestFunctionAnalyzer { 37 38 public ILookupParameter<IEncoding> EncodingParameter { 39 get { return (ILookupParameter<IEncoding>)Parameters["Encoding"]; } 40 } 35 public bool EnabledByDefault { get { return true; } } 41 36 42 37 public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter { … … 49 44 50 45 public ILookupParameter<IMultiObjectiveTestFunction> TestFunctionParameter { 51 get { 52 return (ILookupParameter<IMultiObjectiveTestFunction>)Parameters["TestFunction"]; 53 } 46 get { return (ILookupParameter<IMultiObjectiveTestFunction>)Parameters["TestFunction"]; } 54 47 } 55 48 56 49 public ILookupParameter<DoubleMatrix> BestKnownFrontParameter { 57 get { 58 return (ILookupParameter<DoubleMatrix>)Parameters["BestKnownFront"]; 59 } 50 get { return (ILookupParameter<DoubleMatrix>)Parameters["BestKnownFront"]; } 60 51 } 61 52 62 protected MOTFAnalyzer(MOTFAnalyzer original, Cloner cloner) : base(original, cloner) { 63 } 53 protected MOTFAnalyzer(MOTFAnalyzer original, Cloner cloner) : base(original, cloner) { } 54 64 55 [StorableConstructor] 65 56 protected MOTFAnalyzer(bool deserializing) : base(deserializing) { } 66 public MOTFAnalyzer() { 67 Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding.")); 57 protected MOTFAnalyzer() { 68 58 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector.")); 69 59 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to.")); … … 71 61 Parameters.Add(new LookupParameter<DoubleMatrix>("BestKnownFront", "The currently best known Pareto front")); 72 62 } 73 [StorableHook(HookType.AfterDeserialization)]74 private void AfterDeserialization() {75 }76 77 public bool EnabledByDefault {78 get { return true; }79 }80 81 public override IOperation Apply() {82 var encoding = EncodingParameter.ActualValue;83 var results = ResultsParameter.ActualValue;84 85 IEnumerable<IScope> scopes = new[] { ExecutionContext.Scope };86 for (var i = 0; i < QualitiesParameter.Depth; i++)87 scopes = scopes.Select(x => (IEnumerable<IScope>)x.SubScopes).Aggregate((a, b) => a.Concat(b));88 89 var individuals = scopes.Select(encoding.GetIndividual).ToArray();90 if (individuals.Length > 0) {91 Analyze(individuals, QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(), results);92 }93 return base.Apply();94 }95 96 public abstract void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results);97 63 } 98 64 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/NormalizedHypervolumeAnalyzer.cs
r14030 r14044 32 32 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { 33 33 [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")] 35 35 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 Names48 36 private const string bestKnownFront = "BestKnownFront Zitzler"; 49 37 private const string resultsHV = "NormalizedHypervolume"; … … 51 39 52 40 private const string bestknownHV = "NormalizedBestKnownHyperVolume"; 53 #endregion54 41 55 #region parameters56 42 public IValueParameter<DoubleMatrix> OptimalFrontParameter { 57 get { 58 return (IValueParameter<DoubleMatrix>)Parameters[bestKnownFront]; 59 } 43 get { return (IValueParameter<DoubleMatrix>)Parameters[bestKnownFront]; } 60 44 } 61 45 62 46 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]; } 69 48 } 70 #endregion71 49 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")); 75 55 } 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 76 64 77 65 private void RegisterEventHandlers() { … … 83 71 } 84 72 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; 87 77 int objectives = qualities[0].Length; 78 88 79 double best = BestKnownHyperVolumeParameter.Value.Value; 89 80 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 dimensions81 return base.Apply(); // too pareto front nonexistant or with wrong number of dimensions 91 82 } 92 83 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); 94 85 95 86 if (!results.ContainsKey(resultsHV)) results.Add(new Result(resultsHV, typeof(DoubleValue))); … … 101 92 } 102 93 103 bool[] maximization = TestFunctionParameter.ActualValue.Maximization(objectives);94 bool[] maximization = testFunction.Maximization(objectives); 104 95 double[] invPoint = GetBestPoint(OptimalFrontParameter.Value, maximization); 105 96 double[] refPoint = GetWorstPoint(OptimalFrontParameter.Value, maximization); … … 107 98 double hv = front.Any() ? Hypervolume.Calculate(front, refPoint, maximization) / normalization : 0; 108 99 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())); 114 103 } 115 104 116 105 results[resultsHV].Value = new DoubleValue(hv); 117 results[resultsDist].Value = new DoubleValue(diff);118 106 results[bestknownHV].Value = new DoubleValue(best); 107 results[resultsDist].Value = new DoubleValue(best - hv); 119 108 109 return base.Apply(); 120 110 } 121 111 122 private double[] GetWorstPoint(DoubleMatrix value, bool[] maximization) { 112 113 private static double[] GetWorstPoint(DoubleMatrix value, bool[] maximization) { 123 114 bool[] invMax = new bool[maximization.Length]; 124 115 int i = 0; … … 129 120 } 130 121 131 private double[] GetBestPoint(DoubleMatrix value, bool[] maximization) {122 private static double[] GetBestPoint(DoubleMatrix value, bool[] maximization) { 132 123 double[] res = new double[maximization.Length]; 133 124 for (int i = 0; i < maximization.Length; i++) { -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/ScatterPlotAnalyzer.cs
r14030 r14044 19 19 */ 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; … … 24 25 using HeuristicLab.Encodings.RealVectorEncoding; 25 26 using HeuristicLab.Optimization; 27 using HeuristicLab.Parameters; 26 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 … … 31 33 public class ScatterPlotAnalyzer : MOTFAnalyzer { 32 34 33 [StorableHook(HookType.AfterDeserialization)]34 private void AfterDeserialization() {35 public IScopeTreeLookupParameter<RealVector> IndividualsParameter { 36 get { return (IScopeTreeLookupParameter<RealVector>)Parameters["Individuals"]; } 35 37 } 38 36 39 [StorableConstructor] 37 40 protected ScatterPlotAnalyzer(bool deserializing) : base(deserializing) { } 38 public ScatterPlotAnalyzer(ScatterPlotAnalyzer original, Cloner cloner) : base(original, cloner) { 39 } 41 protected ScatterPlotAnalyzer(ScatterPlotAnalyzer original, Cloner cloner) : base(original, cloner) { } 40 42 public override IDeepCloneable Clone(Cloner cloner) { 41 43 return new ScatterPlotAnalyzer(this, cloner); 42 44 } 43 45 44 public ScatterPlotAnalyzer() { } 46 public ScatterPlotAnalyzer() { 47 Parameters.Add(new ScopeTreeLookupParameter<RealVector>("Individuals", "The individual solutions to the problem")); 48 } 45 49 46 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 47 if (qualities == null || qualities.Length < 1) return; 50 public override IOperation Apply() { 51 var results = ResultsParameter.ActualValue; 52 var qualities = QualitiesParameter.ActualValue; 53 var testFunction = TestFunctionParameter.ActualValue; 48 54 int objectives = qualities[0].Length; 49 double[][] opf = new double[0][]; 50 var optmialFront = TestFunctionParameter.ActualValue.OptimalParetoFront(objectives); 51 52 if (optmialFront != null) opf = optmialFront.Select(s => s.ToArray()).ToArray(); 53 var qualityClones = qualities.Select(s => s.ToArray()).ToArray(); 54 var solutionClones = individuals.Select(s => s.RealVector().ToArray()).ToArray(); 55 var individuals = IndividualsParameter.ActualValue; 55 56 56 57 if (!results.ContainsKey("Scatterplot")) { … … 58 59 } 59 60 60 results["Scatterplot"].Value = new MOSolution(qualityClones, solutionClones, opf, objectives); 61 double[][] optimalFront = new double[0][]; 62 var front = testFunction.OptimalParetoFront(objectives); 63 if (front != null) optimalFront = front.ToArray(); 64 65 var qualityClones = qualities.Select(s => s.ToArray()).ToArray(); 66 var solutionClones = individuals.Select(s => s.ToArray()).ToArray(); 67 68 results["Scatterplot"].Value = new MOSolution(qualityClones, solutionClones, optimalFront, objectives); 69 70 return base.Apply(); 61 71 } 62 72 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/SpacingAnalyzer.cs
r13725 r14044 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 30 31 [Item("SpacingAnalyzer", "The spacing of the current front (see Multi-Objective Performance Metrics - Shodhganga for more information)")] 31 32 public class SpacingAnalyzer : MOTFAnalyzer { 32 33 [StorableHook(HookType.AfterDeserialization)]34 private void AfterDeserialization() {35 }36 37 33 [StorableConstructor] 38 34 protected SpacingAnalyzer(bool deserializing) : base(deserializing) { } 39 35 40 public SpacingAnalyzer() { 41 } 42 43 public SpacingAnalyzer(SpacingAnalyzer original, Cloner cloner) : base(original, cloner) { 44 } 45 36 protected SpacingAnalyzer(SpacingAnalyzer original, Cloner cloner) : base(original, cloner) { } 46 37 public override IDeepCloneable Clone(Cloner cloner) { 47 38 return new SpacingAnalyzer(this, cloner); 48 39 } 49 40 50 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 51 if (!results.ContainsKey("Spacing")) results.Add(new Result("Spacing", typeof(DoubleValue))); 52 results["Spacing"].Value = new DoubleValue(Spacing.Calculate(qualities)); 41 public SpacingAnalyzer() { } 42 43 public override IOperation Apply() { 44 var results = ResultsParameter.ActualValue; 45 var qualities = QualitiesParameter.ActualValue; 46 47 if (!results.ContainsKey("Spacing")) results.Add(new Result("Spacing", new DoubleValue(0))); 48 var resultValue = (DoubleValue)results["Spacing"].Value; 49 50 var spacing = Spacing.Calculate(qualities.Select(q => q.ToArray())); 51 resultValue.Value = spacing; 52 53 return base.Apply(); 53 54 } 54 55 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Interfaces/IMultiObjectiveTestFunctionAnalyzer.cs
r13725 r14044 26 26 27 27 public interface IMultiObjectiveTestFunctionAnalyzer : IAnalyzer, IMultiObjectiveOperator { 28 ILookupParameter<IEncoding> EncodingParameter { get; }29 30 28 IScopeTreeLookupParameter<DoubleArray> QualitiesParameter { get; } 31 32 29 ILookupParameter<ResultCollection> ResultsParameter { get; } 33 34 30 ILookupParameter<IMultiObjectiveTestFunction> TestFunctionParameter { get; } 35 36 31 ILookupParameter<DoubleMatrix> BestKnownFrontParameter { get; } 37 38 32 } 39 33 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/MultiObjectiveTestFunctionProblem.cs
r14030 r14044 286 286 287 287 288 if (analyzer is HypervolumeAnalyzer) { 289 ((HypervolumeAnalyzer)analyzer).ReferencePointParameter.Value = new DoubleArray(TestFunction.ReferencePoint(Objectives)); 290 ((HypervolumeAnalyzer)analyzer).BestKnownHyperVolumeParameter.Value = new DoubleValue(TestFunction.BestKnownHypervolume(Objectives)); 288 var hyperVolumeAnalyzer = analyzer as HypervolumeAnalyzer; 289 if (hyperVolumeAnalyzer != null) { 290 hyperVolumeAnalyzer.ReferencePointParameter.Value = new DoubleArray(TestFunction.ReferencePoint(Objectives)); 291 hyperVolumeAnalyzer.BestKnownHyperVolume = TestFunction.BestKnownHypervolume(Objectives); 291 292 } 292 293 293 if (analyzer is NormalizedHypervolumeAnalyzer) { 294 ((NormalizedHypervolumeAnalyzer)analyzer).OptimalFrontParameter.ActualValue = (DoubleMatrix)BestKnownFrontParameter.ActualValue; 294 var normalizedHyperVolumeAnalyzer = analyzer as NormalizedHypervolumeAnalyzer; 295 if (normalizedHyperVolumeAnalyzer != null) { 296 normalizedHyperVolumeAnalyzer.OptimalFrontParameter.ActualValue = (DoubleMatrix)BestKnownFrontParameter.ActualValue; 297 } 298 299 var scatterPlotAnalyzer = analyzer as ScatterPlotAnalyzer; 300 if (scatterPlotAnalyzer != null) { 301 scatterPlotAnalyzer.IndividualsParameter.ActualName = Encoding.Name; 295 302 } 296 303
Note: See TracChangeset
for help on using the changeset viewer.