Changeset 16171 for branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy
- Timestamp:
- 09/21/18 09:18:49 (6 years ago)
- 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 17 17 <DebugType>full</DebugType> 18 18 <Optimize>false</Optimize> 19 <OutputPath> $(SolutionDir)\bin\</OutputPath>19 <OutputPath>..\..\..\..\trunk\bin\</OutputPath> 20 20 <DefineConstants>DEBUG;TRACE</DefineConstants> 21 21 <ErrorReport>prompt</ErrorReport> … … 80 80 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.ALGLIB-3.7.0.dll</HintPath> 81 81 </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> 83 84 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Collections-3.3.dll</HintPath> 84 85 </Reference> … … 88 89 <Reference Include="HeuristicLab.Core-3.3"> 89 90 <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>93 91 </Reference> 94 92 <Reference Include="HeuristicLab.Encodings.RealVectorEncoding-3.3"> … … 131 129 <Name>HeuristicLab.Analysis-3.3</Name> 132 130 </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> 133 135 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> 134 136 <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project> -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/IIndicator.cs
r15583 r16171 34 34 /// <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> 35 35 /// <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); 37 37 } 38 38 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/CrowdingIndicator.cs
r15583 r16171 28 28 using HeuristicLab.Optimization; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Problems.TestFunctions.MultiObjective; 30 31 31 32 namespace HeuristicLab.Algorithms.MOCMAEvolutionStrategy { … … 41 42 #endregion 42 43 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) { 45 45 var extracted = front.Select(x => x.PenalizedFitness).ToArray(); 46 46 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); 62 48 return pointsums.Select((value, index) => new { value, index }).OrderBy(x => x.value).First().index; 63 49 } -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/HypervolumeIndicator.cs
r15583 r16171 30 30 using HeuristicLab.Problems.TestFunctions.MultiObjective; 31 31 namespace HeuristicLab.Algorithms.MOCMAEvolutionStrategy { 32 [Item("HypervolumeIndicator", "Selection of Offspring based on contributing Hypervolume")]32 [Item("HypervolumeIndicator", "Selection of offspring based on contributing Hypervolume")] 33 33 [StorableClass] 34 34 internal class HypervolumeIndicator : Item, IIndicator { … … 41 41 #endregion 42 42 43 public int LeastContributer(IReadOnlyList<Individual> front, MultiObjectiveBasicProblem<RealVectorEncoding>problem) {43 public int LeastContributer(IReadOnlyList<Individual> front, IMultiObjectiveBasicProblem problem) { 44 44 var frontCopy = front.Select(x => x.PenalizedFitness).ToList(); 45 45 if (frontCopy.Count <= 1) return 0; 46 46 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); 48 49 var contributions = Enumerable.Range(0, frontCopy.Count).Select(i => Contribution(frontCopy, i, problem.Maximization, refPoint)); 49 50 return contributions.Select((value, index) => new { value, index }).OrderBy(x => x.value).First().index; … … 54 55 var point = front[idx]; 55 56 front.RemoveAt(idx); 56 var contribution = -Hypervolume .Calculate(front.ToArray(), refPoint, maximization);57 var contribution = -HypervolumeCalculator.CalculateHypervolume(front.ToArray(), refPoint, maximization); 57 58 front.Insert(idx, point); 58 59 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;66 60 } 67 61 #endregion -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/MinimalDistanceIndicator.cs
r15583 r16171 42 42 #endregion 43 43 44 public int LeastContributer(IReadOnlyList<Individual> front, MultiObjectiveBasicProblem<RealVectorEncoding>problem) {44 public int LeastContributer(IReadOnlyList<Individual> front, IMultiObjectiveBasicProblem problem) { 45 45 var extracted = front.Select(x => x.PenalizedFitness).ToArray(); 46 46 if (extracted.Length <= 2) return 0; -
branches/2943_MOBasicProblem_MOCMAES/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/MOCMAEvolutionStrategy.cs
r16071 r16171 42 42 public class MOCMAEvolutionStrategy : BasicAlgorithm { 43 43 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; } 48 48 set { base.Problem = value; } 49 49 } 50 50 public override bool SupportsPause { 51 51 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 } 52 60 } 53 61 … … 309 317 solutions = new Individual[PopulationSize]; 310 318 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++) { 314 322 var dim = j % bounds.Rows; 315 323 x[j] = random.NextDouble() * (bounds[dim, 1] - bounds[dim, 0]) + bounds[dim, 0]; … … 322 330 private void InitStrategy() { 323 331 const int lambda = 1; 324 double n = Problem.Encoding.Length;332 double n = Encoding.Length; 325 333 targetSuccessProbability = 1.0 / (5.0 + Math.Sqrt(lambda) / 2.0); 326 334 stepSizeDampeningFactor = 1.0 + n / (2.0 * lambda); … … 358 366 if (problem == null) return; 359 367 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); 361 369 ResultsDifferenceBestKnownHypervolume = ResultsBestKnownHypervolume; 362 370 } … … 417 425 } 418 426 private RealVector ClosestFeasible(RealVector x) { 419 var bounds = Problem.Encoding.Bounds;427 var bounds = Encoding.Bounds; 420 428 var r = new RealVector(x.Length); 421 429 for (var i = 0; i < x.Length; i++) { … … 426 434 } 427 435 private bool IsFeasable(RealVector offspring) { 428 var bounds = Problem.Encoding.Bounds;436 var bounds = Encoding.Bounds; 429 437 for (var i = 0; i < offspring.Length; i++) { 430 438 var dim = i % bounds.Rows; … … 438 446 //perform a nondominated sort to assign the rank to every element 439 447 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); 441 449 442 450 //deselect the highest rank fronts until we would end up with less or equal mu elements … … 470 478 471 479 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); 473 484 ResultsSolutions = solutions.Select(x => x.Mean.ToArray()).ToMatrix(); 474 485 … … 476 487 if (problem == null) return; 477 488 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); 486 496 ResultsBestHypervolume = Math.Max(ResultsHypervolume, ResultsBestHypervolume); 487 497 ResultsDifferenceBestKnownHypervolume = ResultsBestKnownHypervolume - ResultsBestHypervolume;
Note: See TracChangeset
for help on using the changeset viewer.