Changeset 10132
- Timestamp:
- 11/13/13 10:46:32 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/DistanceMatrixToPointsTest.cs
r10127 r10132 156 156 [TestMethod] 157 157 public void TestMetricMDSForPermutations() { 158 int nrOfPoints = 10;158 int nrOfPoints = 30; 159 159 int dim = 5; 160 160 Permutation[] orgPoints = new Permutation[nrOfPoints]; … … 168 168 orgDm = CalculateDistanceMatrixFromPermutations(orgPoints); 169 169 170 newPoints = DistanceMatrixToPoints.MetricMDS(orgDm, dim, true); 171 172 CalculateDistanceMatrix(newDm, newPoints); 173 Console.WriteLine("orgDm:"); 174 PrintDM(orgDm); 175 Console.WriteLine("newDm:"); 176 PrintDM(newDm); 177 178 for (int i = 0; i < orgDm.Length; i++) { 179 for (int j = 0; j < orgDm.Length; j++) { 180 double diff = orgDm[i][j] - newDm[i][j]; 170 newPoints = DistanceMatrixToPoints.MetricMDS(orgDm, dim); 171 172 CalculateDistanceMatrix(newDm, newPoints); 173 Console.WriteLine("orgDm:"); 174 PrintDM(orgDm); 175 Console.WriteLine("newDm:"); 176 PrintDM(newDm); 177 178 for (int i = 0; i < orgDm.Length; i++) { 179 for (int j = 0; j < orgDm.Length; j++) { 180 double diff = Math.Abs(orgDm[i][j] - newDm[i][j]); 181 if (diff < 0.0000001) diff = 0.0; 181 182 Assert.IsTrue(diff.IsAlmost(0.0)); 182 183 } … … 186 187 [TestMethod] 187 188 public void TestMetricMDSForPermutationsStatic() { 188 int nrOfPoints = 1 5;189 int nrOfPoints = 10; 189 190 int dim = 5; 190 191 … … 195 196 AllocArray(newDm, nrOfPoints); 196 197 197 newPoints = DistanceMatrixToPoints.MetricMDS(orgDm, dim, true); 198 199 CalculateDistanceMatrix(newDm, newPoints); 200 Console.WriteLine("orgDm:"); 201 PrintDM(orgDm); 202 Console.WriteLine("newDm:"); 203 PrintDM(newDm); 204 205 for (int i = 0; i < orgDm.Length; i++) { 206 for (int j = 0; j < orgDm.Length; j++) { 207 double diff = Math.Abs(orgDm[i][j] - newDm[i][j]); 198 newPoints = DistanceMatrixToPoints.MetricMDS(orgDm, dim, false); 199 200 CalculateDistanceMatrix(newDm, newPoints); 201 Console.WriteLine("orgDm:"); 202 PrintDM(orgDm); 203 Console.WriteLine("newDm:"); 204 PrintDM(newDm); 205 206 double[][] resultDMFromR = StaticPermutationDMResult(); 207 208 for (int i = 0; i < orgDm.Length; i++) { 209 for (int j = 0; j < orgDm.Length; j++) { 210 double diff = Math.Abs(resultDMFromR[i][j] - Math.Round(newDm[i][j], 7)); 208 211 if (diff < 0.000001) diff = 0.0; 212 Assert.IsTrue(diff.IsAlmost(0.0)); 213 214 diff = Math.Abs(orgDm[i][j] - newDm[i][j]); 215 if (diff < 0.00000001) diff = 0.0; 209 216 Assert.IsTrue(diff.IsAlmost(0.0)); 210 217 } … … 230 237 PrintDM(orgDm); 231 238 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]; 239 newPoints = DistanceMatrixToPoints.MetricMDS(orgDm, dim, false); 240 241 CalculateDistanceMatrix(newDm, newPoints); 242 Console.WriteLine("newDm:"); 243 PrintDM(newDm); 244 245 for (int i = 0; i < orgDm.Length; i++) { 246 for (int j = 0; j < orgDm.Length; j++) { 247 double diff = Math.Abs(orgDm[i][j] - newDm[i][j]); 248 if (diff < 0.00000001) diff = 0.0; 241 249 Assert.IsTrue(diff.IsAlmost(0.0)); 242 250 } … … 259 267 260 268 private static double[][] StaticPermutationDM() { 261 double[][] dm = new double[15][]; 262 AllocArray(dm, 15); 263 264 dm[0] = new[] { 265 0, 1.09544511501033, 1.09544511501033, 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 266 0, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 267 1.4142135623731, 0.894427190999916 }; 269 double[][] dm = new double[10][]; 270 AllocArray(dm, 10); 271 272 dm[0] = new[] 273 { 274 0, 1.09544511501033, 1.09544511501033, 0.894427190999916, 0.894427190999916, 1.09544511501033, 0.894427190999916, 275 1.09544511501033, 0.894427190999916, 0.894427190999916 276 }; 268 277 dm[1] = new[] 269 278 { 270 1.09544511501033, 0, 1.09544511501033, 0.894427190999916, 0.894427190999916, 0.894427190999916, 0.894427190999916, 271 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 272 0.894427190999916, 0.894427190999916 279 1.09544511501033, 0, 1.09544511501033, 1.4142135623731, 0.894427190999916, 1.09544511501033, 0.894427190999916, 280 1.09544511501033, 0.894427190999916, 0.894427190999916 273 281 }; 274 282 dm[2] = new[] 275 283 { 276 1.09544511501033, 1.09544511501033, 0, 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.4142135623731, 277 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 0.894427190999916, 278 0.894427190999916 284 1.09544511501033, 1.09544511501033, 0, 0.894427190999916, 0.894427190999916, 1.09544511501033, 0.894427190999916, 285 1.09544511501033, 0.894427190999916, 0.894427190999916 279 286 }; 280 287 dm[3] = new[] 281 288 { 282 0.894427190999916, 0.894427190999916, 0.894427190999916, 0, 1.09544511501033, 1.09544511501033, 1.09544511501033, 283 0.894427190999916, 1.4142135623731, 0.894427190999916, 0.894427190999916, 0.894427190999916, 0.894427190999916, 284 1.09544511501033, 1.09544511501033 289 0.894427190999916, 1.4142135623731, 0.894427190999916, 0, 1.09544511501033, 0.894427190999916, 1.09544511501033, 290 0.894427190999916, 1.09544511501033, 1.09544511501033 285 291 }; 286 292 dm[4] = new[] 287 293 { 288 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 289 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 0.894427190999916, 1.4142135623731, 290 1.09544511501033, 0 294 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.09544511501033, 0, 0.894427190999916, 0, 295 0.894427190999916, 1.09544511501033, 1.09544511501033 291 296 }; 292 297 dm[5] = new[] 293 298 { 294 1.4142135623731, 0.894427190999916, 0.894427190999916, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 295 1.4142135623731, 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 0.894427190999916, 0, 296 1.09544511501033 299 1.09544511501033, 1.09544511501033, 1.09544511501033, 0.894427190999916, 0.894427190999916, 0, 0.894427190999916, 300 1.09544511501033, 0.894427190999916, 1.4142135623731 297 301 }; 298 302 dm[6] = new[] 299 303 { 300 0.894427190999916, 0.894427190999916, 1.4142135623731, 1.09544511501033, 1.09544511501033, 1.09544511501033, 0, 301 0.894427190999916, 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 302 1.09544511501033, 1.09544511501033 304 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.09544511501033, 0, 0.894427190999916, 0, 305 0.894427190999916, 1.09544511501033, 1.09544511501033 303 306 }; 304 307 dm[7] = new[] 305 308 { 306 0, 1.09544511501033, 1.09544511501033, 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916,307 0 , 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 1.4142135623731, 0.894427190999916309 1.09544511501033, 1.09544511501033, 1.09544511501033, 0.894427190999916, 0.894427190999916, 1.09544511501033, 310 0.894427190999916, 0, 1.4142135623731, 0.894427190999916 308 311 }; 309 312 dm[8] = new[] 310 313 { 311 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.4142135623731, 0.894427190999916, 0.894427190999916, 312 0.894427190999916, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 313 0.894427190999916, 0.894427190999916 314 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.09544511501033, 1.09544511501033, 0.894427190999916, 315 1.09544511501033, 1.4142135623731, 0, 1.09544511501033 314 316 }; 315 317 dm[9] = new[] 316 318 { 317 1.09544511501033, 1.09544511501033, 1.09544511501033, 0.894427190999916, 1.4142135623731, 0.894427190999916, 318 0.894427190999916, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 0, 319 0.894427190999916, 1.4142135623731 320 }; 321 dm[10] = new[] 322 { 323 0, 1.09544511501033, 1.09544511501033, 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 324 0, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 1.4142135623731, 0.894427190999916 325 }; 326 dm[11] = new[] 327 { 328 1.09544511501033, 1.09544511501033, 0, 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.4142135623731, 329 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 0.894427190999916, 330 0.894427190999916 331 }; 332 dm[12] = new[] 333 { 334 1.09544511501033, 1.09544511501033, 1.09544511501033, 0.894427190999916, 1.4142135623731, 0.894427190999916, 335 0.894427190999916, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 0, 336 0.894427190999916, 1.4142135623731 337 }; 338 dm[13] = new[] 339 { 340 1.4142135623731, 0.894427190999916, 0.894427190999916, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 341 1.4142135623731, 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 0.894427190999916, 0, 342 1.09544511501033 343 }; 344 dm[14] = new[] 345 { 346 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 347 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 0.894427190999916, 1.4142135623731, 348 1.09544511501033, 0 349 }; 319 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.09544511501033, 1.09544511501033, 1.4142135623731, 320 1.09544511501033, 0.894427190999916, 1.09544511501033, 0 321 }; 322 323 return dm; 324 } 325 326 private static double[][] StaticPermutationDMResult() { 327 double[][] dm = new double[10][]; 328 AllocArray(dm, 10); 329 330 dm[0] = new[] 331 { 332 0.0000000,1.0954451,1.0954451,0.8944272,8.944272e-01,1.0954451,8.944272e-01,1.0954451,0.8944272,0.8944272 333 }; 334 dm[1] = new[] 335 { 336 1.0954451,0.0000000,1.0954451,1.4142136,8.944272e-01,1.0954451,8.944272e-01,1.0954451,0.8944272,0.8944272 337 }; 338 dm[2] = new[] 339 { 340 1.0954451,1.0954451,0.0000000,0.8944272,8.944272e-01,1.0954451,8.944272e-01,1.0954451,0.8944272,0.8944272 341 }; 342 dm[3] = new[] 343 { 344 0.8944272,1.4142136,0.8944272,0.0000000,1.095445e+00,0.8944272,1.095445e+00,0.8944272,1.0954451,1.0954451 345 }; 346 dm[4] = new[] 347 { 348 0.8944272,0.8944272,0.8944272,1.0954451,0.000000e+00,0.8944272,4.331115e-16,0.8944272,1.0954451,1.0954451 349 }; 350 dm[5] = new[] 351 { 352 1.0954451,1.0954451,1.0954451,0.8944272,8.944272e-01,0.0000000,8.944272e-01,1.0954451,0.8944272,1.4142136 353 }; 354 dm[6] = new[] 355 { 356 0.8944272,0.8944272,0.8944272,1.0954451,4.331115e-16,0.8944272,0.000000e+00,0.8944272,1.0954451,1.0954451 357 }; 358 dm[7] = new[] 359 { 360 1.0954451,1.0954451,1.0954451,0.8944272,8.944272e-01,1.0954451,8.944272e-01,0.0000000,1.4142136,0.8944272 361 }; 362 dm[8] = new[] 363 { 364 0.8944272,0.8944272,0.8944272,1.0954451,1.095445e+00,0.8944272,1.095445e+00,1.4142136,0.0000000,1.0954451 365 }; 366 dm[9] = new[] 367 { 368 0.8944272,0.8944272,0.8944272,1.0954451,1.095445e+00,1.4142136,1.095445e+00,0.8944272,1.0954451,0.0000000 369 }; 370 350 371 return dm; 351 372 }
Note: See TracChangeset
for help on using the changeset viewer.