Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17701 for branches


Ignore:
Timestamp:
07/27/20 20:14:29 (4 years ago)
Author:
dleko
Message:

#2825 Add Hypervolume Indicator and distance to the hypervolume of the best known front.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/NSGA3.cs

    r17700 r17701  
    8383        private const string GenerationalDistanceResultName = "Generational Distance";
    8484        private const string InvertedGenerationalDistanceResultName = "Inverted Generational Distance";
     85        private const string HypervolumeResultName = "Hypervolume";
     86        private const string BestKnownHypervolumeResultName = "Best known hypervolume";
     87        private const string DifferenceToBestKnownHypervolumeResultName = "Absolute Distance to BestKnownHypervolume";
    8588        private const string ScatterPlotResultName = "Scatter Plot";
    8689        private const string CurrentFrontResultName = "Pareto Front"; // Do not touch this
     
    171174            get { return (DoubleValue)Results[InvertedGenerationalDistanceResultName].Value; }
    172175            set { Results[InvertedGenerationalDistanceResultName].Value = value; }
     176        }
     177
     178        public DoubleValue ResultsHypervolume
     179        {
     180            get { return (DoubleValue)Results[HypervolumeResultName].Value; }
     181            set { Results[HypervolumeResultName].Value = value; }
     182        }
     183
     184        public DoubleValue ResultsBestKnownHypervolume
     185        {
     186            get { return (DoubleValue)Results[BestKnownHypervolumeResultName].Value; }
     187            set { Results[BestKnownHypervolumeResultName].Value = value; }
     188        }
     189
     190        public DoubleValue ResultsDifferenceToBestKnownHypervolume
     191        {
     192            get { return (DoubleValue)Results[DifferenceToBestKnownHypervolumeResultName].Value; }
     193            set { Results[DifferenceToBestKnownHypervolumeResultName].Value = value; }
    173194        }
    174195
     
    250271            Results.Add(new Result(GenerationalDistanceResultName, "The generational distance to an optimal pareto front defined in the Problem", new DoubleValue(double.NaN)));
    251272            Results.Add(new Result(InvertedGenerationalDistanceResultName, "The inverted generational distance to an optimal pareto front defined in the Problem", new DoubleValue(double.NaN)));
     273            Results.Add(new Result(HypervolumeResultName, "The hypervolume of the current front considering the Reference point defined in the Problem", new DoubleValue(double.NaN)));
     274            Results.Add(new Result(BestKnownHypervolumeResultName, "The best known hypervolume considering the Reference point defined in the Problem", new DoubleValue(double.NaN)));
     275            Results.Add(new Result(DifferenceToBestKnownHypervolumeResultName, "The difference between the current and the best known hypervolume", new DoubleValue(double.NaN)));
    252276            Results.Add(new Result(ScatterPlotResultName, "A scatterplot displaying the evaluated solutions and (if available) the analytically optimal front", new ParetoFrontScatterPlot()));
    253277            Results.Add(new Result(CurrentFrontResultName, "The Pareto Front", new DoubleMatrix()));
     
    256280            // todo: add BestKnownFront parameter
    257281            ResultsScatterPlot = new ParetoFrontScatterPlot(new double[0][], new double[0][], problem.BestKnownFront.ToJaggedArray(), problem.Objectives, problem.ProblemSize);
     282            ResultsBestKnownHypervolume = new DoubleValue(Hypervolume.Calculate(problem.BestKnownFront.ToJaggedArray(), problem.ReferencePoint.CloneAsArray(), problem.Maximization));
    258283        }
    259284
     
    262287            random = new MersenneTwister();
    263288            solutions = GetInitialPopulation();
    264             InitReferencePoints();
    265         }
    266 
    267         private void InitReferencePoints()
    268         {
    269             // Generate reference points and add them to results
    270289            referencePoints = ReferencePoint.GenerateReferencePoints(random, NumberOfObjectives);
    271290            ResultsGeneratedReferencePoints = Utility.ConvertToDoubleMatrix(referencePoints);
     
    348367            if (!(Problem is MultiObjectiveTestFunctionProblem problem)) return;
    349368
     369            // Indicators
    350370            ResultsGenerationalDistance = new DoubleValue(problem.BestKnownFront != null ? GenerationalDistance.Calculate(solutions.Select(s => s.Fitness), problem.BestKnownFront.ToJaggedArray(), 1) : double.NaN);
    351371            ResultsInvertedGenerationalDistance = new DoubleValue(problem.BestKnownFront != null ? InvertedGenerationalDistance.Calculate(solutions.Select(s => s.Fitness), problem.BestKnownFront.ToJaggedArray(), 1) : double.NaN);
     372
     373            var front = NonDominatedSelect.GetDominatingVectors(solutions.Select(x => x.Fitness), problem.ReferencePoint.CloneAsArray(), Problem.Maximization, true).ToArray();
     374            if (front.Length == 0) return;
     375            ResultsHypervolume = new DoubleValue(Hypervolume.Calculate(front, problem.ReferencePoint.CloneAsArray(), problem.Maximization));
     376            ResultsDifferenceToBestKnownHypervolume = new DoubleValue(ResultsBestKnownHypervolume.Value - ResultsHypervolume.Value);
    352377
    353378            Problem.Analyze(
Note: See TracChangeset for help on using the changeset viewer.