Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/30/13 21:49:27 (11 years ago)
Author:
ascheibe
Message:

#1886 added metric mds for testing purposes

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/ConvexHullMeasures.cs

    r10092 r10097  
    5454    //calculates the volume of a convex d-polytope
    5555    //decomposition based on boundary triangulation
    56     public static double CalculateVolume(List<double[]> hyperHull) {
    57       double[] innerPoint = CalculateInnerPoint(hyperHull);
     56    public static double CalculateVolume(List<double[]> convexHull) {
     57      double[] innerPoint = CalculateInnerPoint(convexHull);
    5858      double volume = 0.0;
    5959
    60       for (int i = 0; i < hyperHull.Count - 1; i += 2) {
     60      for (int i = 0; i < convexHull.Count - 1; i += 2) {
    6161        List<double[]> simplex = new List<double[]>();
    6262        simplex.Add(innerPoint);
    63         simplex.Add(hyperHull[i]);
    64         simplex.Add(hyperHull[i + 1]);
     63        simplex.Add(convexHull[i]);
     64        simplex.Add(convexHull[i + 1]);
    6565        volume += CalculateSimplexVolume(simplex);
    6666      }
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DistanceMatrixToPoints.cs

    r10078 r10097  
    6161      int pi = 0;
    6262      for (int i = 0; i < dm.Length; i++) {
    63         if (!q[i].IsAlmost(0) && q[i] > 0.0) {
     63        if (!q[i].IsAlmost(0.0) && q[i] > 0.0) {
     64          for (int j = 0; j < dm.Length; j++) {
     65            points[j][pi] = Math.Sqrt(q[i]) * v[j, i];
     66          }
     67          pi++;
     68        }
     69      }
     70
     71      return points;
     72    }
     73
     74    public static double[][] MetricMDS(double[][] dm) {
     75      double[][] points = new double[dm.Length][];
     76      double[,] a = new double[dm.Length, dm.Length];
     77      double[,] b = new double[dm.Length, dm.Length];
     78      double[] ai = new double[dm.Length];
     79      double[] aj = new double[dm.Length];
     80      double aavg = 0.0;
     81      double[] q = new double[dm.Length];
     82      double[,] v = new double[dm.Length, dm.Length];
     83
     84
     85      for (int i = 0; i < dm.Length; i++) {
     86        for (int j = 0; j < dm.Length; j++) {
     87          a[i, j] = -0.5 * Math.Pow(dm[i][j], 2);
     88          aavg += a[i, j];
     89        }
     90      }
     91
     92      aavg /= dm.Length * dm.Length;
     93
     94      for (int i = 0; i < dm.Length; i++) {
     95        ai[i] = dm[i].Average();
     96      }
     97
     98      for (int i = 0; i < dm.Length; i++) {
     99        for (int j = 0; j < dm.Length; j++) {
     100          aj[i] += dm[j][i];
     101        }
     102        aj[i] /= dm.Length;
     103      }
     104
     105      for (int i = 0; i < dm.Length; i++) {
     106        for (int j = 0; j < dm.Length; j++) {
     107          b[i, j] = a[i, j] - ai[i] - aj[j] + aavg;
     108        }
     109      }
     110
     111      //TODO: check b for negative values and make it positiv
     112
     113      double[] tau;
     114      double[,] r;
     115      alglib.rmatrixqr(ref b, dm.Length, dm.Length, out tau);
     116      alglib.rmatrixqrunpackr(b, dm.Length, dm.Length, out r);
     117
     118      bool res = alglib.smatrixevd(r, dm.Length, 1, true, out q, out v);
     119      if (!res) throw new Exception("Eigenvalue computation did not converge!");
     120
     121      int zeroCnt = q.Count(x => x.IsAlmost(0) || x < 0.0);
     122      for (int i = 0; i < dm.Length; i++) {
     123        points[i] = new double[dm.Length - zeroCnt];
     124      }
     125
     126      int pi = 0;
     127      for (int i = 0; i < dm.Length; i++) {
     128        if (!q[i].IsAlmost(0.0) && q[i] > 0.0) {
    64129          for (int j = 0; j < dm.Length; j++) {
    65130            points[j][pi] = Math.Sqrt(q[i]) * v[j, i];
Note: See TracChangeset for help on using the changeset viewer.