Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14085


Ignore:
Timestamp:
07/15/16 14:14:50 (8 years ago)
Author:
mkommend
Message:

#1087: Further refactoring of testfunction problem and analyzers.

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  
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Optimization;
     27using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    3132  [Item("CrowdingAnalyzer", "The mean crowding distance for each point of the Front (see Multi-Objective Performance Metrics - Shodhganga for more information)")]
    3233  public class CrowdingAnalyzer : MOTFAnalyzer {
     34
     35    public ILookupParameter<DoubleMatrix> BoundsParameter {
     36      get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
     37    }
    3338
    3439    [StorableConstructor]
     
    4146    }
    4247
    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    }
    4452
    4553    public override IOperation Apply() {
    4654      var results = ResultsParameter.ActualValue;
    4755      var qualities = QualitiesParameter.ActualValue;
    48       var testFunction = TestFunctionParameter.ActualValue;
    49       int objectives = qualities[0].Length;
     56      var bounds = BoundsParameter.ActualValue;
    5057
    5158      if (!results.ContainsKey("Crowding")) results.Add(new Result("Crowding", new DoubleValue()));
    5259      var resultValue = (DoubleValue)results["Crowding"].Value;
    5360
    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());
    5562      resultValue.Value = crowdingDistance;
    5663
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/GenerationalDistanceAnalyzer.cs

    r14044 r14085  
    6565      var resultValue = (DoubleValue)results["GenerationalDistance"].Value;
    6666
    67       var distance = GenerationalDistance.Calculate(qualities.Select(x => x.ToArray()), optimalfront, Dampening);
     67      var distance = GenerationalDistance.Calculate(qualities.Select(x => x.CloneAsArray()), optimalfront, Dampening);
    6868      resultValue.Value = distance;
    6969
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs

    r14081 r14085  
    3434  public class HypervolumeAnalyzer : MOTFAnalyzer {
    3535
    36     public IValueParameter<DoubleArray> ReferencePointParameter {
    37       get { return (IValueParameter<DoubleArray>)Parameters["ReferencePoint"]; }
     36    public ILookupParameter<DoubleArray> ReferencePointParameter {
     37      get { return (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"]; }
    3838    }
    3939
     
    4949    [StorableConstructor]
    5050    protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) { }
    51     [StorableHook(HookType.AfterDeserialization)]
    52     private void AfterDeserialization() {
    53       RegisterEventHandlers();
    54     }
    5551
    5652    protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner)
    5753      : base(original, cloner) {
    58       RegisterEventHandlers();
    5954    }
    6055    public override IDeepCloneable Clone(Cloner cloner) {
     
    6358
    6459    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"));
    6661      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;
    7362    }
    7463
     
    7766      var qualities = QualitiesParameter.ActualValue;
    7867      var testFunction = TestFunctionParameter.ActualValue;
     68      var referencePoint = ReferencePointParameter.ActualValue;
    7969      int objectives = qualities[0].Length;
     70
     71
    8072
    8173      if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", typeof(DoubleValue)));
     
    9385      IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true);
    9486
    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;
    9688
    9789
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/InvertedGenerationalDistanceAnalyzer.cs

    r14044 r14085  
    6060      int objectives = qualities[0].Length;
    6161
    62       var optimalfront = TestFunctionParameter.ActualValue.OptimalParetoFront(objectives);
     62      var optimalfront = testFunction.OptimalParetoFront(objectives);
    6363      if (optimalfront == null) return base.Apply();
    6464
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Interfaces/IMultiObjectiveTestFunction.cs

    r14065 r14085  
    3131    bool[] Maximization(int objectives);
    3232    double[,] Bounds(int objectives);
     33
    3334    IEnumerable<double[]> OptimalParetoFront(int objectives);
     35    double OptimalHypervolume(int objectives);
    3436    double[] ReferencePoint(int objectives);
    35     double BestKnownHypervolume(int objectives);
    3637
    3738    int MinimumSolutionLength { get; }
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/MultiObjectiveTestFunctionProblem.cs

    r14073 r14085  
    6565    public override bool[] Maximization {
    6666      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();
    7069      }
    7170    }
     
    8786      set { TestFunctionParameter.Value = value; }
    8887    }
    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; }
    9195    }
    9296    #endregion
     
    112116      Parameters.Add(new FixedValueParameter<IntValue>("Objectives", "The dimensionality of the solution vector (number of objectives).", new IntValue(2)));
    113117      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."));
    114119      Parameters.Add(new ValueParameter<IMultiObjectiveTestFunction>("TestFunction", "The function that is to be optimized.", new Fonseca()));
    115120      Parameters.Add(new ValueParameter<DoubleMatrix>("BestKnownFront", "The currently best known Pareto front"));
     
    165170    #region Events
    166171    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));
    171182    }
    172183
     
    186197      Objectives = Math.Max(TestFunction.MinimumObjectives, Math.Min(Objectives, TestFunction.MaximumObjectives));
    187198
    188       Bounds = (DoubleMatrix)new DoubleMatrix(TestFunction.Bounds(Objectives)).Clone();
    189199      ParameterizeAnalyzers();
    190200      UpdateParameterValues();
     
    228238        analyzer.BestKnownFrontParameter.ActualName = BestKnownFrontParameter.Name;
    229239
     240        var crowdingAnalyzer = analyzer as CrowdingAnalyzer;
     241        if (crowdingAnalyzer != null) {
     242          crowdingAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name;
     243        }
     244
    230245        var hyperVolumeAnalyzer = analyzer as HypervolumeAnalyzer;
    231246        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);
    234249        }
    235250
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/NonDominatedSelect.cs

    r14081 r14085  
    2424namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
    2525
    26   public class NonDominatedSelect {
     26  public static class NonDominatedSelect {
    2727    public enum DominationResult { Dominates, IsDominated, IsNonDominated };
    2828
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/MultiObjectiveTestFunction.cs

    r14068 r14085  
    105105    /// returns the best known Hypervolume for this test function   (default=-1)
    106106    /// </summary>     
    107     public virtual double BestKnownHypervolume(int objectives) {
     107    public virtual double OptimalHypervolume(int objectives) {
    108108      CheckObjectives(objectives);
    109109      return GetBestKnownHypervolume(objectives);
Note: See TracChangeset for help on using the changeset viewer.