コード例 #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 EuclideanDistanceMetric();

        // GetDistance() tests.
        Assert.Equal(Math.Sqrt(76), distanceMetric.CalcDistance(connGenes1, connGenes2));
        Assert.Equal(Math.Sqrt(76), distanceMetric.CalcDistance(connGenes2, connGenes1));

        // TestDistance() tests.
        Assert.True(distanceMetric.TestDistance(connGenes1, connGenes2, Math.Sqrt(76) + 0.001));
        Assert.False(distanceMetric.TestDistance(connGenes1, connGenes2, Math.Sqrt(76) - 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 EuclideanDistanceMetric();

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

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

        Assert.True(distanceMetric.TestDistance(connGenes2, connGenes1, 5.01));
        Assert.False(distanceMetric.TestDistance(connGenes2, connGenes1, 5.0));
        Assert.False(distanceMetric.TestDistance(connGenes2, connGenes1, 1.0));
        Assert.False(distanceMetric.TestDistance(connGenes2, connGenes1, 0.0));
    }
コード例 #3
0
        public void TestDatasets(string path)
        {
            Console.WriteLine("Test: " + path);
            var features = GetClusterData(Path.Combine(TestPathSingleton.TestDirectory, path));

            Assert.IsNotEmpty(features);

            var cluster = new UMCClusterLight();

            cluster.Id = features[0].Id;
            features.ForEach(x => cluster.AddChildFeature(x));

            var maps = new Dictionary <int, UMCClusterLight>();


            // Map the features
            var mapFeatures = new Dictionary <int, List <UMCLight> >();

            foreach (var feature in features)
            {
                if (!mapFeatures.ContainsKey(feature.GroupId))
                {
                    mapFeatures.Add(feature.GroupId, new List <UMCLight>());
                }
                mapFeatures[feature.GroupId].Add(feature);
            }

            Console.WriteLine("Cluster\tMass\tNET");
            Console.WriteLine("{0}\t{1}\t{2}\t", cluster.Id, cluster.MassStandardDeviation, cluster.NetStandardDeviation);
            Console.WriteLine();

            var distance = new EuclideanDistanceMetric <FeatureLight>();

            //features.ForEach(x => Console.WriteLine(distance.EuclideanDistance(x, cluster)));
        }
コード例 #4
0
        public void TestPairwise(string path)
        {
            Console.WriteLine("Test: " + path);
            var features = GetClusterData(Path.Combine(TestPathSingleton.TestDirectory, path));

            Assert.IsNotEmpty(features);

            var cluster = new UMCClusterLight();

            cluster.Id = features[0].Id;
            features.ForEach(x => cluster.AddChildFeature(x));


            var distance = new EuclideanDistanceMetric <FeatureLight>();

            for (var i = 0; i < features.Count; i++)
            {
                var featureX = features[i];
                for (var j = 0; j < features.Count; j++)
                {
                    if (i != j)
                    {
                        var featureY = features[j];
                        // Console.WriteLine(distance.EuclideanDistance(featureX, featureY));
                    }
                }
            }
        }
コード例 #5
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 EuclideanDistanceMetric();;

            // 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));
        }
コード例 #6
0
        public void TestMismatchGenomes()
        {
            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, 100, 1.0);
            connGenes2[1] = (1, 110, 2.0);
            connGenes2[2] = (2, 120, 3.0);
            connGenes2[3] = (3, 130, 4.0);
            connGenes2[4] = (4, 140, 5.0);

            var distanceMetric = new EuclideanDistanceMetric();;

            // GetDistance() tests.
            Assert.AreEqual(Math.Sqrt(110), distanceMetric.GetDistance(connGenes1, connGenes2));
            Assert.AreEqual(Math.Sqrt(110), distanceMetric.GetDistance(connGenes2, connGenes1));

            // TestDistance() tests.
            Assert.IsTrue(distanceMetric.TestDistance(connGenes1, connGenes2, Math.Sqrt(110) + 0.001));
            Assert.IsFalse(distanceMetric.TestDistance(connGenes1, connGenes2, Math.Sqrt(110) - 0.001));
        }
        public void SpeciateAdd_Euclidean()
        {
            IRandomSource rng                = RandomDefaults.CreateRandomSource(3);
            var           distanceMetric     = new EuclideanDistanceMetric();
            var           speciationStrategy = new RegularizedGeneticKMeansSpeciationStrategy <double>(distanceMetric, 50, 0.1);

            TestSpeciateAdd(100, 3, 2, 0.5, distanceMetric, speciationStrategy, rng, false);
            TestSpeciateAdd(100, 10, 10, 0.2, distanceMetric, speciationStrategy, rng, false);
            TestSpeciateAdd(100, 30, 10, 0.1, distanceMetric, speciationStrategy, rng, false);
        }
        public void TestSpeciateAll_Euclidean()
        {
            IRandomSource rng                = RandomDefaults.CreateRandomSource(1);
            var           distanceMetric     = new EuclideanDistanceMetric();
            var           speciationStrategy = new GeneticKMeansSpeciationStrategy <double>(distanceMetric, 50, RandomDefaults.CreateRandomSource());

            TestSpeciateAll(100, 3, 2, 0.5, distanceMetric, speciationStrategy, rng);
            TestSpeciateAll(100, 10, 10, 0.2, distanceMetric, speciationStrategy, rng);
            TestSpeciateAll(100, 30, 10, 0.1, distanceMetric, speciationStrategy, rng);
        }
