Exemplo n.º 1
0
        /// <summary>
        /// Orders the queries based on the given comparer.
        /// </summary>
        /// <param name="labels">The label for all query URL pairs</param>
        /// <param name="threadIndex">Specifies the thread which is executing this code</param>
        /// <param name="scoreBegin">position of the first query-URL pair to sort in the score array</param>
        /// <param name="labelBegin">position of the first query-URL pair to sort in the label array</param>
        /// <param name="count">number of query-URL pairs</param>
        /// <param name="permutation">resulting query order array</param>
        /// <param name="scores">The scores for all query URL pairs</param>
        private void SortRankingResults(short[] labels, int threadIndex, int scoreBegin, int labelBegin, int count, int[] permutation, double[] scores)
        {
            Array.Copy(_oneTwoThree, permutation, count);

            DcgPermutationComparer comparer = _comparers[threadIndex];

            // set values for the comparer
            comparer.Scores       = scores;
            comparer.Labels       = labels;
            comparer.ScoresOffset = scoreBegin;
            comparer.LabelsOffset = labelBegin;

            // calculate the permutation
            Array.Sort(permutation, 0, count, comparer);

            // check if there is topN re-sorter specified. If so,
            // change the order of the TOP N results
            if (_secondLevelcomparers != null)
            {
                // set values for the comparer
                _secondLevelcomparers[threadIndex].Labels       = labels;
                _secondLevelcomparers[threadIndex].LabelsOffset = labelBegin;

                // calculate the permutation
                Array.Sort(permutation, 0, Math.Min(count, _secondLevelcomparers[threadIndex].CompareFirstN), _secondLevelcomparers[threadIndex]);
            }
        }
Exemplo n.º 2
0
        // thread worker
        private void WinLossRangeWorkerFromScores(Dataset dataset, short[] labels, double[] scores, double[] result, int query, int threadIndex)
        {
            int begin = dataset.Boundaries[query];
            int count = dataset.Boundaries[query + 1] - begin;

            int[] permutation = _permutationBuffers[threadIndex];
            DcgPermutationComparer comparer = _comparers[threadIndex];

            // set values for the comparer
            comparer.Scores       = scores;
            comparer.Labels       = labels;
            comparer.ScoresOffset = begin;
            comparer.LabelsOffset = begin;

            // calculate the permutation
            Array.Copy(_oneTwoThree, permutation, count);
            Array.Sort(permutation, 0, count, comparer);

            int surplus       = 0;
            int maxsurplus    = 0;
            int maxsurpluspos = 0;

            for (int t = 0; t < count; ++t)
            {
                if (labels[begin + permutation[t]] > 0 ||
                    labels[begin + permutation[t]] < 0)
                {
                    surplus += labels[begin + permutation[t]];
                }
                else
                {
                    surplus--;
                }
                if (surplus > maxsurplus)
                {
                    maxsurplus    = surplus;
                    maxsurpluspos = t;
                }
                if (t == 100)
                {
                    Utils.InterlockedAdd(ref result[0], surplus);
                }
                if (t == 200)
                {
                    Utils.InterlockedAdd(ref result[1], surplus);
                }
                if (t == 300)
                {
                    Utils.InterlockedAdd(ref result[2], surplus);
                }
                if (t == 400)
                {
                    Utils.InterlockedAdd(ref result[3], surplus);
                }
                if (t == 500)
                {
                    Utils.InterlockedAdd(ref result[4], surplus);
                }
                if (t == 1000)
                {
                    Utils.InterlockedAdd(ref result[5], surplus);
                }
            }
            Utils.InterlockedAdd(ref result[6], maxsurplus);
            Utils.InterlockedAdd(ref result[7], maxsurpluspos);
            Utils.InterlockedAdd(ref result[8], count);
        }