コード例 #1
0
    public void TestPartialMatchGenomes()
    {
        var connGenes1 = new ConnectionGenes <double>(5);

        connGenes1[0] = (0, 10, 1.0);
        connGenes1[1] = (1, 11, 2.0);
        connGenes1[2] = (2, 12, 3.0);
        connGenes1[3] = (3, 13, 4.0);
        connGenes1[4] = (4, 14, 5.0);

        var connGenes2 = new ConnectionGenes <double>(5);

        connGenes2[0] = (0, 10, 1.0);
        connGenes2[1] = (3, 13, 4.0);
        connGenes2[2] = (100, 11, 2.0);
        connGenes2[3] = (200, 12, 3.0);
        connGenes2[4] = (400, 14, 5.0);

        var distanceMetric = new ManhattanDistanceMetric();

        // GetDistance() tests.
        Assert.Equal(20, distanceMetric.CalcDistance(connGenes1, connGenes2));
        Assert.Equal(20, distanceMetric.CalcDistance(connGenes2, connGenes1));

        // TestDistance() tests.
        Assert.True(distanceMetric.TestDistance(connGenes1, connGenes2, 20 + 0.001));
        Assert.False(distanceMetric.TestDistance(connGenes1, connGenes2, 20 - 0.001));
    }
コード例 #2
0
    public void TestPythagoras()
    {
        var connGenes1 = new ConnectionGenes <double>(2);

        connGenes1[0] = (0, 3, 0.0);
        connGenes1[1] = (0, 4, 0.0);

        var connGenes2 = new ConnectionGenes <double>(2);

        connGenes2[0] = (0, 3, 3.0);
        connGenes2[1] = (0, 4, 4.0);

        var distanceMetric = new ManhattanDistanceMetric();

        // GetDistance() tests.
        Assert.Equal(7.0, distanceMetric.CalcDistance(connGenes1, connGenes2));
        Assert.Equal(7.0, distanceMetric.CalcDistance(connGenes2, connGenes1));

        // TestDistance() tests.
        Assert.True(distanceMetric.TestDistance(connGenes1, connGenes2, 7.01));
        Assert.False(distanceMetric.TestDistance(connGenes1, connGenes2, 7.0));
        Assert.False(distanceMetric.TestDistance(connGenes1, connGenes2, 1.0));
        Assert.False(distanceMetric.TestDistance(connGenes1, connGenes2, 0.0));

        Assert.True(distanceMetric.TestDistance(connGenes2, connGenes1, 7.01));
        Assert.False(distanceMetric.TestDistance(connGenes2, connGenes1, 7.0));
        Assert.False(distanceMetric.TestDistance(connGenes2, connGenes1, 1.0));
        Assert.False(distanceMetric.TestDistance(connGenes2, connGenes1, 0.0));
    }
コード例 #3
0
        public void TestMatchingGenomes()
        {
            var connGenes1 = new ConnectionGenes <double>(5);

            connGenes1[0] = (0, 10, 1.0);
            connGenes1[1] = (1, 11, 2.0);
            connGenes1[2] = (2, 12, 3.0);
            connGenes1[3] = (3, 13, 4.0);
            connGenes1[4] = (4, 14, 5.0);

            var connGenes2 = new ConnectionGenes <double>(5);

            connGenes2[0] = (0, 10, 1.0);
            connGenes2[1] = (1, 11, 2.0);
            connGenes2[2] = (2, 12, 3.0);
            connGenes2[3] = (3, 13, 4.0);
            connGenes2[4] = (4, 14, 5.0);

            var distanceMetric = new ManhattanDistanceMetric();;

            // GetDistance() tests.
            Assert.AreEqual(0.0, distanceMetric.CalcDistance(connGenes1, connGenes2));
            Assert.AreEqual(0.0, distanceMetric.CalcDistance(connGenes2, connGenes1));

            // TestDistance() tests.
            Assert.IsTrue(distanceMetric.TestDistance(connGenes1, connGenes2, 1.0));
            Assert.IsTrue(distanceMetric.TestDistance(connGenes1, connGenes2, 0.001));
            Assert.IsFalse(distanceMetric.TestDistance(connGenes1, connGenes2, 0.0));

            Assert.IsTrue(distanceMetric.TestDistance(connGenes2, connGenes1, 5.0));
            Assert.IsTrue(distanceMetric.TestDistance(connGenes2, connGenes1, 0.001));
            Assert.IsFalse(distanceMetric.TestDistance(connGenes2, connGenes1, 0.0));
        }