Beispiel #1
0
        public DefaultOrderer(
            SummaryOrderPolicy summaryOrderPolicy = SummaryOrderPolicy.Default,
            MethodOrderPolicy methodOrderPolicy   = MethodOrderPolicy.Declared)
        {
            this.summaryOrderPolicy = summaryOrderPolicy;
            IComparer <Descriptor> targetComparer = new DescriptorComparer(methodOrderPolicy);

            benchmarkComparer    = new BenchmarkComparer(paramsComparer, jobComparer, targetComparer);
            logicalGroupComparer = new LogicalGroupComparer(benchmarkComparer);
        }
        /// <summary>
        /// A manner to compare two features and see how similar they are.
        /// This method takes the assumption that the enumerator from the
        /// <see cref="FeatureVector"/>s return objects in an ordered manner.
        /// </summary>
        /// <param name="primary">The reference item for comparison.
        /// All descriptors will be compared with the other vector.</param>
        /// <param name="secondary">The comparison item, only descriptors which
        /// it shares with the reference vector will be compared.</param>
        /// <returns>A weighted average between [0, 1] which shows the similarity.
        /// A value of 1 means that they are the exact same and 0 means that they
        /// are nothing alike.</returns>
        public static double Compare(FeatureVector primary, FeatureVector secondary)
        {
            if (primary == null)
            {
                throw new ArgumentNullException(nameof(primary));
            }
            if (secondary == null)
            {
                throw new ArgumentNullException(nameof(secondary));
            }

            WeightManager             weights  = Settings.Weights;
            DescriptorComparer        comparer = DescriptorComparer.Instance;
            IEnumerator <IDescriptor> pdescs   = primary.Descriptors.GetEnumerator();
            IEnumerator <IDescriptor> sdescs   = secondary.Descriptors.GetEnumerator();

            double sumCubedElem = 0;
            double sumHist      = 0;
            int    countHist    = 0;

            bool hasNext = true;

            hasNext &= pdescs.MoveNext();
            hasNext &= sdescs.MoveNext();

            while (hasNext)
            {
                IDescriptor pdesc = pdescs.Current;
                IDescriptor sdesc = sdescs.Current;

                int dif = comparer.Compare(pdesc, sdesc);
                if (dif == 0)
                {
                    if (pdesc is ElemDescriptor)
                    {
                        sumCubedElem += Math.Pow(pdesc.Compare(sdesc), 2)
                                        * weights[pdesc.Name];
                    }
                    else if (pdesc is HistDescriptor)
                    {
                        sumHist += pdesc.Compare(sdesc) * weights[pdesc.Name];
                        countHist++;
                    }

                    hasNext &= pdescs.MoveNext();
                    hasNext &= sdescs.MoveNext();
                    continue;

                    // The primary one is beind so increment that side.
                }
                else if (dif < 0)
                {
                    hasNext &= pdescs.MoveNext();

                    // The secondary one is beind so increment that side.
                }
                else if (dif > 0)
                {
                    hasNext &= sdescs.MoveNext();
                }
            }

            double L2       = Math.Sqrt(sumCubedElem);
            double distance = (sumHist + L2) / (countHist + 1);

            return(distance);
        }