Пример #1
0
        /// <summary>
        /// Compare two classifications and get a metric that identifies how similar they are.
        ///
        /// Consider this the gold standard categorization and alternatePartition the unattended clustering.
        /// (It doesn't matter, as the results are symmetrical.)
        /// </summary>
        /// <param name="alternatePartition">The unattended clustering.</param>
        /// <param name="alpha">Determines how to weight the Precision and Recall.
        /// The default value of 0.5 works well for most situations and evenly balances Precision and Recall.
        /// Must be between 0 and 1. </param>
        /// <returns>The metric. Casting it to a double (or calling BCubed) will retrieve a numerical measure.
        /// If that value is 1.0, the classifications are identical.
        /// </returns>
        public ClusterMetric <TPoint, TLabel> Compare(Classification <TPoint, TLabel> alternatePartition, double alpha = 0.5)
        {
            var category = this;
            var cluster  = alternatePartition;
            ClusterMetric <TPoint, TLabel> metric;

            // IsSimilar is fast, but less precise. If it says the Classifications have identical clustering, they do,
            // but if they do not, we need to figure out how bad they match and need to create a real ClusterMetric.
            if (category.IsSimilarTo(cluster))
            {
                metric = new ClusterMetric <TPoint, TLabel>();
            }
            else
            {
                metric = new ClusterMetric <TPoint, TLabel>(
                    Points().ToList(),
                    label => category.LabelToPoints[label],
                    label => cluster.LabelToPoints[label],
                    point => category.PointToLabel[point],
                    point => cluster.PointToLabel[point],
                    alpha
                    );
            }

            metric.Measure();
            return(metric);
        }
 /// <summary>
 /// Compare the initial and final classifications and set MeasuredChange.
 /// </summary>
 /// <returns>The result of the comparison.</returns>
 ClusterMetric <UnsignedPoint, string> RecordResult()
 {
     // Compute the BCubed score between the initial and final classification IF there was an initial classification.
     if (InitialClassification.NumPartitions != InitialClassification.NumPoints)
     {
         Timer.Start("Compare classifications");
         MeasuredChange = CompareClassifications();
         Timer.Stop("Compare classifications");
         // Write comparison to the log.
         Logger.Info($"Comparison between initial and final classification: {MeasuredChange}. Acceptable: {Configuration.AcceptableBCubed}");
     }
     else
     {
         MeasuredChange = new ClusterMetric <UnsignedPoint, string>()
         {
             Precision = 0,
             Recall    = 0
         };
     }
     return(MeasuredChange);
 }