Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10127 for branches


Ignore:
Timestamp:
11/11/13 22:41:09 (11 years ago)
Author:
ascheibe
Message:

#1886 fixed a bug in metric mds and added another unit test

Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior
Files:
2 edited

Legend:

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

    r10118 r10127  
    212212    }
    213213
     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
    214260    private static double[][] StaticPermutationDM() {
    215261      double[][] dm = new double[15][];
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DistanceMatrixToPoints.cs

    r10112 r10127  
    154154      }
    155155
    156       double k1 = SumIfLZero(ev);
     156      int k1 = SumIfLZero(ev);
    157157      if (k1 < k) {
    158158        throw new Exception("Zero-eigenvalues detected. This leads to a degenerate point set. Use constants. ");
    159         //TODO: handling of this case; implement adding of constants
    160159      }
    161160
     
    227226    }
    228227
    229     private static double SumIfLZero(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));
    231230    }
    232231
Note: See TracChangeset for help on using the changeset viewer.