Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/05/13 23:04:16 (11 years ago)
Author:
ascheibe
Message:

#1886 fixed metric MDS and updated unit test

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

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/AlgorithmBehaviorUnitTests.csproj

    r10104 r10108  
    3636  </PropertyGroup>
    3737  <ItemGroup>
     38    <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     39      <SpecificVersion>False</SpecificVersion>
     40      <HintPath>..\..\..\trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath>
     41    </Reference>
    3842    <Reference Include="HeuristicLab.Common-3.3">
    3943      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/DistanceMatrixToPointsTest.cs

    r10078 r10108  
    2222using System;
    2323using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
     24using HeuristicLab.Common;
    2425using Microsoft.VisualStudio.TestTools.UnitTesting;
    2526
     
    2829  public class DistanceMatrixToPointsTest {
    2930    [TestMethod]
    30     public void TestDistanceMatrixConversion() {
    31       int nrOfPoints = 4;
     31    public void TestDistanceMatrixConversionStatic() {
     32      int nrOfPoints = 3;
    3233      int dim = 2;
    3334      double[][] orgPoints = new double[nrOfPoints][];
     
    3637      double[][] newPoints = null;
    3738
    38 
    3939      AllocArray(orgPoints, dim);
    4040      AllocArray(orgDm, nrOfPoints);
    4141      AllocArray(newDm, nrOfPoints);
    42       SamplePoints(orgPoints);
     42      //SamplePoints(orgPoints);
     43      StaticPoints(orgPoints);
    4344      CalculateDistanceMatrix(orgDm, orgPoints);
    4445
    45       newPoints = DistanceMatrixToPoints.ConvertDistanceMatrixToPoints(orgDm);
     46      newPoints = DistanceMatrixToPoints.MetricMDS(orgDm);
    4647
    4748      CalculateDistanceMatrix(newDm, newPoints);
    48       //TODO
     49      Console.WriteLine("orgDm:");
     50      PrintDM(orgDm);
     51      Console.WriteLine("newDm:");
     52      PrintDM(newDm);
    4953
     54      for (int i = 0; i < orgDm.Length; i++) {
     55        for (int j = 0; j < orgDm.Length; j++) {
     56          double diff = orgDm[i][j] - newDm[i][j];
     57          Assert.IsTrue(diff.IsAlmost(0.0));
     58        }
     59      }
     60    }
     61
     62    private static void PrintDM(double[][] dm) {
     63      for (int i = 0; i < dm.Length; i++) {
     64        for (int j = 0; j < dm.Length; j++) {
     65          Console.Write(dm[i][j] + " ");
     66        }
     67        Console.WriteLine();
     68      }
    5069    }
    5170
     
    6079    }
    6180
     81    private static void StaticPoints(double[][] points) {
     82      points[0][0] = 2;
     83      points[0][1] = 1;
     84
     85      points[1][0] = 5;
     86      points[1][1] = 5;
     87
     88      points[2][0] = 3;
     89      points[2][1] = 7;
     90    }
     91
    6292    private static void CalculateDistanceMatrix(double[][] dm, double[][] points) {
    6393      for (int i = 0; i < points.Length; i++) {
    6494        for (int j = 0; j < points.Length; j++) {
    65           dm[i][j] = CalcEuclideanDistance(points[i], points[j]);
     95          dm[i][j] = points[i].EuclideanDistance(points[j]);
    6696        }
    6797      }
    68     }
    69 
    70     private static double CalcEuclideanDistance(double[] p1, double[] p2) {
    71       double result = 0.0;
    72       for (int i = 0; i < p1.Length; i++) {
    73         result += Math.Pow(p1[i] - p2[i], 2);
    74       }
    75       return Math.Sqrt(result);
    7698    }
    7799
Note: See TracChangeset for help on using the changeset viewer.