Changeset 10118
- Timestamp:
- 11/10/13 21:55:56 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/DistanceMatrixToPointsTest.cs
r10109 r10118 45 45 CalculateDistanceMatrix(orgDm, orgPoints); 46 46 47 newPoints = DistanceMatrixToPoints.MetricMDS(orgDm );47 newPoints = DistanceMatrixToPoints.MetricMDS(orgDm, dim, true); 48 48 49 49 CalculateDistanceMatrix(newDm, newPoints); … … 156 156 [TestMethod] 157 157 public void TestMetricMDSForPermutations() { 158 int nrOfPoints = 30;159 int dim = 20;158 int nrOfPoints = 10; 159 int dim = 5; 160 160 Permutation[] orgPoints = new Permutation[nrOfPoints]; 161 161 double[][] orgDm; … … 168 168 orgDm = CalculateDistanceMatrixFromPermutations(orgPoints); 169 169 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 = orgDm[i][j] - newDm[i][j]; 181 Assert.IsTrue(diff.IsAlmost(0.0)); 182 } 183 } 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]; 181 Assert.IsTrue(diff.IsAlmost(0.0)); 182 } 183 } 184 } 185 186 [TestMethod] 187 public void TestMetricMDSForPermutationsStatic() { 188 int nrOfPoints = 15; 189 int dim = 5; 190 191 double[][] orgDm = StaticPermutationDM(); 192 double[][] newDm = new double[nrOfPoints][]; 193 double[][] newPoints = null; 194 195 AllocArray(newDm, nrOfPoints); 196 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]); 208 if (diff < 0.000001) diff = 0.0; 209 Assert.IsTrue(diff.IsAlmost(0.0)); 210 } 211 } 212 } 213 214 private static double[][] StaticPermutationDM() { 215 double[][] dm = new double[15][]; 216 AllocArray(dm, 15); 217 218 dm[0] = new[] { 219 0, 1.09544511501033, 1.09544511501033, 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 220 0, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 221 1.4142135623731, 0.894427190999916 }; 222 dm[1] = new[] 223 { 224 1.09544511501033, 0, 1.09544511501033, 0.894427190999916, 0.894427190999916, 0.894427190999916, 0.894427190999916, 225 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 226 0.894427190999916, 0.894427190999916 227 }; 228 dm[2] = new[] 229 { 230 1.09544511501033, 1.09544511501033, 0, 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.4142135623731, 231 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 0.894427190999916, 232 0.894427190999916 233 }; 234 dm[3] = new[] 235 { 236 0.894427190999916, 0.894427190999916, 0.894427190999916, 0, 1.09544511501033, 1.09544511501033, 1.09544511501033, 237 0.894427190999916, 1.4142135623731, 0.894427190999916, 0.894427190999916, 0.894427190999916, 0.894427190999916, 238 1.09544511501033, 1.09544511501033 239 }; 240 dm[4] = new[] 241 { 242 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 243 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 0.894427190999916, 1.4142135623731, 244 1.09544511501033, 0 245 }; 246 dm[5] = new[] 247 { 248 1.4142135623731, 0.894427190999916, 0.894427190999916, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 249 1.4142135623731, 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 0.894427190999916, 0, 250 1.09544511501033 251 }; 252 dm[6] = new[] 253 { 254 0.894427190999916, 0.894427190999916, 1.4142135623731, 1.09544511501033, 1.09544511501033, 1.09544511501033, 0, 255 0.894427190999916, 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 256 1.09544511501033, 1.09544511501033 257 }; 258 dm[7] = new[] 259 { 260 0, 1.09544511501033, 1.09544511501033, 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 261 0, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 1.4142135623731, 0.894427190999916 262 }; 263 dm[8] = new[] 264 { 265 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.4142135623731, 0.894427190999916, 0.894427190999916, 266 0.894427190999916, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 267 0.894427190999916, 0.894427190999916 268 }; 269 dm[9] = new[] 270 { 271 1.09544511501033, 1.09544511501033, 1.09544511501033, 0.894427190999916, 1.4142135623731, 0.894427190999916, 272 0.894427190999916, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 0, 273 0.894427190999916, 1.4142135623731 274 }; 275 dm[10] = new[] 276 { 277 0, 1.09544511501033, 1.09544511501033, 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 278 0, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 1.4142135623731, 0.894427190999916 279 }; 280 dm[11] = new[] 281 { 282 1.09544511501033, 1.09544511501033, 0, 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.4142135623731, 283 1.09544511501033, 1.09544511501033, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 0.894427190999916, 284 0.894427190999916 285 }; 286 dm[12] = new[] 287 { 288 1.09544511501033, 1.09544511501033, 1.09544511501033, 0.894427190999916, 1.4142135623731, 0.894427190999916, 289 0.894427190999916, 1.09544511501033, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 0, 290 0.894427190999916, 1.4142135623731 291 }; 292 dm[13] = new[] 293 { 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 297 }; 298 dm[14] = new[] 299 { 300 0.894427190999916, 0.894427190999916, 0.894427190999916, 1.09544511501033, 0, 1.09544511501033, 1.09544511501033, 301 0.894427190999916, 0.894427190999916, 1.4142135623731, 0.894427190999916, 0.894427190999916, 1.4142135623731, 302 1.09544511501033, 0 303 }; 304 return dm; 184 305 } 185 306
Note: See TracChangeset
for help on using the changeset viewer.