Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a WinLoss calculator
        /// </summary>
        /// <param name="maxDocsPerQuery">the maximum number of documents per query</param>
        /// <param name="sortingAlgorithm">a string describing the sorting algorithm to use</param>
        public WinLossCalculator(int maxDocsPerQuery, string sortingAlgorithm)
        {
            int numThreads = BlockingThreadPool.NumThreads;

            _oneTwoThree        = Utils.GetIdentityPermutation(maxDocsPerQuery);
            _permutationBuffers = new int[numThreads][];
            for (int i = 0; i < numThreads; ++i)
            {
                _permutationBuffers[i] = new int[maxDocsPerQuery];
            }
            _scoreBuffers = new double[numThreads][];
            for (int i = 0; i < numThreads; ++i)
            {
                _scoreBuffers[i] = new double[maxDocsPerQuery];
            }
            _comparers = new DcgPermutationComparer[numThreads];
            for (int i = 0; i < numThreads; ++i)
            {
                _comparers[i] = DcgPermutationComparerFactory.GetDcgPermutationFactory(sortingAlgorithm);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a DCG calculator
        /// </summary>
        /// <param name="maxDocsPerQuery">the maximum number of documents per query</param>
        /// <param name="sortingAlgorithm">a string describing the sorting algorithm to use</param>
        /// <param name="topNDocsForIdealDcg">specifies the ideal DCG@ computation.</param>
        public DcgCalculator(int maxDocsPerQuery, string sortingAlgorithm, int topNDocsForIdealDcg = 0)
        {
            int numThreads = BlockingThreadPool.NumThreads;

            _oneTwoThree        = Utils.GetIdentityPermutation(maxDocsPerQuery);
            _permutationBuffers = new int[numThreads][];
            for (int i = 0; i < numThreads; ++i)
            {
                _permutationBuffers[i] = new int[maxDocsPerQuery];
            }

            _scoreBuffers = new double[numThreads][];
            for (int i = 0; i < numThreads; ++i)
            {
                _scoreBuffers[i] = new double[maxDocsPerQuery];
            }

            _comparers = new DcgPermutationComparer[numThreads];

            for (int i = 0; i < numThreads; ++i)
            {
                _comparers[i] = DcgPermutationComparerFactory.GetDcgPermutationFactory(sortingAlgorithm);

                // only reorder query/URL pairs, if we have at least two query/URL pairs for reordering
                if (topNDocsForIdealDcg > 1)
                {
                    // using lazy initialize for the _secondLevelComparers to make it cheap and easy
                    // later to test, if re-ordering needs to be computed. This way it also only allocates
                    // the memory it really needs
                    if (_secondLevelcomparers == null)
                    {
                        _secondLevelcomparers = new DescendingStableIdealComparer[numThreads];
                    }

                    _secondLevelcomparers[i] = new DescendingStableIdealComparer(topNDocsForIdealDcg);
                }
            }
        }