コード例 #1
0
 /// <summary>
 /// Inserts a new feature tree into the mix...
 /// </summary>
 protected override void Insert(FeatureTree <T, U> node, T feature)
 {
     if (node == null)
     {
         node = new FeatureTree <T, U>(m_func);
     }
     node.Insert(feature);
 }
コード例 #2
0
        /// <summary>
        /// Clusters features based on some specified values.
        /// </summary>
        /// <typeparam name="TChild"></typeparam>
        /// <typeparam name="TCluster"></typeparam>
        /// <param name="features"></param>
        /// <param name="sortFunction"></param>
        /// <param name="massDiffFunction"></param>
        /// <param name="comparison"></param>
        /// <param name="massTolerance"></param>
        /// <returns></returns>
        private IEnumerable <TCluster> Cluster <TChild, TCluster>(IEnumerable <TChild> features,
                                                                  Comparison <TChild> sortFunction,
                                                                  Func <TChild, TChild, double> massDiffFunction,
                                                                  Func <TChild, TChild, int> comparison,
                                                                  double massTolerance)
            where TChild :   FeatureLight, new()
            where TCluster : FeatureLight, IFeatureCluster <TChild>, new ()
        {
            var clusters     = new List <TCluster>();
            var currentIndex = 0;
            var n            = features.Count();

            // Sort the features based on m/z first
            var msFeatures = new List <TChild>();

            msFeatures.AddRange(features);

            OnProgress("Sorting features for partitioning step");
            msFeatures.Sort(sortFunction);

            OnProgress("Examining features within partitions");

            // Iterate through all of the features
            while (currentIndex < n)
            {
                var hasGap      = false;
                var lastFeature = msFeatures[currentIndex];
                var lastIndex   = currentIndex + 1;
                var gapFeatures = new List <TChild> {
                    lastFeature
                };
                while (!hasGap && lastIndex < n)
                {
                    var currentFeature = msFeatures[lastIndex];


                    var massDiff = massDiffFunction(currentFeature, lastFeature);

                    // Time to quit
                    if (Math.Abs(massDiff) > massTolerance)
                    {
                        // Stop here...
                        hasGap = true;
                    }
                    else
                    {
                        // Increment and save this feature
                        lastIndex++;
                        gapFeatures.Add(currentFeature);
                        lastFeature = currentFeature;
                    }
                }
                currentIndex = lastIndex;

                // Now that we have a gap...let's go a head and start building the features
                // first we build a scan dictionary
                // sorted by scans
                var featureMap = new Dictionary <int, List <TChild> >();
                foreach (var feature in gapFeatures)
                {
                    var scan = feature.Scan;
                    if (!featureMap.ContainsKey(scan))
                    {
                        featureMap.Add(scan, new List <TChild>());
                    }
                    featureMap[scan].Add(feature);
                }

                // Now build the tree...where each node is a feature.
                var scans = featureMap.Keys.OrderBy(x => x);
                var tree  = new FeatureTree <TChild, TCluster>(comparison);

                foreach (var feature in scans.SelectMany(scan => featureMap[scan]))
                {
                    tree.Insert(feature);
                }

                var newFeatures = tree.Build();
                clusters.AddRange(newFeatures);
            }
            return(clusters);
        }
コード例 #3
0
 protected override void Add(T feature)
 {
     m_features.Add(feature);
     m_left  = new FeatureTree <T, U>(m_func);
     m_right = new FeatureTree <T, U>(m_func);
 }