コード例 #9
0
        public void TestDistanceChangeEuclidean()
        {
            var cluster = new UMCClusterLight();

            cluster.MassMonoisotopic = 500;
            cluster.Net       = .5;
            cluster.Net       = .5;
            cluster.DriftTime = 20;


            var euclid = new EuclideanDistanceMetric <UMCClusterLight>();
            DistanceFunction <UMCClusterLight> func = euclid.EuclideanDistance;

            var    deltaNet       = .01;
            double deltaMassPPM   = 1;
            double deltaDriftTime = 1;

            Console.WriteLine("Mass Diff, Mass Dist, Net, Net Dist, Drift, Drift Dist");

            for (var i = 0; i < 50; i++)
            {
                var clusterD = new UMCClusterLight();
                var clusterN = new UMCClusterLight();
                var clusterM = new UMCClusterLight();

                clusterM.DriftTime        = cluster.DriftTime + deltaDriftTime;
                clusterM.Net              = cluster.Net + deltaNet;
                clusterM.Net              = cluster.Net + deltaNet;
                clusterM.MassMonoisotopic = FeatureLight.ComputeDaDifferenceFromPPM(cluster.MassMonoisotopic,
                                                                                    deltaMassPPM * i);


                clusterN.DriftTime        = cluster.DriftTime + deltaDriftTime;
                clusterN.Net              = cluster.Net + (deltaNet * i);
                clusterN.Net              = cluster.Net + (deltaNet * i);
                clusterN.MassMonoisotopic = FeatureLight.ComputeDaDifferenceFromPPM(cluster.MassMonoisotopic,
                                                                                    deltaMassPPM);


                clusterD.DriftTime        = cluster.DriftTime + (deltaDriftTime * i);
                clusterD.Net              = cluster.Net + deltaNet;
                clusterD.Net              = cluster.Net + deltaNet;
                clusterD.MassMonoisotopic = FeatureLight.ComputeDaDifferenceFromPPM(cluster.MassMonoisotopic,
                                                                                    deltaMassPPM);

                var distM = func(cluster, clusterM);
                var distN = func(cluster, clusterN);
                var distD = func(cluster, clusterD);

                var output = string.Format("{0},{1},{2},{3},{4},{5}", deltaMassPPM * i, distM, deltaNet * i, distN,
                                           deltaDriftTime * i, distD);
                Console.WriteLine(output);
            }
        }
コード例 #10
0
        public void TestTwoClusters(string path)
        {
            Console.WriteLine("Test: " + path);
            var features = GetClusterData(Path.Combine(TestPathSingleton.TestDirectory, path));

            Assert.IsNotEmpty(features);

            var cluster = new UMCClusterLight();

            cluster.Id = features[0].Id;
            features.ForEach(x => cluster.AddChildFeature(x));


            cluster.CalculateStatistics(ClusterCentroidRepresentation.Median);
            Console.WriteLine("Cluster\tMass\tNET");
            Console.WriteLine("{0}\t{1}\t{2}\t", cluster.Id, cluster.MassStandardDeviation, cluster.NetStandardDeviation);
            Console.WriteLine();

            var distance = new EuclideanDistanceMetric <FeatureLight>();

            features.ForEach(x => Console.WriteLine(distance.EuclideanDistance(x, cluster)));
        }
