- Timestamp:
- 11/11/13 22:41:09 (11 years ago)
- Location:
- branches/HeuristicLab.Analysis.AlgorithmBehavior
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/DistanceMatrixToPointsTest.cs
r10118 r10127 212 212 } 213 213 214 [TestMethod] 215 public void TestMetricMDSForSmallDistances() { 216 int nrOfPoints = 4; 217 int dim = 2; 218 double[][] orgPoints = new double[nrOfPoints][]; 219 double[][] orgDm = new double[nrOfPoints][]; 220 double[][] newDm = new double[nrOfPoints][]; 221 double[][] newPoints = null; 222 223 AllocArray(orgPoints, dim); 224 AllocArray(orgDm, nrOfPoints); 225 AllocArray(newDm, nrOfPoints); 226 SmallDiffStaticPoints(orgPoints); 227 CalculateDistanceMatrix(orgDm, orgPoints); 228 229 Console.WriteLine("orgDm:"); 230 PrintDM(orgDm); 231 232 newPoints = DistanceMatrixToPoints.MetricMDS(orgDm, dim, true); 233 234 CalculateDistanceMatrix(newDm, newPoints); 235 Console.WriteLine("newDm:"); 236 PrintDM(newDm); 237 238 for (int i = 0; i < orgDm.Length; i++) { 239 for (int j = 0; j < orgDm.Length; j++) { 240 double diff = orgDm[i][j] - newDm[i][j]; 241 Assert.IsTrue(diff.IsAlmost(0.0)); 242 } 243 } 244 } 245 246 private static void SmallDiffStaticPoints(double[][] points) { 247 points[0][0] = 1; 248 points[0][1] = 1; 249 250 points[1][0] = 1.03; 251 points[1][1] = 1.2; 252 253 points[2][0] = 1.05; 254 points[2][1] = 1.01; 255 256 points[3][0] = 1.5; 257 points[3][1] = 1.1; 258 } 259 214 260 private static double[][] StaticPermutationDM() { 215 261 double[][] dm = new double[15][]; -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DistanceMatrixToPoints.cs
r10112 r10127 154 154 } 155 155 156 doublek1 = SumIfLZero(ev);156 int k1 = SumIfLZero(ev); 157 157 if (k1 < k) { 158 158 throw new Exception("Zero-eigenvalues detected. This leads to a degenerate point set. Use constants. "); 159 //TODO: handling of this case; implement adding of constants160 159 } 161 160 … … 227 226 } 228 227 229 private static doubleSumIfLZero(double[] a) {230 return a. Where(x => x > 0.0 && !x.IsAlmost(0.0)).Sum();228 private static int SumIfLZero(double[] a) { 229 return a.Count(x => x > 0.0 && !x.IsAlmost(0.0)); 231 230 } 232 231
Note: See TracChangeset
for help on using the changeset viewer.