Changeset 10097
- Timestamp:
- 10/30/13 21:49:27 (11 years ago)
- 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 54 54 //calculates the volume of a convex d-polytope 55 55 //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); 58 58 double volume = 0.0; 59 59 60 for (int i = 0; i < hyperHull.Count - 1; i += 2) {60 for (int i = 0; i < convexHull.Count - 1; i += 2) { 61 61 List<double[]> simplex = new List<double[]>(); 62 62 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]); 65 65 volume += CalculateSimplexVolume(simplex); 66 66 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DistanceMatrixToPoints.cs
r10078 r10097 61 61 int pi = 0; 62 62 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) { 64 129 for (int j = 0; j < dm.Length; j++) { 65 130 points[j][pi] = Math.Sqrt(q[i]) * v[j, i];
Note: See TracChangeset
for help on using the changeset viewer.