Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/15/16 17:19:34 (8 years ago)
Author:
bwerth
Message:

#1087 regorganized testfunctions, added view for qualities

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Comparators/Spacing.cs

    r13562 r13620  
    11using System;
     2using System.Collections.Generic;
     3using HeuristicLab.Common;
    24using HeuristicLab.Encodings.RealVectorEncoding;
     5using HeuristicLab.Problems.MultiObjectiveTestFunctions.Comparators;
    36
    47namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
     
    1518
    1619
    17     public static double GetSpacing(RealVector[] front) {
     20    public static double GetSpacing(IEnumerable<double[]> front) {
    1821      return new Spacing().Get(front);
    1922    }
    20     public static double GetDistance(RealVector[] front, RealVector[] optimalFront) {
     23    public static double GetDistance(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront) {
    2124      return new Spacing().Get(front);
    2225    }
    2326
    24     public double Compare(RealVector[] front, RealVector[] optimalFront) {
     27    public double Compare(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront) {
    2528      return GetSpacing(front) - GetSpacing(optimalFront);
    2629    }
    2730
    28     public double Get(RealVector[] front) {
     31    public double Get(IEnumerable<double[]> front) {
    2932      //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);
    3742
    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 inefficient
    51       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);
    6143    }
    6244
Note: See TracChangeset for help on using the changeset viewer.