Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10132


Ignore:
Timestamp:
11/13/13 10:46:32 (11 years ago)
Author:
ascheibe
Message:

#1886 updated unit test to take account for rounding errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/DistanceMatrixToPointsTest.cs

    r10127 r10132  
    156156    [TestMethod]
    157157    public void TestMetricMDSForPermutations() {
    158       int nrOfPoints = 10;
     158      int nrOfPoints = 30;
    159159      int dim = 5;
    160160      Permutation[] orgPoints = new Permutation[nrOfPoints];
     
    168168      orgDm = CalculateDistanceMatrixFromPermutations(orgPoints);
    169169
    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;
    181182          Assert.IsTrue(diff.IsAlmost(0.0));
    182183        }
     
    186187    [TestMethod]
    187188    public void TestMetricMDSForPermutationsStatic() {
    188       int nrOfPoints = 15;
     189      int nrOfPoints = 10;
    189190      int dim = 5;
    190191
     
    195196      AllocArray(newDm, nrOfPoints);
    196197
    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));
    208211          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;
    209216          Assert.IsTrue(diff.IsAlmost(0.0));
    210217        }
     
    230237      PrintDM(orgDm);
    231238
    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;
    241249          Assert.IsTrue(diff.IsAlmost(0.0));
    242250        }
     
    259267
    260268    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      };
    268277      dm[1] = new[]
    269278      {
    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
    273281      };
    274282      dm[2] = new[]
    275283      {
    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
    279286      };
    280287      dm[3] = new[]
    281288      {
    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
    285291      };
    286292      dm[4] = new[]
    287293      {
    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
    291296      };
    292297      dm[5] = new[]
    293298      {
    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
    297301      };
    298302      dm[6] = new[]
    299303      {
    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
    303306      };
    304307      dm[7] = new[]
    305308      {
    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.894427190999916
     309        1.09544511501033, 1.09544511501033, 1.09544511501033, 0.894427190999916, 0.894427190999916, 1.09544511501033,
     310        0.894427190999916, 0, 1.4142135623731, 0.894427190999916
    308311      };
    309312      dm[8] = new[]
    310313      {
    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
    314316      };
    315317      dm[9] = new[]
    316318      {
    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
    350371      return dm;
    351372    }
Note: See TracChangeset for help on using the changeset viewer.