Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Comparators/Spacing.cs @ 13620

Last change on this file since 13620 was 13620, checked in by bwerth, 8 years ago

#1087 regorganized testfunctions, added view for qualities

File size: 1.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using HeuristicLab.Common;
4using HeuristicLab.Encodings.RealVectorEncoding;
5using HeuristicLab.Problems.MultiObjectiveTestFunctions.Comparators;
6
7namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
8
9
10  /// <summary>
11  /// Spacing is defined as the standarddeviation of all d[i]
12  /// where d[i] is the minimum eukildean distance any point has
13  /// to all OTHER points in the same front
14  /// </summary>
15  public class Spacing : IMultiObjectiveDistance {
16
17    public Spacing() { }
18
19
20    public static double GetSpacing(IEnumerable<double[]> front) {
21      return new Spacing().Get(front);
22    }
23    public static double GetDistance(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront) {
24      return new Spacing().Get(front);
25    }
26
27    public double Compare(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront) {
28      return GetSpacing(front) - GetSpacing(optimalFront);
29    }
30
31    public double Get(IEnumerable<double[]> front) {
32      //TODO build a kd-tree, sort the array, do someting intelligent here
33      if (front == null) throw new ArgumentException("Fronts must not be null");
34      List<double> d = new List<double>();
35      foreach (double[] r in front) {
36        double dist = Utilities.minDistance(r, front, false);
37        d.Add(dist>=0?dist:0);
38      }
39      int n = d.Count;
40      if (n == 0) throw new ArgumentException("Fronts must not be empty");
41      return Math.Sqrt(d.Variance()*(n-1)/n);
42
43    }
44
45  }
46}
Note: See TracBrowser for help on using the repository browser.