Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/21/18 09:18:49 (6 years ago)
Author:
bwerth
Message:

#2943 worked on MOBasicProblem - added Interfaces;reworked MOCalculators; several minor changes

Location:
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/HeuristicLab.Algorithms.MOCMAEvolutionStrategy-3.3.csproj

    r16123 r16171  
    1717    <DebugType>full</DebugType>
    1818    <Optimize>false</Optimize>
    19     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     19    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    2020    <DefineConstants>DEBUG;TRACE</DefineConstants>
    2121    <ErrorReport>prompt</ErrorReport>
     
    8080      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.ALGLIB-3.7.0.dll</HintPath>
    8181    </Reference>
    82     <Reference Include="HeuristicLab.Collections-3.3">
     82    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     83      <SpecificVersion>False</SpecificVersion>
    8384      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Collections-3.3.dll</HintPath>
    8485    </Reference>
     
    8889    <Reference Include="HeuristicLab.Core-3.3">
    8990      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Core-3.3.dll</HintPath>
    90     </Reference>
    91     <Reference Include="HeuristicLab.Data-3.3">
    92       <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Data-3.3.dll</HintPath>
    9391    </Reference>
    9492    <Reference Include="HeuristicLab.Encodings.RealVectorEncoding-3.3">
     
    131129      <Name>HeuristicLab.Analysis-3.3</Name>
    132130    </ProjectReference>
     131    <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
     132      <Project>{bbab9df5-5ef3-4ba8-ade9-b36e82114937}</Project>
     133      <Name>HeuristicLab.Data-3.3</Name>
     134    </ProjectReference>
    133135    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
    134136      <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project>
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/IIndicator.cs

    r15583 r16171  
    3434    /// <param name="problem">The problem on which the front is evaluated (!! The function itself will NOT be evluated only bounds referencePoints & other metadata will be used</param>
    3535    /// <returns>the index of the least contributing point according to any type of quality criteria</returns>
    36     int LeastContributer(IReadOnlyList<Individual> front, MultiObjectiveBasicProblem<RealVectorEncoding> problem);
     36    int LeastContributer(IReadOnlyList<Individual> front, IMultiObjectiveBasicProblem problem);
    3737  }
    3838}
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/CrowdingIndicator.cs

    r15583 r16171  
    2828using HeuristicLab.Optimization;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Problems.TestFunctions.MultiObjective;
    3031
    3132namespace HeuristicLab.Algorithms.MOCMAEvolutionStrategy {
     
    4142    #endregion
    4243
    43     public int LeastContributer(IReadOnlyList<Individual> front, MultiObjectiveBasicProblem<RealVectorEncoding> problem) {
    44       var bounds = problem.Encoding.Bounds;
     44    public int LeastContributer(IReadOnlyList<Individual> front, IMultiObjectiveBasicProblem problem) {
    4545      var extracted = front.Select(x => x.PenalizedFitness).ToArray();
    4646      if (extracted.Length <= 2) return 0;
    47       var pointsums = new double[extracted.Length];
    48 
    49       for (var dim = 0; dim < problem.Maximization.Length; dim++) {
    50         var arr = extracted.Select(x => x[dim]).ToArray();
    51         Array.Sort(arr);
    52         var fmax = problem.Encoding.Bounds[dim % bounds.Rows, 1];
    53         var fmin = bounds[dim % bounds.Rows, 0];
    54         var pointIdx = 0;
    55         foreach (var point in extracted) {
    56           var pos = Array.BinarySearch(arr, point[dim]);
    57           var d = pos != 0 && pos != arr.Length - 1 ? (arr[pos + 1] - arr[pos - 1]) / (fmax - fmin) : double.PositiveInfinity;
    58           pointsums[pointIdx] += d;
    59           pointIdx++;
    60         }
    61       }
     47      var pointsums = CrowdingCalculator.CalculateCrowdingDistances(extracted);
    6248      return pointsums.Select((value, index) => new { value, index }).OrderBy(x => x.value).First().index;
    6349    }
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/HypervolumeIndicator.cs

    r15583 r16171  
    3030using HeuristicLab.Problems.TestFunctions.MultiObjective;
    3131namespace HeuristicLab.Algorithms.MOCMAEvolutionStrategy {
    32   [Item("HypervolumeIndicator", "Selection of Offspring based on contributing Hypervolume")]
     32  [Item("HypervolumeIndicator", "Selection of offspring based on contributing Hypervolume")]
    3333  [StorableClass]
    3434  internal class HypervolumeIndicator : Item, IIndicator {
     
    4141    #endregion
    4242
    43     public int LeastContributer(IReadOnlyList<Individual> front, MultiObjectiveBasicProblem<RealVectorEncoding> problem) {
     43    public int LeastContributer(IReadOnlyList<Individual> front, IMultiObjectiveBasicProblem problem) {
    4444      var frontCopy = front.Select(x => x.PenalizedFitness).ToList();
    4545      if (frontCopy.Count <= 1) return 0;
    4646      var p = problem as MultiObjectiveTestFunctionProblem;
    47       var refPoint = BuildReferencePoint(p != null ? frontCopy.Concat(new[] { p.ReferencePoint.CloneAsArray() }) : frontCopy, problem.Maximization);
     47      var tep = p != null ? frontCopy.Concat(new[] {p.ReferencePoint.CloneAsArray()}) : frontCopy;
     48      var refPoint = HypervolumeCalculator.CalculateNadirPoint(tep, problem.Maximization);
    4849      var contributions = Enumerable.Range(0, frontCopy.Count).Select(i => Contribution(frontCopy, i, problem.Maximization, refPoint));
    4950      return contributions.Select((value, index) => new { value, index }).OrderBy(x => x.value).First().index;
     
    5455      var point = front[idx];
    5556      front.RemoveAt(idx);
    56       var contribution = -Hypervolume.Calculate(front.ToArray(), refPoint, maximization);
     57      var contribution = -HypervolumeCalculator.CalculateHypervolume(front.ToArray(), refPoint, maximization);
    5758      front.Insert(idx, point);
    5859      return contribution;
    59     }
    60     private static double[] BuildReferencePoint(IEnumerable<double[]> front, IReadOnlyList<bool> maximization) {
    61       var refPoint = new double[maximization.Count];
    62       foreach (var point in front)
    63         for (var i = 0; i < maximization.Count; i++)
    64           refPoint[i] = maximization[i] ? Math.Min(refPoint[i], point[i]) : Math.Max(refPoint[i], point[i]);
    65       return refPoint;
    6660    }
    6761    #endregion
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/MinimalDistanceIndicator.cs

    r15583 r16171  
    4242    #endregion
    4343
    44     public int LeastContributer(IReadOnlyList<Individual> front, MultiObjectiveBasicProblem<RealVectorEncoding> problem) {
     44    public int LeastContributer(IReadOnlyList<Individual> front, IMultiObjectiveBasicProblem problem) {
    4545      var extracted = front.Select(x => x.PenalizedFitness).ToArray();
    4646      if (extracted.Length <= 2) return 0;
  • branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/MOCMAEvolutionStrategy.cs

    r16071 r16171  
    4242  public class MOCMAEvolutionStrategy : BasicAlgorithm {
    4343    public override Type ProblemType {
    44       get { return typeof(MultiObjectiveBasicProblem<RealVectorEncoding>); }
    45     }
    46     public new MultiObjectiveBasicProblem<RealVectorEncoding> Problem {
    47       get { return (MultiObjectiveBasicProblem<RealVectorEncoding>)base.Problem; }
     44      get { return typeof(IMultiObjectiveBasicProblem); }
     45    }
     46    public new IMultiObjectiveBasicProblem Problem {
     47      get { return (IMultiObjectiveBasicProblem)base.Problem; }
    4848      set { base.Problem = value; }
    4949    }
    5050    public override bool SupportsPause {
    5151      get { return true; }
     52    }
     53
     54    private RealVectorEncoding Encoding {
     55      get {
     56        if(Problem == null || !(Problem.Encoding is RealVectorEncoding))
     57          throw new ArgumentException("Multiobjective CMA-ES is only applicable to problems with RealVectorEncodings");
     58        return (RealVectorEncoding)Problem.Encoding;
     59      }
    5260    }
    5361
     
    309317      solutions = new Individual[PopulationSize];
    310318      for (var i = 0; i < PopulationSize; i++) {
    311         var x = new RealVector(Problem.Encoding.Length); // Uniform distibution in all dimensions assumed.
    312         var bounds = Problem.Encoding.Bounds;
    313         for (var j = 0; j < Problem.Encoding.Length; j++) {
     319        var x = new RealVector(Encoding.Length); // Uniform distibution in all dimensions assumed.
     320        var bounds = Encoding.Bounds;
     321        for (var j = 0; j < Encoding.Length; j++) {
    314322          var dim = j % bounds.Rows;
    315323          x[j] = random.NextDouble() * (bounds[dim, 1] - bounds[dim, 0]) + bounds[dim, 0];
     
    322330    private void InitStrategy() {
    323331      const int lambda = 1;
    324       double n = Problem.Encoding.Length;
     332      double n = Encoding.Length;
    325333      targetSuccessProbability = 1.0 / (5.0 + Math.Sqrt(lambda) / 2.0);
    326334      stepSizeDampeningFactor = 1.0 + n / (2.0 * lambda);
     
    358366      if (problem == null) return;
    359367      if (problem.BestKnownFront != null) {
    360         ResultsBestKnownHypervolume = Hypervolume.Calculate(problem.BestKnownFront.ToJaggedArray(), problem.TestFunction.ReferencePoint(problem.Objectives), Problem.Maximization);
     368        ResultsBestKnownHypervolume = HypervolumeCalculator.CalculateHypervolume(problem.BestKnownFront.ToJaggedArray(), problem.TestFunction.ReferencePoint(problem.Objectives), Problem.Maximization);
    361369        ResultsDifferenceBestKnownHypervolume = ResultsBestKnownHypervolume;
    362370      }
     
    417425    }
    418426    private RealVector ClosestFeasible(RealVector x) {
    419       var bounds = Problem.Encoding.Bounds;
     427      var bounds = Encoding.Bounds;
    420428      var r = new RealVector(x.Length);
    421429      for (var i = 0; i < x.Length; i++) {
     
    426434    }
    427435    private bool IsFeasable(RealVector offspring) {
    428       var bounds = Problem.Encoding.Bounds;
     436      var bounds = Encoding.Bounds;
    429437      for (var i = 0; i < offspring.Length; i++) {
    430438        var dim = i % bounds.Rows;
     
    438446      //perform a nondominated sort to assign the rank to every element
    439447      int[] ranks;
    440       var fronts = DominationCalculator<Individual>.CalculateAllParetoFronts(parents.ToArray(), parents.Select(i => i.PenalizedFitness).ToArray(), Problem.Maximization, out ranks);
     448      var fronts = DominationCalculator.CalculateAllParetoFronts(parents.ToArray(), parents.Select(i => i.PenalizedFitness).ToArray(), Problem.Maximization, out ranks);
    441449
    442450      //deselect the highest rank fronts until we would end up with less or equal mu elements
     
    470478
    471479    private void Analyze() {
    472       ResultsScatterPlot = new ParetoFrontScatterPlot(solutions.Select(x => x.Fitness).ToArray(), solutions.Select(x => x.Mean.ToArray()).ToArray(), ResultsScatterPlot.ParetoFront, ResultsScatterPlot.Objectives, ResultsScatterPlot.ProblemSize);
     480      var qualities = solutions.Select(x => x.Fitness).ToArray();
     481
     482      //to do check for side effects
     483      ResultsScatterPlot = new ParetoFrontScatterPlot(qualities, solutions.Select(x => x.Mean.ToArray()).ToArray(), ResultsScatterPlot.ParetoFront, ResultsScatterPlot.Objectives, ResultsScatterPlot.ProblemSize);
    473484      ResultsSolutions = solutions.Select(x => x.Mean.ToArray()).ToMatrix();
    474485
     
    476487      if (problem == null) return;
    477488
    478       var front = NonDominatedSelect.GetDominatingVectors(solutions.Select(x => x.Fitness), problem.ReferencePoint.CloneAsArray(), Problem.Maximization, true).ToArray();
    479       if (front.Length == 0) return;
    480       var bounds = problem.Bounds.CloneAsMatrix();
    481       ResultsCrowding = Crowding.Calculate(front, bounds);
    482       ResultsSpacing = Spacing.Calculate(front);
    483       ResultsGenerationalDistance = problem.BestKnownFront != null ? GenerationalDistance.Calculate(front, problem.BestKnownFront.ToJaggedArray(), 1) : double.NaN;
    484       ResultsInvertedGenerationalDistance = problem.BestKnownFront != null ? InvertedGenerationalDistance.Calculate(front, problem.BestKnownFront.ToJaggedArray(), 1) : double.NaN;
    485       ResultsHypervolume = Hypervolume.Calculate(front, problem.ReferencePoint.CloneAsArray(), Problem.Maximization);
     489     
     490      if (qualities.Length == 0) return;
     491      ResultsCrowding = CrowdingCalculator.CalculateCrowding(qualities);
     492      ResultsSpacing = SpacingCalculator.CalculateSpacing(qualities);
     493      ResultsGenerationalDistance = problem.BestKnownFront != null ? GenerationalDistanceCalculator.CalculateGenerationalDistance(qualities, problem.BestKnownFront.ToJaggedArray(), 1) : double.NaN;
     494      ResultsInvertedGenerationalDistance = problem.BestKnownFront != null ? GenerationalDistanceCalculator.CalculateInverseGenerationalDistance(qualities, problem.BestKnownFront.ToJaggedArray(), 1) : double.NaN;
     495      ResultsHypervolume = HypervolumeCalculator.CalculateHypervolume(qualities, problem.ReferencePoint.CloneAsArray(), Problem.Maximization);
    486496      ResultsBestHypervolume = Math.Max(ResultsHypervolume, ResultsBestHypervolume);
    487497      ResultsDifferenceBestKnownHypervolume = ResultsBestKnownHypervolume - ResultsBestHypervolume;
Note: See TracChangeset for help on using the changeset viewer.