Changeset 13620 for branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Comparators/Spacing.cs
- Timestamp:
- 02/15/16 17:19:34 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Comparators/Spacing.cs
r13562 r13620 1 1 using System; 2 using System.Collections.Generic; 3 using HeuristicLab.Common; 2 4 using HeuristicLab.Encodings.RealVectorEncoding; 5 using HeuristicLab.Problems.MultiObjectiveTestFunctions.Comparators; 3 6 4 7 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { … … 15 18 16 19 17 public static double GetSpacing( RealVector[]front) {20 public static double GetSpacing(IEnumerable<double[]> front) { 18 21 return new Spacing().Get(front); 19 22 } 20 public static double GetDistance( RealVector[] front, RealVector[]optimalFront) {23 public static double GetDistance(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront) { 21 24 return new Spacing().Get(front); 22 25 } 23 26 24 public double Compare( RealVector[] front, RealVector[]optimalFront) {27 public double Compare(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront) { 25 28 return GetSpacing(front) - GetSpacing(optimalFront); 26 29 } 27 30 28 public double Get( RealVector[]front) {31 public double Get(IEnumerable<double[]> front) { 29 32 //TODO build a kd-tree, sort the array, do someting intelligent here 30 double sum = 0; 31 if (front.Length == 0) throw new Exception("Front does not contain any points"); 32 double[] d = new double[front.Length]; 33 int i = 0; 34 foreach (RealVector r in front) { 35 d[i] = minDistance(r, front); 36 sum += d[i++]; 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); 37 42 38 }39 double mean = sum / front.Length;40 sum = 0;41 foreach (double e in d) {42 sum += (e - mean) * (e - mean);43 }44 sum /= front.Length;45 return Math.Sqrt(sum);46 47 }48 49 private double minDistance(RealVector point, RealVector[] list) {50 //TODO inefficient51 double min = Double.MaxValue;52 foreach (RealVector r in list) {53 if (r == point) continue;54 double d = 0;55 for (int i = 0; i < r.Length; i++) {56 d += (point[i] - r[i]) * (point[i] - r[i]);57 }58 min = Math.Min(d, min);59 }60 return Math.Sqrt(min);61 43 } 62 44
Note: See TracChangeset
for help on using the changeset viewer.