コード例 #11
0
        //[TestCase(@"ClusterData\clusterData-single-1500.txt")]
        public void TestAverageLinkage(string path)
        {
            Console.WriteLine("Average Linkage Test: " + path);
            var features = GetClusterData(Path.Combine(TestPaths.TestFilesDirectory, path));

            Assert.IsNotEmpty(features);

            var cluster = new UMCClusterLight();

            cluster.Id = features[0].Id;
            features.ForEach(x => cluster.AddChildFeature(x));

            var maps = new Dictionary <int, UMCClusterLight>();

            var average = new UMCAverageLinkageClusterer <UMCLight, UMCClusterLight>();

            average.Parameters = new FeatureClusterParameters <UMCLight>();
            average.Parameters.CentroidRepresentation = ClusterCentroidRepresentation.Median;
            average.Parameters.Tolerances             = new Algorithms.FeatureTolerances();
            average.Parameters.Tolerances.Net         = .02;
            average.Parameters.Tolerances.Mass        = 6;
            average.Parameters.Tolerances.DriftTime   = .3;

            var distance = new WeightedEuclideanDistance <UMCLight>();

            average.Parameters.DistanceFunction = distance.EuclideanDistance;
            var euclid = new EuclideanDistanceMetric <UMCLight>();

            average.Parameters.DistanceFunction = euclid.EuclideanDistance;
            var clusters = average.Cluster(features);

            Console.WriteLine("Clusters = {0}", clusters.Count);
            var id = 1;

            foreach (var testCluster in clusters)
            {
                testCluster.CalculateStatistics(ClusterCentroidRepresentation.Mean);
                var distances = new List <double>();

                // Show a sampling of 5 results
                var threshold = (int)(testCluster.Features.Count / (double)5);
                if (threshold < 1)
                {
                    threshold = 1;
                }

                testCluster.Id = id++;
                var featureID = 0;

                foreach (var feature in testCluster.Features)
                {
                    featureID++;
                    if (featureID % threshold == 0)
                    {
                        Console.WriteLine("{0},{1},{2},{3}",
                                          feature.Net,
                                          feature.MassMonoisotopicAligned,
                                          feature.DriftTime,
                                          testCluster.Id);
                    }

                    var newDistance = distance.EuclideanDistance(feature, testCluster);
                    distances.Add(newDistance);
                }
                //Console.WriteLine();
                //Console.WriteLine("Distances");
                //distances.ForEach(x => Console.WriteLine(x));
                //Console.WriteLine();
            }
        }
コード例 #12
0
ファイル: UMCClustering.cs プロジェクト: msdna/MultiAlign
        public void TestDistanceChangeEuclidean()
        {
            var cluster = new UMCClusterLight();
            cluster.MassMonoisotopic = 500;
            cluster.Net = .5;
            cluster.Net = .5;
            cluster.DriftTime = 20;

            var euclid = new EuclideanDistanceMetric<UMCClusterLight>();
            DistanceFunction<UMCClusterLight> func = euclid.EuclideanDistance;

            var deltaNet = .01;
            double deltaMassPPM = 1;
            double deltaDriftTime = 1;

            Console.WriteLine("Mass Diff, Mass Dist, Net, Net Dist, Drift, Drift Dist");

            for (var i = 0; i < 50; i++)
            {
                var clusterD = new UMCClusterLight();
                var clusterN = new UMCClusterLight();
                var clusterM = new UMCClusterLight();

                clusterM.DriftTime = cluster.DriftTime + deltaDriftTime;
                clusterM.Net = cluster.Net + deltaNet;
                clusterM.Net = cluster.Net + deltaNet;
                clusterM.MassMonoisotopic = FeatureLight.ComputeDaDifferenceFromPPM(cluster.MassMonoisotopic,
                    deltaMassPPM*i);

                clusterN.DriftTime = cluster.DriftTime + deltaDriftTime;
                clusterN.Net = cluster.Net + (deltaNet*i);
                clusterN.Net = cluster.Net + (deltaNet*i);
                clusterN.MassMonoisotopic = FeatureLight.ComputeDaDifferenceFromPPM(cluster.MassMonoisotopic,
                    deltaMassPPM);

                clusterD.DriftTime = cluster.DriftTime + (deltaDriftTime*i);
                clusterD.Net = cluster.Net + deltaNet;
                clusterD.Net = cluster.Net + deltaNet;
                clusterD.MassMonoisotopic = FeatureLight.ComputeDaDifferenceFromPPM(cluster.MassMonoisotopic,
                    deltaMassPPM);

                var distM = func(cluster, clusterM);
                var distN = func(cluster, clusterN);
                var distD = func(cluster, clusterD);

                var output = string.Format("{0},{1},{2},{3},{4},{5}", deltaMassPPM*i, distM, deltaNet*i, distN,
                    deltaDriftTime*i, distD);
                Console.WriteLine(output);
            }
        }