Skip to content

Revert to using native code for FastTree ranking gradient #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/Microsoft.ML.FastTree/FastTreeRanking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ protected override void GetGradientInOneQuery(int query, int threadIndex)
{
// calculates the permutation that orders "scores" in descending order, without modifying "scores"
Array.Copy(_oneTwoThree, permutation, numDocuments);
#if USE_FASTTREENATIVE2
#if USE_FASTTREENATIVE

PermutationSort(permutation, scoresToUse, labels, numDocuments, begin);
// Get how far about baseline our current
Expand Down Expand Up @@ -818,24 +818,26 @@ protected override void GetGradientInOneQuery(int query, int threadIndex)
if (!_trainDcg && (_costFunctionParam == 'c' || _useShiftedNdcg))
{
PermutationSort(permutation, scoresToUse, labels, numDocuments, begin);
inverseMaxDcg = 1.0 / DCGCalculator.MaxDCGQuery(labels, begin, numDocuments, numDocuments, _labelCounts[query]);
inverseMaxDcg = 1.0 / DcgCalculator.MaxDcgQuery(labels, begin, numDocuments, numDocuments, _labelCounts[query]);
}
C_GetDerivatives(numDocuments, begin, pPermutation, pLabels,
// A constant related to secondary labels, which does not exist in the current codebase.
const bool secondaryIsolabelExclusive = false;
GetDerivatives(numDocuments, begin, pPermutation, pLabels,
pScores, pLambdas, pWeights, pDiscount,
inverseMaxDcg, pGainLabels,
_secondaryMetricShare, _secondaryIsolabelExclusive, secondaryInverseMaxDcg, pSecondaryGains,
_secondaryMetricShare, secondaryIsolabelExclusive, secondaryInverseMaxDcg, pSecondaryGains,
pSigmoidTable, _minScore, _maxScore, _sigmoidTable.Length, _scoreToSigmoidTableFactor,
_costFunctionParam, _distanceWeight2, numActualResults, &lambdaSum, double.MinValue,
_baselineAlphaCurrent, baselineDcgGap);

// For computing the "ideal" case of the DCGs.
if (_baselineDcg != null)
{
if (scoresToUse == _scores)
Array.Copy(_scores, begin, _scoresCopy, begin, numDocuments);
if (scoresToUse == Scores)
Array.Copy(Scores, begin, _scoresCopy, begin, numDocuments);
for (int i = begin; i < begin + numDocuments; ++i)
{
_scoresCopy[i] += _gradient[i] / _weights[i];
_scoresCopy[i] += Gradient[i] / Weights[i];
}
Array.Copy(_oneTwoThree, permutation, numDocuments);
PermutationSort(permutation, _scoresCopy, labels, numDocuments, begin);
Expand Down