Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/12/13 01:06:00 (11 years ago)
Author:
ascheibe
Message:

#1886

  • added more performance tests
  • tried to mute qhull
Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior/PerformanceTests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/PerformanceTests/PerformanceTests.csproj

    r10223 r10224  
    5050      <Name>HeuristicLab.Analysis.AlgorithmBehavior.Analyzers-3.3</Name>
    5151    </ProjectReference>
     52    <ProjectReference Include="..\MIConvexHull\MIConvexHull.csproj">
     53      <Project>{2337776d-7d0c-40aa-a439-c26c3ce24fab}</Project>
     54      <Name>MIConvexHull</Name>
     55    </ProjectReference>
    5256  </ItemGroup>
    5357  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/PerformanceTests/Program.cs

    r10223 r10224  
    2525using System.Linq;
    2626using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
     27using MIConvexHull;
    2728
    2829namespace PerformanceTests {
    2930  class Program {
     31
     32    static int nrOfPoints = 1000;
     33    static int dimension = 10;
     34
    3035    static void Main(string[] args) {
    31       // TestSimpleVolumeCalculation();
    32       // TestVolCalc();
    33       //TestQHullVolumeCalculation();
    34       TestQhull();
     36      //TestConvexHullPerformance();
     37      //TestVolumeCalculationPerformance();
     38
     39      TestMDSPerformance();
    3540    }
    3641
    37     public static void TestQhull() {
    38       var points = new List<double[]>();
    39       points.Add(new double[] { -0.72045174, 1.44667601, -1.75159125 });
    40       points.Add(new double[] { -0.67521503, 0.61127293, -0.33962646 });
    41       points.Add(new double[] { 2.02392510, -0.41962562, -1.12211942 });
    42       points.Add(new double[] { 0.02647963, -0.24983950, -0.47038916 });
    43       points.Add(new double[] { 0.61548803, -0.25039511, 0.97745744 });
    44       points.Add(new double[] { -1.65142294, -0.09537136, 1.93154268 });
    45       points.Add(new double[] { 1.12618422, 0.49384888, 0.05286691 });
    46       points.Add(new double[] { -0.12506782, -2.29161965, -0.09710301 });
     42    public static void TestMDSPerformance() {
     43      double[][] orgPoints = new double[nrOfPoints][];
     44      double[][] orgDm = new double[nrOfPoints][];
     45      double[][] newPoints = null;
     46      Stopwatch watch = new Stopwatch();
    4747
    48       double volume = QhullWrapper.CalculateVolume(points);
    49       volume = Math.Round(volume, 6);
    50       Console.WriteLine("Volume is: " + volume);
     48      AllocArray(orgPoints, dimension);
     49      AllocArray(orgDm, nrOfPoints);
     50      SamplePoints(orgPoints);
     51      CalculateDistanceMatrix(orgDm, orgPoints);
    5152
    52       var result = QhullWrapper.Calculate(points);
     53      watch.Start();
     54      newPoints = DistanceMatrixToPoints.MetricMDS(orgDm, dimension);
     55      watch.Stop();
     56      Console.WriteLine("Runtime of MetricMDS (in sec): " + watch.Elapsed.TotalSeconds);
     57
     58      Console.ReadLine();
    5359    }
    5460
     61    public static void TestConvexHullPerformance() {
     62      List<double[]> result = null;
     63      Stopwatch watch = new Stopwatch();
    5564
    56     public static void TestVolCalc() {
    57       int dim = 3;
    58       int size = 8;
    59       var data = CreateRandomData(size, dim);
     65      var data = CreateRandomData(nrOfPoints, dimension);
    6066      var dataList = data.ToList();
     67
     68      //calculate convex hull with LP
     69      watch.Start();
     70      result = LPHull.Calculate(data);
     71      watch.Stop();
     72      Console.WriteLine("Runtime of LPHull (in sec): " + watch.Elapsed.TotalSeconds);
     73
     74      //calculate convex hull with SMO
     75      watch.Restart();
     76      result = HyperHull.Calculate(data);
     77      watch.Stop();
     78      Console.WriteLine("Runtime of HyperHull (in sec): " + watch.Elapsed.TotalSeconds);
     79
     80      //calculate convex hull with MIConvexHull
     81      watch.Restart();
     82      result = ConvexHull.Create(data).Points.Select(x => x.Position).ToList();
     83      watch.Stop();
     84      Console.WriteLine("Runtime of MIConvexHull (in sec): " + watch.Elapsed.TotalSeconds);
     85
     86      //calculate convex hull with QHull
     87      watch.Restart();
     88      result = QhullWrapper.Calculate(dataList);
     89      watch.Stop();
     90      Console.WriteLine("Runtime of QHull (in sec): " + watch.Elapsed.TotalSeconds);
     91
     92      Console.ReadLine();
     93    }
     94
     95    public static void TestVolumeCalculationPerformance() {
     96      var data = CreateRandomData(nrOfPoints, dimension);
     97      var dataList = data.ToList();
     98      List<double[]> convexHull = null;
     99      double volume = 0.0;
    61100      Stopwatch watch = new Stopwatch();
    62101
    63102
    64       //calculate convex hull
     103      //calculate volume with LP and then use QHull
    65104      watch.Start();
    66       var convexHull = LPHull.Calculate(data);
     105      convexHull = LPHull.Calculate(data);
     106      volume = QhullWrapper.CalculateVolume(convexHull);
    67107      watch.Stop();
    68       Console.WriteLine("Convex hull calculation took : " + watch.Elapsed.TotalSeconds + " seconds.");
     108      Console.WriteLine(Environment.NewLine + "## Runtime of LPHull/QHull (sec): " + watch.Elapsed.TotalSeconds);
     109      //Console.WriteLine("Volume of convex hull is: " + volume);
    69110
     111      //calculate volume with QHull
     112      watch.Restart();
     113      volume = QhullWrapper.CalculateVolume(dataList);
     114      watch.Stop();
     115      Console.WriteLine(Environment.NewLine + "## Runtime of QHull (sec): " + watch.Elapsed.TotalSeconds);
     116      //Console.WriteLine("Volume of convex hull is: " + volume);
    70117
    71       //calculate volume of convex hull
    72       watch.Start();
    73       double volume = ConvexHullMeasures.CalculateVolume(convexHull);
    74       watch.Stop();
    75       Console.WriteLine("Volume calculation of convex hull took : " + watch.Elapsed.TotalSeconds + " seconds.");
    76       Console.WriteLine("Volume of convex hull is: " + volume);
    77 
    78 
    79       //do volume calculation from the whole data set
    80       watch.Start();
     118      //calculate volume of data with delauny triangulation
     119      watch.Restart();
    81120      volume = ConvexHullMeasures.CalculateVolume(dataList);
    82121      watch.Stop();
    83       Console.WriteLine("Volume calculation of whole data set took : " + watch.Elapsed.TotalSeconds + " seconds.");
    84       Console.WriteLine("Volume of whole data is: " + volume);
    85     }
     122      Console.WriteLine(Environment.NewLine + "## Runtime using all data with delauny (sec): " + watch.Elapsed.TotalSeconds);
     123      //Console.WriteLine("Volume of convex hull is: " + volume);
    86124
    87     private static void TestQHullVolumeCalculation() {
    88       const int numPoints = 8;
    89       const int dimension = 3;
     125      //calculate volume with convex hull (LPHull) and delauny triangulation
     126      watch.Restart();
     127      convexHull = LPHull.Calculate(data);
     128      volume = ConvexHullMeasures.CalculateVolume(convexHull);
     129      watch.Stop();
     130      Console.WriteLine(Environment.NewLine + "## Runtime using convex hull and delauny (sec): " + watch.Elapsed.TotalSeconds);
     131      //Console.WriteLine("Volume of convex hull is: " + volume);
    90132
    91       var points = new List<double[]>();
    92 
    93       points.Add(new double[] { -0.72045174, 1.44667601, -1.75159125 });
    94       points.Add(new double[] { -0.67521503, 0.61127293, -0.33962646 });
    95       points.Add(new double[] { 2.02392510, -0.41962562, -1.12211942 });
    96       points.Add(new double[] { 0.02647963, -0.24983950, -0.47038916 });
    97       points.Add(new double[] { 0.61548803, -0.25039511, 0.97745744 });
    98       points.Add(new double[] { -1.65142294, -0.09537136, 1.93154268 });
    99       points.Add(new double[] { 1.12618422, 0.49384888, 0.05286691 });
    100       points.Add(new double[] { -0.12506782, -2.29161965, -0.09710301 });
    101 
    102       Stopwatch watch = new Stopwatch();
    103       //calculate convex hull
    104       watch.Start();
    105       var convexHull = LPHull.Calculate(points.ToArray());
    106       watch.Stop();
    107       Console.WriteLine("Convex hull calculation took : " + watch.Elapsed.TotalSeconds + " seconds.");
    108 
    109 
    110       //calculate volume of convex hull
    111       watch.Start();
    112       double volume = ConvexHullMeasures.CalculateVolume(convexHull);
    113       watch.Stop();
    114       Console.WriteLine("Volume calculation of convex hull took : " + watch.Elapsed.TotalSeconds + " seconds.");
    115       Console.WriteLine("Volume of convex hull is: " + volume);  //7.960698
    116 
    117 
    118       //do volume calculation from the whole data set
    119       watch.Start();
    120       volume = ConvexHullMeasures.CalculateVolume(points);
    121       watch.Stop();
    122       Console.WriteLine("Volume calculation of whole data set took : " + watch.Elapsed.TotalSeconds + " seconds.");
    123       Console.WriteLine("Volume of whole data is: " + volume);
    124     }
    125 
    126     private static void TestSimpleVolumeCalculation() {
    127       const int numPoints = 4;
    128       const int dimension = 3;
    129 
    130       double[] num1 = new double[dimension];
    131       double[] num2 = new double[dimension];
    132       double[] num3 = new double[dimension];
    133       double[] num4 = new double[dimension];
    134 
    135       num1[0] = 1;
    136       num1[1] = 2;
    137       num1[2] = 2;
    138 
    139       num2[0] = 3;
    140       num2[1] = 4;
    141       num2[2] = 3;
    142 
    143       num3[0] = 3;
    144       num3[1] = 6;
    145       num3[2] = 3;
    146 
    147       num4[0] = 7;
    148       num4[1] = 8;
    149       num4[2] = 3;
    150 
    151       var points = new List<double[]>();
    152       points.Add(num1);
    153       points.Add(num2);
    154       points.Add(num3);
    155       points.Add(num4);
    156 
    157 
    158       double volume = ConvexHullMeasures.CalculateSimplexVolume(points);
    159 
     133      Console.ReadLine();
    160134    }
    161135
     
    172146      return result;
    173147    }
     148
     149    private static void CalculateDistanceMatrix(double[][] dm, double[][] points) {
     150      for (int i = 0; i < points.Length; i++) {
     151        for (int j = 0; j < points.Length; j++) {
     152          dm[i][j] = points[i].EuclideanDistance(points[j]);
     153        }
     154      }
     155    }
     156
     157    private static void AllocArray(double[][] arr, int size) {
     158      for (int i = 0; i < arr.Length; i++) {
     159        arr[i] = new double[size];
     160      }
     161    }
     162
     163    private static void SamplePoints(double[][] points) {
     164      Random rand = new Random();
     165
     166      for (int i = 0; i < points.Length; i++) {
     167        for (int j = 0; j < points[i].Length; j++) {
     168          points[i][j] = rand.NextDouble() * 100;
     169        }
     170      }
     171    }
    174172  }
    175173}
Note: See TracChangeset for help on using the changeset viewer.