Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10077


Ignore:
Timestamp:
10/21/13 23:43:43 (11 years ago)
Author:
ascheibe
Message:

#1886 fixed a bug in the point calculation from distance matrices

File:
1 edited

Legend:

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

    r10060 r10077  
    2121
    2222using System;
     23using System.Linq;
     24using HeuristicLab.Common;
    2325
    2426namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
     
    3335    public static double[][] ConvertDistanceMatrixToPoints(double[][] dm) {
    3436      double[][] points = new double[dm.Length][];
    35       for (int i = 0; i < dm.Length; i++) {
    36         points[i] = new double[dm.Length];
    37       }
    3837      double[,] m = new double[dm.Length, dm.Length];
    3938      double[] q = new double[dm.Length]; //eigenvalues
    40       double[,] v = new double[dm.Length, dm.Length];  //eigenvectors
     39      double[,] v = new double[dm.Length, dm.Length]; //eigenvectors
    4140
    4241      for (int i = 0; i < dm.Length; i++) {
     
    4645      }
    4746
    48       bool res = alglib.smatrixevd(m, dm.Length, 1, true, out q, out v);
     47      //QR decomposition to get the upper part for smatrixevd
     48      double[] tau;
     49      double[,] r;
     50      alglib.rmatrixqr(ref m, dm.Length, dm.Length, out tau);
     51      alglib.rmatrixqrunpackr(m, dm.Length, dm.Length, out r);
     52
     53      bool res = alglib.smatrixevd(r, dm.Length, 1, true, out q, out v);
    4954      if (!res) throw new Exception("Eigenvalue computation did not converge!");
    5055
     56      int zeroCnt = q.Count(x => x.IsAlmost(0));
    5157      for (int i = 0; i < dm.Length; i++) {
    52         for (int j = 0; j < dm.Length; j++) {
    53           points[j][i] = Math.Sqrt(q[i]) * v[j, i];
     58        points[i] = new double[dm.Length - zeroCnt];
     59      }
     60
     61      int pi = 0;
     62      for (int i = 0; i < dm.Length; i++) {
     63        if (q[i].IsAlmost(0)) {
     64          for (int j = 0; j < dm.Length; j++) {
     65            points[j][pi] = Math.Sqrt(q[i]) * v[j, i];
     66          }
     67          pi++;
    5468        }
    5569      }
Note: See TracChangeset for help on using the changeset viewer.