Changeset 10109 for branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers
- Timestamp:
- 11/05/13 23:57:18 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DistanceMatrixToPoints.cs
r10108 r10109 33 33 * 34 34 */ 35 public static double[][] ConvertDistanceMatrixToPoints(double[][] dm ) {35 public static double[][] ConvertDistanceMatrixToPoints(double[][] dm, int k = 2) { 36 36 double[][] points = new double[dm.Length][]; 37 37 double[,] m = new double[dm.Length, dm.Length]; … … 45 45 } 46 46 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); 47 bool res = alglib.smatrixevd(m, dm.Length, 1, true, out q, out v); 54 48 if (!res) throw new Exception("Eigenvalue computation did not converge!"); 55 49 56 int zeroCnt = q.Count(x => x.IsAlmost(0) || x < 0.0); 57 for (int i = 0; i < dm.Length; 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.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++; 50 //TODO: this should also work without allocating memory for ev and evec 51 double[] ev = new double[k]; 52 double[][] evec = new double[dm.Length][]; 53 AllocArray(evec, k); 54 Array.Copy(q, q.Length - k, ev, 0, k); 55 for (int i = 0; i < k; i++) { 56 for (int j = 0; j < dm.Length; j++) { 57 evec[j][i] = v[j, i + (q.Length - k)]; 68 58 } 69 59 } 70 60 61 double k1 = SumIfLZero(ev); 62 if (k1 < k) { 63 throw new Exception("Zero-eigenvalues detected. This leads to a degenerate point set. Use constants. "); 64 //TODO: handling of this case; implement adding of constants 65 } 66 67 AllocArray(points, k); 68 for (int i = 0; i < k; i++) { 69 for (int j = 0; j < dm.Length; j++) { 70 points[j][i] = Math.Sqrt(ev[i]) * evec[j][i]; 71 } 72 } 71 73 return points; 72 74 }
Note: See TracChangeset
for help on using the changeset viewer.