Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14044


Ignore:
Timestamp:
07/12/16 18:20:50 (8 years ago)
Author:
mkommend
Message:

#1087: Refactored and improved analyzers for multi-objective test functions.

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  
    1919 */
    2020#endregion
     21
     22using System.Linq;
    2123using HeuristicLab.Common;
    2224using HeuristicLab.Core;
     
    2931  [Item("CrowdingAnalyzer", "The mean crowding distance for each point of the Front (see Multi-Objective Performance Metrics - Shodhganga for more information)")]
    3032  public class CrowdingAnalyzer : MOTFAnalyzer {
    31     [StorableHook(HookType.AfterDeserialization)]
    32     private void AfterDeserialization() {
    33     }
     33
    3434    [StorableConstructor]
    3535    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) {
    3738    }
    3839    public override IDeepCloneable Clone(Cloner cloner) {
     
    4041    }
    4142
    42 
    43 
    4443    public CrowdingAnalyzer() { }
    4544
    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;
    4749      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();
    5058    }
     59
    5160  }
    5261}
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/GenerationalDistanceAnalyzer.cs

    r14030 r14044  
    1919 */
    2020#endregion
     21
     22using System.Linq;
    2123using HeuristicLab.Common;
    2224using HeuristicLab.Core;
     
    3032  [Item("GenerationalDistanceAnalyzer", "The generational distance between the current and the best known front (see Multi-Objective Performance Metrics - Shodhganga for more information)")]
    3133  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; }
    3438    }
     39
     40    public double Dampening {
     41      get { return DampeningParameter.Value.Value; }
     42      set { DampeningParameter.Value.Value = value; }
     43    }
     44
    3545    [StorableConstructor]
    3646    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) { }
    3948    public override IDeepCloneable Clone(Cloner cloner) {
    4049      return new GenerationalDistanceAnalyzer(this, cloner);
    4150    }
    4251
    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)));
    5254    }
    5355
    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;
    5760
    58     public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) {
    59       int objectives = qualities[0].Length;
    6061      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();
    6471    }
    6572  }
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs

    r14030 r14044  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
     
    3231namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
    3332  [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")]
    3534  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) { }
    3651    [StorableHook(HookType.AfterDeserialization)]
    3752    private void AfterDeserialization() {
     53      RegisterEventHandlers();
    3854    }
    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    }
    4260    public override IDeepCloneable Clone(Cloner cloner) {
    4361      return new HypervolumeAnalyzer(this, cloner);
    4462    }
    4563
    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 
    6164    public HypervolumeAnalyzer() {
    6265      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();
    6469    }
    6570
    6671    private void RegisterEventHandlers() {
    67       ReferencePointParameter.ValueChanged += ReferencePointParameterOnValueChanged;
     72      ReferencePointParameter.ValueChanged += (o, e) => BestKnownHyperVolume = 0;
    6873    }
    6974
    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;
    7679      int objectives = qualities[0].Length;
    7780
    7881      if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", typeof(DoubleValue)));
    7982      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
    8284      double best;
    8385      if (!results.ContainsKey("BestKnownHypervolume")) {
     
    8789        best = ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value;
    8890      }
    89       if (Double.IsNaN(best)) best = hv; else best = Math.Max(best, hv);
    9091
    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()));
    94101      }
    95102
    96103      results["Hypervolume"].Value = new DoubleValue(hv);
    97       results["Absolute Distance to BestKnownHypervolume"].Value = new DoubleValue(diff);
    98104      results["BestKnownHypervolume"].Value = new DoubleValue(best);
     105      results["Absolute Distance to BestKnownHypervolume"].Value = new DoubleValue(best - hv);
    99106
     107      return base.Apply();
    100108    }
     109
    101110  }
    102111}
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/InvertedGenerationalDistanceAnalyzer.cs

    r14030 r14044  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3132  [Item("InvertedGenerationalDistanceAnalyzer", "The inverted generational distance between the current and the best known front (see Multi-Objective Performance Metrics - Shodhganga for more information)")]
    3233  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"]; }
    3538    }
     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
    3649    [StorableConstructor]
    3750    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) { }
    4152    public override IDeepCloneable Clone(Cloner cloner) {
    4253      return new InvertedGenerationalDistanceAnalyzer(this, cloner);
    4354    }
    4455
    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();
    5472    }
    5573
    56     public InvertedGenerationalDistanceAnalyzer() {
    57       Parameters.Add(new ValueParameter<DoubleValue>("Dampening", "", new DoubleValue(1)));
    58     }
    5974
    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     }
    6775  }
    6876}
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/MOTFAnalyzer.cs

    r14030 r14044  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    23 using System.Linq;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
     
    3533  [StorableClass]
    3634  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; } }
    4136
    4237    public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter {
     
    4944
    5045    public ILookupParameter<IMultiObjectiveTestFunction> TestFunctionParameter {
    51       get {
    52         return (ILookupParameter<IMultiObjectiveTestFunction>)Parameters["TestFunction"];
    53       }
     46      get { return (ILookupParameter<IMultiObjectiveTestFunction>)Parameters["TestFunction"]; }
    5447    }
    5548
    5649    public ILookupParameter<DoubleMatrix> BestKnownFrontParameter {
    57       get {
    58         return (ILookupParameter<DoubleMatrix>)Parameters["BestKnownFront"];
    59       }
     50      get { return (ILookupParameter<DoubleMatrix>)Parameters["BestKnownFront"]; }
    6051    }
    6152
    62     protected MOTFAnalyzer(MOTFAnalyzer original, Cloner cloner) : base(original, cloner) {
    63     }
     53    protected MOTFAnalyzer(MOTFAnalyzer original, Cloner cloner) : base(original, cloner) { }
     54
    6455    [StorableConstructor]
    6556    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() {
    6858      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector."));
    6959      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to."));
     
    7161      Parameters.Add(new LookupParameter<DoubleMatrix>("BestKnownFront", "The currently best known Pareto front"));
    7262    }
    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);
    9763  }
    9864}
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/NormalizedHypervolumeAnalyzer.cs

    r14030 r14044  
    3232namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
    3333  [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")]
    3535  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 Names
    4836    private const string bestKnownFront = "BestKnownFront Zitzler";
    4937    private const string resultsHV = "NormalizedHypervolume";
     
    5139
    5240    private const string bestknownHV = "NormalizedBestKnownHyperVolume";
    53     #endregion
    5441
    55     #region parameters
    5642    public IValueParameter<DoubleMatrix> OptimalFrontParameter {
    57       get {
    58         return (IValueParameter<DoubleMatrix>)Parameters[bestKnownFront];
    59       }
     43      get { return (IValueParameter<DoubleMatrix>)Parameters[bestKnownFront]; }
    6044    }
    6145
    6246    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]; }
    6948    }
    70     #endregion
    7149
    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"));
    7555    }
     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
    7664
    7765    private void RegisterEventHandlers() {
     
    8371    }
    8472
    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;
    8777      int objectives = qualities[0].Length;
     78
    8879      double best = BestKnownHyperVolumeParameter.Value.Value;
    8980      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 dimensions
     81        return base.Apply(); // too pareto front nonexistant or with wrong number of dimensions
    9182      }
    9283
    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);
    9485
    9586      if (!results.ContainsKey(resultsHV)) results.Add(new Result(resultsHV, typeof(DoubleValue)));
     
    10192      }
    10293
    103       bool[] maximization = TestFunctionParameter.ActualValue.Maximization(objectives);
     94      bool[] maximization = testFunction.Maximization(objectives);
    10495      double[] invPoint = GetBestPoint(OptimalFrontParameter.Value, maximization);
    10596      double[] refPoint = GetWorstPoint(OptimalFrontParameter.Value, maximization);
     
    10798      double hv = front.Any() ? Hypervolume.Calculate(front, refPoint, maximization) / normalization : 0;
    10899
    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()));
    114103      }
    115104
    116105      results[resultsHV].Value = new DoubleValue(hv);
    117       results[resultsDist].Value = new DoubleValue(diff);
    118106      results[bestknownHV].Value = new DoubleValue(best);
     107      results[resultsDist].Value = new DoubleValue(best - hv);
    119108
     109      return base.Apply();
    120110    }
    121111
    122     private double[] GetWorstPoint(DoubleMatrix value, bool[] maximization) {
     112
     113    private static double[] GetWorstPoint(DoubleMatrix value, bool[] maximization) {
    123114      bool[] invMax = new bool[maximization.Length];
    124115      int i = 0;
     
    129120    }
    130121
    131     private double[] GetBestPoint(DoubleMatrix value, bool[] maximization) {
     122    private static double[] GetBestPoint(DoubleMatrix value, bool[] maximization) {
    132123      double[] res = new double[maximization.Length];
    133124      for (int i = 0; i < maximization.Length; i++) {
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/ScatterPlotAnalyzer.cs

    r14030 r14044  
    1919 */
    2020#endregion
     21
    2122using System.Linq;
    2223using HeuristicLab.Common;
     
    2425using HeuristicLab.Encodings.RealVectorEncoding;
    2526using HeuristicLab.Optimization;
     27using HeuristicLab.Parameters;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
     
    3133  public class ScatterPlotAnalyzer : MOTFAnalyzer {
    3234
    33     [StorableHook(HookType.AfterDeserialization)]
    34     private void AfterDeserialization() {
     35    public IScopeTreeLookupParameter<RealVector> IndividualsParameter {
     36      get { return (IScopeTreeLookupParameter<RealVector>)Parameters["Individuals"]; }
    3537    }
     38
    3639    [StorableConstructor]
    3740    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) { }
    4042    public override IDeepCloneable Clone(Cloner cloner) {
    4143      return new ScatterPlotAnalyzer(this, cloner);
    4244    }
    4345
    44     public ScatterPlotAnalyzer() { }
     46    public ScatterPlotAnalyzer() {
     47      Parameters.Add(new ScopeTreeLookupParameter<RealVector>("Individuals", "The individual solutions to the problem"));
     48    }
    4549
    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;
    4854      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;
    5556
    5657      if (!results.ContainsKey("Scatterplot")) {
     
    5859      }
    5960
    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();
    6171    }
    6272  }
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/SpacingAnalyzer.cs

    r13725 r14044  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3031  [Item("SpacingAnalyzer", "The spacing of the current front (see Multi-Objective Performance Metrics - Shodhganga for more information)")]
    3132  public class SpacingAnalyzer : MOTFAnalyzer {
    32 
    33     [StorableHook(HookType.AfterDeserialization)]
    34     private void AfterDeserialization() {
    35     }
    36 
    3733    [StorableConstructor]
    3834    protected SpacingAnalyzer(bool deserializing) : base(deserializing) { }
    3935
    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) { }
    4637    public override IDeepCloneable Clone(Cloner cloner) {
    4738      return new SpacingAnalyzer(this, cloner);
    4839    }
    4940
    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();
    5354    }
    5455  }
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Interfaces/IMultiObjectiveTestFunctionAnalyzer.cs

    r13725 r14044  
    2626
    2727  public interface IMultiObjectiveTestFunctionAnalyzer : IAnalyzer, IMultiObjectiveOperator {
    28     ILookupParameter<IEncoding> EncodingParameter { get; }
    29 
    3028    IScopeTreeLookupParameter<DoubleArray> QualitiesParameter { get; }
    31 
    3229    ILookupParameter<ResultCollection> ResultsParameter { get; }
    33 
    3430    ILookupParameter<IMultiObjectiveTestFunction> TestFunctionParameter { get; }
    35 
    3631    ILookupParameter<DoubleMatrix> BestKnownFrontParameter { get; }
    37 
    3832  }
    3933}
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/MultiObjectiveTestFunctionProblem.cs

    r14030 r14044  
    286286
    287287
    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);
    291292        }
    292293
    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;
    295302        }
    296303
Note: See TracChangeset for help on using the changeset viewer.