示例#1
0
        /// <summary>
        /// The calculate minimal hg.
        /// </summary>
        /// <param name="totalElements">
        /// The elementsOnTop.
        /// </param>
        /// <param name="indices">
        /// The indices.
        /// </param>
        /// <param name="threshold">
        /// The threshold.
        /// </param>
        /// <returns>
        /// The <see cref="HGScore"/>.
        /// </returns>
        public static MHGScore CalculateMinimalHG(int totalElements, SortedSet <int> indices, double threshold)
        {
            int    totalMatches = indices.Count;
            double ratio        = totalMatches / (double)totalElements;
            var    minHG        = new MHGScore(totalElements, totalMatches, 0, 0, 1);
            int    matchesOnTop = 1;

            foreach (int index in indices)
            {
                int elementsOnTop = index;
                if (matchesOnTop / (double)elementsOnTop > ratio)
                {
                    double hg = HG(totalElements, elementsOnTop, totalMatches, matchesOnTop, true);
                    if (hg <= threshold)
                    {
                        double hgt = HGT(hg, elementsOnTop, totalElements, totalMatches, matchesOnTop);
                        if (hgt <= threshold && hgt < minHG.ScoreValue)
                        {
                            minHG = new MHGScore(totalElements, totalMatches, elementsOnTop, matchesOnTop, hgt);
                        }
                    }
                }

                matchesOnTop++;
            }

            return(minHG);
        }
示例#2
0
        /// <summary>
        /// The fast score.
        /// </summary>
        /// <param name="totalElements">
        /// The total elements.
        /// </param>
        /// <param name="indices">
        /// The indices.
        /// </param>
        /// <param name="i">
        /// The i.
        /// </param>
        /// <returns>
        /// The <see cref="HGScore"/>.
        /// </returns>
        public static MHGScore FastScore(int totalElements, SortedSet <int> indices, int i)
        {
            Score min          = new MHGScore(totalElements, 0, 0, 0, 1);
            int   totalMatches = indices.Count;

            for (double j = Math.Pow(2, i); j >= 2; j /= 2)
            {
                var   elementsOnTop = (int)(totalElements / j);
                int   matchesOnTop  = indices.Take(elementsOnTop + 1).Count();
                Score hGScore       = CalculateHGT(totalElements, elementsOnTop, totalMatches, matchesOnTop);
                if (hGScore.ScoreValue < min.ScoreValue)
                {
                    min = hGScore;
                }
            }

            return(new MHGScore(min));
        }