Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/18/16 15:50:10 (8 years ago)
Author:
bwerth
Message:

#1087 refactored Analyzers to use ResultParameters

Location:
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3
Files:
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/CrowdingAnalyzer.cs

    r14085 r14097  
    3737    }
    3838
     39    public IResultParameter<DoubleValue> CrowdingResultParameter {
     40      get { return (IResultParameter<DoubleValue>)Parameters["Crowding"]; }
     41    }
     42
    3943    [StorableConstructor]
    4044    protected CrowdingAnalyzer(bool deserializing) : base(deserializing) { }
     
    4953      Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds",
    5054        "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."));
     55      Parameters.Add(new ResultParameter<DoubleValue>("Crowding", "The average corwding value of all points (excluding infinities)"));
     56      CrowdingResultParameter.DefaultValue = new DoubleValue(double.NaN);
     57
    5158    }
    5259
    5360    public override IOperation Apply() {
    54       var results = ResultsParameter.ActualValue;
    5561      var qualities = QualitiesParameter.ActualValue;
    5662      var bounds = BoundsParameter.ActualValue;
    5763
    58       if (!results.ContainsKey("Crowding")) results.Add(new Result("Crowding", new DoubleValue()));
    59       var resultValue = (DoubleValue)results["Crowding"].Value;
    60 
    6164      var crowdingDistance = Crowding.Calculate(qualities.Select(x => x.ToArray()), bounds.CloneAsMatrix());
    62       resultValue.Value = crowdingDistance;
     65      CrowdingResultParameter.ActualValue.Value = crowdingDistance;
    6366
    6467      return base.Apply();
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/GenerationalDistanceAnalyzer.cs

    r14085 r14097  
    2020#endregion
    2121
     22using System;
    2223using System.Linq;
    2324using HeuristicLab.Common;
     
    4344    }
    4445
     46    public IResultParameter<DoubleValue> GenerationalDistanceResultParameter {
     47      get { return (IResultParameter<DoubleValue>)Parameters["Generational Distance"]; }
     48    }
     49
    4550    [StorableConstructor]
    4651    protected GenerationalDistanceAnalyzer(bool deserializing) : base(deserializing) { }
     
    5257    public GenerationalDistanceAnalyzer() {
    5358      Parameters.Add(new FixedValueParameter<DoubleValue>("Dampening", "", new DoubleValue(1)));
     59      Parameters.Add(new ResultParameter<DoubleValue>("Generational Distance", "The genrational distance between the current front and the optimal front"));
     60      GenerationalDistanceResultParameter.DefaultValue = new DoubleValue(double.NaN);
     61
    5462    }
    5563
    5664    public override IOperation Apply() {
    57       var results = ResultsParameter.ActualValue;
    5865      var qualities = QualitiesParameter.ActualValue;
    5966      int objectives = qualities[0].Length;
     
    6269      if (optimalfront == null) return base.Apply();
    6370
    64       if (!results.ContainsKey("GenerationalDistance")) results.Add(new Result("GenerationalDistance", new DoubleValue()));
    65       var resultValue = (DoubleValue)results["GenerationalDistance"].Value;
    66 
    6771      var distance = GenerationalDistance.Calculate(qualities.Select(x => x.CloneAsArray()), optimalfront, Dampening);
    68       resultValue.Value = distance;
     72      GenerationalDistanceResultParameter.ActualValue.Value = distance;
    6973
    7074      return base.Apply();
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs

    r14092 r14097  
    3838      get { return (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"]; }
    3939    }
     40    public IResultParameter<DoubleValue> HypervolumeResultParameter {
     41      get { return (IResultParameter<DoubleValue>)Parameters["Hypervolume"]; }
     42    }
     43    public IResultParameter<DoubleValue> BestKnownHypervolumeResultParameter {
     44      get { return (IResultParameter<DoubleValue>)Parameters["Best known hypervolume"]; }
     45    }
     46    public IResultParameter<DoubleValue> HypervolumeDistanceResultParameter {
     47      get { return (IResultParameter<DoubleValue>)Parameters["Absolute Distance to BestKnownHypervolume"]; }
     48    }
     49
    4050
    4151    [StorableConstructor]
     
    5262    public HypervolumeAnalyzer() {
    5363      Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
     64      Parameters.Add(new ResultParameter<DoubleValue>("Hypervolume", "The hypervolume of the current generation"));
     65      Parameters.Add(new ResultParameter<DoubleValue>("Best known hypervolume", "The optimal hypervolume"));
     66      Parameters.Add(new ResultParameter<DoubleValue>("Absolute Distance to BestKnownHypervolume", "The difference between the best known and the current hypervolume"));
     67      HypervolumeResultParameter.DefaultValue = new DoubleValue(0);
     68      BestKnownHypervolumeResultParameter.DefaultValue = new DoubleValue(0);
     69      HypervolumeDistanceResultParameter.DefaultValue = new DoubleValue(0);
     70
     71
    5472    }
    5573
    5674    public override IOperation Apply() {
    57       var results = ResultsParameter.ActualValue;
    5875      var qualities = QualitiesParameter.ActualValue;
    5976      var testFunction = TestFunctionParameter.ActualValue;
     
    6178      var referencePoint = ReferencePointParameter.ActualValue;
    6279
    63       if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", new DoubleValue(0)));
    64       if (!results.ContainsKey("Absolute Distance to BestKnownHypervolume")) results.Add(new Result("Absolute Distance to BestKnownHypervolume", new DoubleValue(0)));
    65 
    66       double best = testFunction.OptimalHypervolume(objectives);
    67       if (!results.ContainsKey("BestKnownHypervolume")) {
    68         results.Add(new Result("BestKnownHypervolume", new DoubleValue(0)));
    69       } else {
    70         best = Math.Max(best, ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value);
     80      double best = BestKnownHypervolumeResultParameter.ActualValue.Value;
     81      if (referencePoint.SequenceEqual(testFunction.ReferencePoint(objectives))) {
     82        best = Math.Max(best, testFunction.OptimalHypervolume(objectives));
    7183      }
    72 
    7384
    7485      IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true);
     
    7687      double hv = Hypervolume.Calculate(front, referencePoint.ToArray(), testFunction.Maximization(objectives));
    7788
    78       if (double.IsNaN(best) || best < hv) {
     89      if (!double.IsNaN(hv) || best < hv) {
    7990        best = hv;
    80         BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities.Select(q => q.ToArray()).ToArray()));
    8191      }
    8292
    83       ((DoubleValue)(results["Hypervolume"].Value)).Value = hv;
    84       ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value = best;
    85       ((DoubleValue)(results["Absolute Distance to BestKnownHypervolume"].Value)).Value = best - hv;
     93      HypervolumeResultParameter.ActualValue.Value = hv;
     94      BestKnownHypervolumeResultParameter.ActualValue.Value = best;
     95      HypervolumeDistanceResultParameter.ActualValue.Value = best - hv;
    8696
    8797      return base.Apply();
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/InvertedGenerationalDistanceAnalyzer.cs

    r14085 r14097  
    4343    }
    4444
     45    public IResultParameter<DoubleValue> InvertedGenerationalDistanceResultParameter {
     46      get { return (IResultParameter<DoubleValue>)Parameters["Inverted Generational Distance"]; }
     47    }
     48
    4549    public InvertedGenerationalDistanceAnalyzer() {
    4650      Parameters.Add(new FixedValueParameter<DoubleValue>("Dampening", "", new DoubleValue(1)));
     51      Parameters.Add(new ResultParameter<DoubleValue>("Inverted Generational Distance", "The genrational distance between the current front and the optimal front"));
     52      InvertedGenerationalDistanceResultParameter.DefaultValue = new DoubleValue(double.NaN);
     53
    4754    }
     55
    4856
    4957    [StorableConstructor]
     
    5563
    5664    public override IOperation Apply() {
    57       var results = ResultsParameter.ActualValue;
    5865      var qualities = QualitiesParameter.ActualValue;
    5966      var testFunction = TestFunctionParameter.ActualValue;
     
    6370      if (optimalfront == null) return base.Apply();
    6471
    65       if (!results.ContainsKey("InvertedGenerationalDistance")) results.Add(new Result("InvertedGenerationalDistance", new DoubleValue(double.NaN)));
    66       var resultValue = (DoubleValue)results["InvertedGenerationalDistance"].Value;
    67 
    6872      var invertedGenerationalDistance = InvertedGenerationalDistance.Calculate(qualities.Select(q => q.ToArray()), optimalfront, DampeningParameter.Value.Value);
    69       resultValue.Value = invertedGenerationalDistance;
     73      InvertedGenerationalDistanceResultParameter.ActualValue.Value = invertedGenerationalDistance;
    7074
    7175      return base.Apply();
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/ScatterPlotAnalyzer.cs

    r14092 r14097  
    3737    }
    3838
     39    public IResultParameter<ScatterPlotContent> ScatterPlotResultParameter {
     40      get { return (IResultParameter<ScatterPlotContent>)Parameters["Scatterplot"]; }
     41    }
     42
     43
    3944    [StorableConstructor]
    4045    protected ScatterPlotAnalyzer(bool deserializing) : base(deserializing) { }
     
    4651    public ScatterPlotAnalyzer() {
    4752      Parameters.Add(new ScopeTreeLookupParameter<RealVector>("Individuals", "The individual solutions to the problem"));
     53      Parameters.Add(new ResultParameter<ScatterPlotContent>("Scatterplot", "The scatterplot for the current and optimal (if known front)"));
     54
    4855    }
    4956
    5057    public override IOperation Apply() {
    51       var results = ResultsParameter.ActualValue;
    5258      var qualities = QualitiesParameter.ActualValue;
    5359      var testFunction = TestFunctionParameter.ActualValue;
    5460      int objectives = qualities[0].Length;
    5561      var individuals = IndividualsParameter.ActualValue;
    56 
    57       if (!results.ContainsKey("Scatterplot")) {
    58         results.Add(new Result("Scatterplot", typeof(ScatterPlotContent)));
    59       }
    6062
    6163      double[][] optimalFront = new double[0][];
     
    6668      var solutionClones = individuals.Select(s => s.ToArray()).ToArray();
    6769
    68       results["Scatterplot"].Value = new ScatterPlotContent(qualityClones, solutionClones, optimalFront, objectives);
     70      ScatterPlotResultParameter.ActualValue = new ScatterPlotContent(qualityClones, solutionClones, optimalFront, objectives);
    6971
    7072      return base.Apply();
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/SpacingAnalyzer.cs

    r14044 r14097  
    3131  [Item("SpacingAnalyzer", "The spacing of the current front (see Multi-Objective Performance Metrics - Shodhganga for more information)")]
    3232  public class SpacingAnalyzer : MOTFAnalyzer {
     33
     34    public IResultParameter<DoubleValue> SpacingResultParameter {
     35      get { return (IResultParameter<DoubleValue>)Parameters["Spacing"]; }
     36    }
    3337    [StorableConstructor]
    3438    protected SpacingAnalyzer(bool deserializing) : base(deserializing) { }
     39
    3540
    3641    protected SpacingAnalyzer(SpacingAnalyzer original, Cloner cloner) : base(original, cloner) { }
     
    3944    }
    4045
    41     public SpacingAnalyzer() { }
     46    public SpacingAnalyzer() {
     47      Parameters.Add(new ResultParameter<DoubleValue>("Spacing", "The spacing of the current front"));
     48      SpacingResultParameter.DefaultValue = new DoubleValue(double.NaN);
     49    }
    4250
    4351    public override IOperation Apply() {
    44       var results = ResultsParameter.ActualValue;
    4552      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 
    5053      var spacing = Spacing.Calculate(qualities.Select(q => q.ToArray()));
    51       resultValue.Value = spacing;
     54      SpacingResultParameter.ActualValue.Value = spacing;
    5255
    5356      return base.Apply();
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/HeuristicLab.Problems.MultiObjectiveTestFunctions-3.3.csproj

    r14092 r14097  
    161161    <Compile Include="Calculators\InvertedGenerationalDistance.cs" />
    162162    <Compile Include="Calculators\GenerationalDistance.cs" />
    163     <Compile Include="Calculators\Utilities.cs" />
     163    <Compile Include="Utilities.cs" />
    164164    <Compile Include="Instances\MISCInstanceProvider.cs" />
    165165    <Compile Include="Instances\ZDTInstanceProvider.cs" />
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/MultiObjectiveTestFunctionProblem.cs

    r14092 r14097  
    174174      var front = TestFunction.OptimalParetoFront(Objectives);
    175175      if (front != null) {
    176         BestKnownFrontParameter.Value = (DoubleMatrix)new DoubleMatrix(To2D(front.ToArray())).AsReadOnly();
     176        BestKnownFrontParameter.Value = (DoubleMatrix)Utilities.ToMatrix(front).AsReadOnly();
    177177      } else BestKnownFrontParameter.Value = null;
    178178
     
    249249    }
    250250
    251     public static T[,] To2D<T>(T[][] source) {
    252       try {
    253         int firstDimension = source.Length;
    254         int secondDimension = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular
    255 
    256         var result = new T[firstDimension, secondDimension];
    257         for (int i = 0; i < firstDimension; ++i)
    258           for (int j = 0; j < secondDimension; ++j)
    259             result[i, j] = source[i][j];
    260 
    261         return result;
    262       }
    263       catch (InvalidOperationException) {
    264         throw new InvalidOperationException("The given jagged array is not rectangular.");
    265       }
    266     }
    267 
    268251    #endregion
    269252  }
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Utilities.cs

    r14096 r14097  
    2222using System.Collections.Generic;
    2323using System.Linq;
     24using HeuristicLab.Data;
    2425
    2526namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
     
    4445    }
    4546
     47    internal static DoubleMatrix ToMatrix(IEnumerable<double[]> source) {
     48      try {
     49        int firstDimension = source.Count();
     50        int secondDimension = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular
     51
     52        var result = new DoubleMatrix(firstDimension, secondDimension);
     53        var enumarator = source.GetEnumerator();
     54        for (int i = 0; i < firstDimension && enumarator.MoveNext(); ++i)
     55          for (int j = 0; j < secondDimension; ++j)
     56            result[i, j] = enumarator.Current[j];
     57        return result;
     58      }
     59      catch (InvalidOperationException) {
     60        throw new InvalidOperationException("The given jagged array is not rectangular.");
     61      }
     62    }
     63
    4664    internal class DimensionComparer : IComparer<double[]> {
    4765      private readonly int dim;
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Views/ScatterPlotContent.cs

    r14093 r14097  
    2828namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
    2929  [StorableClass]
     30  [Item("ScatterPlot", "The optimal front, current front and its associated Points in the searchspace")]
    3031  public class ScatterPlotContent : Item {
    3132
     
    3738      }
    3839
    39       set {
     40      private set {
    4041        qualities = value;
    4142      }
     
    4950      }
    5051
    51       set {
     52      private set {
    5253        objectives = value;
    5354      }
     
    6162      }
    6263
    63       set {
     64      private set {
    6465        solutions = value;
    6566      }
     
    7374      }
    7475
    75       set {
     76      private set {
    7677        paretoFront = value;
    7778      }
Note: See TracChangeset for help on using the changeset viewer.