protected override void UpdateState(RowCursorState state) { // Calculate the current group DCG, NDCG and MaxDcg. RankingUtils.QueryMaxDcg(_labelGains, _truncationLevel, _discountMap, state.QueryLabels, state.QueryOutputs, state.MaxDcgCur); RankingUtils.QueryDcg(_labelGains, _truncationLevel, _discountMap, state.QueryLabels, state.QueryOutputs, state.DcgCur); for (int t = 0; t < _truncationLevel; t++) { Double ndcg = state.MaxDcgCur[t] > 0 ? state.DcgCur[t] / state.MaxDcgCur[t] : 0; state.NdcgCur[t] = ndcg; } state.QueryLabels.Clear(); state.QueryOutputs.Clear(); }
public void UpdateGroup(Single weight) { RankingUtils.QueryMaxDcg(_labelGains, TruncationLevel, _discountMap, _queryLabels, _queryOutputs, _groupMaxDcgCur); if (_groupMaxDcg != null) { var maxDcg = new Double[TruncationLevel]; Array.Copy(_groupMaxDcgCur, maxDcg, TruncationLevel); _groupMaxDcg.Add(maxDcg); } RankingUtils.QueryDcg(_labelGains, TruncationLevel, _discountMap, _queryLabels, _queryOutputs, _groupDcgCur); if (_groupDcg != null) { var groupDcg = new Double[TruncationLevel]; Array.Copy(_groupDcgCur, groupDcg, TruncationLevel); _groupDcg.Add(groupDcg); } var groupNdcg = new Double[TruncationLevel]; for (int t = 0; t < TruncationLevel; t++) { Double ndcg = _groupMaxDcgCur[t] > 0 ? _groupDcgCur[t] / _groupMaxDcgCur[t] : 0; _sumNdcgAtN[t] += ndcg * weight; _sumDcgAtN[t] += _groupDcgCur[t] * weight; groupNdcg[t] = ndcg; } _sumWeights += weight; if (_groupNdcg != null) { _groupNdcg.Add(groupNdcg); } _queryLabels.Clear(); _queryOutputs.Clear(); }