Changeset 10274 for branches/HeuristicLab.Analysis.AlgorithmBehavior
- Timestamp:
- 01/03/14 01:17:02 (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
r10272 r10274 89 89 return result; 90 90 } 91 92 public static double[] CalculateCentroid(List<double[]> convexHull) { 93 int n = convexHull.Count; 94 int dim = convexHull.First().Length; 95 double[] centroid = new double[dim]; 96 97 for (int i = 0; i < dim; i++) { 98 for (int j = 0; j < n; j++) { 99 centroid[i] += convexHull[j][i]; 100 } 101 centroid[i] /= n; 102 } 103 return centroid; 104 } 105 106 //measures to calculate: AVG, SUM, STD.DEV 107 public static double[] CalculateMovementDistances(List<double[]> centroids) { 108 double[] distances = new double[centroids.Count - 1]; 109 110 // it is assumed that the centroids are sorted chronological 111 for (int i = 0; i < centroids.Count - 1; i++) { 112 distances[i] = centroids[i].EuclideanDistance(centroids[i + 1]); 113 } 114 115 return distances; 116 } 117 118 public static double CalculateOverallMovementDistances(List<double[]> centroids) { 119 // it is assumed that the centroids are sorted chronological 120 return centroids[0].EuclideanDistance(centroids[centroids.Count - 1]); 121 } 122 123 //calculate theta from two vectors (dot product) 124 public static double CalculateTheta(double[] a, double[] b) { 125 return Math.Acos(a.DotProduct(b) / (a.EuclideanNorm() * b.EuclideanNorm())); 126 } 127 128 //calculate theta using law of cosines 129 public static double CalculateTheta(double[] a, double[] b, double[] c) { 130 double ab = a.EuclideanDistance(b); 131 double bc = b.EuclideanDistance(c); 132 double ca = c.EuclideanDistance(a); 133 134 return Math.Acos((ab * ab + bc * bc - ca * ca) / (2 * ab * bc)); 135 } 136 137 //measures to calculate: AVG, SUM, STD.DEV 138 public static double[] CalculateCentroidsMotion(List<double[]> centroids) { 139 double[] thetas = new double[centroids.Count - 2]; 140 141 for (int i = 1; i < centroids.Count - 1; i++) { 142 thetas[i - 1] = CalculateTheta(centroids[i - 1], centroids[i], centroids[i + 1]); 143 } 144 145 return thetas; 146 } 91 147 } 92 148 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DoubleArrayExtensions.cs
r10092 r10274 31 31 return Math.Sqrt(result); 32 32 } 33 34 public static double EuclideanNorm(this double[] p) { 35 double norm = 0.0; 36 for (int i = 0; i < p.Length; i++) { 37 norm += p[i] * p[i]; 38 } 39 return Math.Sqrt(norm); 40 } 41 42 public static double DotProduct(this double[] p1, double[] p2) { 43 double sum = 0.0; 44 for (int i = 0; i < p1.Length; i++) { 45 sum += p1[i] * p2[i]; 46 } 47 return sum; 48 } 33 49 } 34 50 }
Note: See TracChangeset
for help on using the changeset viewer.