Changeset 10077
- Timestamp:
- 10/21/13 23:43:43 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DistanceMatrixToPoints.cs
r10060 r10077 21 21 22 22 using System; 23 using System.Linq; 24 using HeuristicLab.Common; 23 25 24 26 namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers { … … 33 35 public static double[][] ConvertDistanceMatrixToPoints(double[][] dm) { 34 36 double[][] points = new double[dm.Length][]; 35 for (int i = 0; i < dm.Length; i++) {36 points[i] = new double[dm.Length];37 }38 37 double[,] m = new double[dm.Length, dm.Length]; 39 38 double[] q = new double[dm.Length]; //eigenvalues 40 double[,] v = new double[dm.Length, dm.Length]; 39 double[,] v = new double[dm.Length, dm.Length]; //eigenvectors 41 40 42 41 for (int i = 0; i < dm.Length; i++) { … … 46 45 } 47 46 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); 49 54 if (!res) throw new Exception("Eigenvalue computation did not converge!"); 50 55 56 int zeroCnt = q.Count(x => x.IsAlmost(0)); 51 57 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++; 54 68 } 55 69 }
Note: See TracChangeset
for help on using the changeset viewer.