示例#1
0
        public IClusterer <T, U> Create(GenericClusteringAlgorithmType clusterType)
        {
            IClusterer <T, U> clusterer = null;

            switch (clusterType)
            {
            case GenericClusteringAlgorithmType.AverageLinkage:
                clusterer = new UMCAverageLinkageClusterer <T, U>();
                break;

            case GenericClusteringAlgorithmType.Centroid:
                clusterer = new UMCCentroidClusterer <T, U>();
                break;

            case GenericClusteringAlgorithmType.SingleLinkage:
                clusterer = new UMCSingleLinkageClusterer <T, U>();
                break;

            case GenericClusteringAlgorithmType.Prims:
                clusterer = new UMCPrimsClustering <T, U>();
                break;

            case GenericClusteringAlgorithmType.BinarySearchTree:
                clusterer = new Clustering.MsFeatureTreeClusterer <T, U>();
                break;

            default:
                throw new ArgumentOutOfRangeException(string.Format("Cannot create generic {0} clusterer.", clusterType));
            }

            return(clusterer);
        }
示例#2
0
        public static IClusterer<UMCLight, UMCClusterLight> Create(LcmsFeatureClusteringAlgorithmType clusterType)
        {
            IClusterer<UMCLight, UMCClusterLight> clusterer = null;
            switch (clusterType)
            {
                case LcmsFeatureClusteringAlgorithmType.AverageLinkage:
                    clusterer = new UMCAverageLinkageClusterer<UMCLight, UMCClusterLight>();
                    break;
                case LcmsFeatureClusteringAlgorithmType.Centroid:
                    clusterer = new UMCCentroidClusterer<UMCLight, UMCClusterLight>();
                    break;
                case LcmsFeatureClusteringAlgorithmType.SingleLinkage:
                    clusterer = new UMCSingleLinkageClusterer<UMCLight, UMCClusterLight>();
                    break;
                case LcmsFeatureClusteringAlgorithmType.Prims:
                    clusterer = new UMCPrimsClustering<UMCLight, UMCClusterLight>();
                    break;
            }

            return clusterer;
        }
示例#3
0
        //[TestCase(@"ClusterData\clusterData-merged-nodelin.txt")]
        public void TestPrims(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>();

            var prims = new UMCPrimsClustering <UMCLight, UMCClusterLight>();

            prims.Parameters = new FeatureClusterParameters <UMCLight>();
            prims.Parameters.CentroidRepresentation = ClusterCentroidRepresentation.Mean;
            prims.Parameters.Tolerances             = new FeatureTolerances();

            var clusters = prims.Cluster(features);

            var counts = new Dictionary <int, Dictionary <int, int> >();
            var cid    = 0;

            foreach (var clusterx in clusters)
            {
                clusterx.Id = cid++;
                foreach (var feature in clusterx.Features)
                {
                    if (!counts.ContainsKey(feature.GroupId))
                    {
                        counts.Add(feature.GroupId, new Dictionary <int, int>());
                    }
                    if (!counts[feature.GroupId].ContainsKey(feature.Id))
                    {
                        counts[feature.GroupId].Add(feature.Id, 0);
                    }

                    if (feature.Id == 51 || feature.Id == 37)
                    {
                        Console.WriteLine("Found it {0} cluster {1}", feature.Id, clusterx.Id);
                    }

                    counts[feature.GroupId][feature.Id]++;
                    Console.WriteLine("Found {0}", clusterx.Id);
                    if (counts[feature.GroupId][feature.Id] > 1)
                    {
                        Console.WriteLine("Duplicate!!!! cluster {0}  feature {1}", clusterx.Id, feature.Id);
                    }
                }
            }

            Console.WriteLine("Group\tFeature\tCount");
            foreach (var group in counts.Keys)
            {
                foreach (var id in counts[group].Keys)
                {
                    Console.WriteLine("{0}\t{1}\t{2}", group, id, counts[group][id]);
                }
            }

            Console.WriteLine("Clusters = {0}", clusters.Count);
        }
示例#4
0
        //[TestCase(@"ClusterData\clusterData-single-1500.txt", 4)]
        //[TestCase(@"ClusterData\clusterData-single-1500-two.txt", 4)]
        public void TestPrimsWeighted(string path, double sigma)
        {
            sigma = 1;

            Console.WriteLine();
            Console.WriteLine("Tests: " + path);
            Console.WriteLine("Sigma Cutoff: {0}", sigma);
            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>();


            var prims = new UMCPrimsClustering <UMCLight, UMCClusterLight>(sigma);

            prims.Parameters = new FeatureClusterParameters <UMCLight>();
            prims.Parameters.CentroidRepresentation      = ClusterCentroidRepresentation.Mean;
            prims.Parameters.Tolerances                  = new FeatureTolerances();
            prims.Parameters.OnlyClusterSameChargeStates = false;
            prims.Parameters.Tolerances.DriftTime        = .3;
            prims.Parameters.Tolerances.Mass             = 15;
            prims.Parameters.Tolerances.Net              = .02;
            prims.DumpLinearRelationship                 = false;

            var distance = new WeightedEuclideanDistance <UMCLight>();

            prims.Parameters.DistanceFunction = distance.EuclideanDistance;
            var clusters = prims.Cluster(features);


            Console.WriteLine();
            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 15 results
                var threshold = (int)(testCluster.Features.Count / (double)15);
                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();
            }
            Console.WriteLine();
            Console.WriteLine("Test Done:");
            Console.WriteLine();
        }