예제 #1
0
        public void TestKmedoidClustering()
        {
            FloatMatrixIndexer data = new FloatMatrixIndexer(new float[, ]
            {
                { 2, 6 }, { 3, 4 }, { 3, 8 }, { 4, 7 }, { 6, 2 }, { 6, 4 }, { 7, 3 }, { 7, 4 }, { 8, 5 }, { 7, 6 }
            });
            GenericDistanceMatrix distance = new GenericDistanceMatrix(data, new L1Distance());

            int[] clustering = KmedoidClustering.GenerateClusters(data, distance, 2);
            Assert.IsTrue(new[] { 0, 0, 0, 0, 7, 7, 7, 7, 7, 7 }.SequenceEqual(clustering));
        }
예제 #2
0
        public void TestGeneralDistanceMatrix()
        {
            var distance       = new EuclideanDistance();
            var distanceMatrix = new GenericDistanceMatrix(new FloatMatrixIndexer(new float[, ] {
                { 0, 0 }, { 1, 0 }, { 3, 0 }
            }), distance);

            Assert.AreEqual(0, distanceMatrix[0, 0]);
            Assert.AreEqual(0, distanceMatrix[2, 2]);
            Assert.AreEqual(distanceMatrix[1, 2], distanceMatrix[2, 1]);
            Assert.AreEqual(1, distanceMatrix[1, 0]);
            Assert.AreEqual(2, distanceMatrix[1, 2]);

            distanceMatrix[0, 1] = -1;
            Assert.AreEqual(-1, distanceMatrix[0, 1]);
        }