示例#1
0
        /// <summary>
        /// Finds two vectors and returns the value.
        /// </summary>
        internal double Find(Peak vector1Peak, GroupInfo vector1Group, Peak vector2Peak, GroupInfo vector2Group)
        {
            IntensityMatrix.RowHeader h1 = new IntensityMatrix.RowHeader(vector1Peak, vector1Group);
            IntensityMatrix.RowHeader h2 = new IntensityMatrix.RowHeader(vector2Peak, vector2Group);

            int i = ValueMatrix.FindIndex(h1);
            int j = ValueMatrix.FindIndex(h2);

            return(Values[i, j]);
        }
        /// <summary>
        ///
        /// </summary>
        protected override IEnumerable <Cluster> Cluster(IntensityMatrix vmatrix, DistanceMatrix UNUSED, ArgsClusterer args, ConfigurationClusterer tag, ProgressReporter prog)
        {
            // Get parameters
            // COUNT LIMIT
            int countLimit = (int)tag.UntypedArgs.Parameters[0];
            // DISTANCE LIMIT
            double distanceLimit = (double)tag.UntypedArgs.Parameters[1];
            // SEED PEAK
            WeakReference <Peak> seedPeakRef = (WeakReference <Peak>)tag.UntypedArgs.Parameters[2];
            Peak seedPeak = seedPeakRef.GetTargetOrThrow();
            // SEED GROUP
            GroupInfo groupInfo = (GroupInfo)tag.UntypedArgs.Parameters[3];
            // DO-K-MEANS?
            bool doKMeans = (bool)tag.UntypedArgs.Parameters[4];

            // Create the seed cluster
            Cluster        seedCluster = new Cluster("1", tag);
            List <Cluster> seedList    = new List <Cluster> {
                seedCluster
            };
            int seedIndex = vmatrix.FindIndex(new IntensityMatrix.RowHeader(seedPeak, args.SplitGroups ? groupInfo : null));

            if (seedIndex == -1)
            {
                throw new InvalidOperationException($"The chosen peak {{{seedPeak}}} cannot be used a seed because it is not present in the value matrix. Please check that this peak has not been excluded by the filter condition {{{args.PeakFilter}}}.");
            }

            seedCluster.Exemplars.Add(vmatrix.Vectors[seedIndex]);

            // Autogenerate the clusters
            int?   nCountLimit    = (countLimit != Int32.MinValue) ? countLimit : (int?)null;
            double?nDistanceLimit = (distanceLimit != Double.MinValue) ? countLimit : (double?)null;

            List <Cluster> autoGenClusters = AutogenerateClusters(vmatrix, seedList, nDistanceLimit, nCountLimit, args.Distance, tag, prog);

            // Do k-means (if requested)
            if (doKMeans)
            {
                prog.Enter("k-means");
                LegacyClustererHelper.PerformKMeansCentering(vmatrix, autoGenClusters, args.Distance, prog);
                prog.Leave();
            }

            // Return full list
            return(autoGenClusters);
        }