コード例 #1
0
  protected int gradientUpdate(_Query query) {
    double diff;
    int i, trainSize = 0;

    // Step 1: calculate the ranking score
    for (_QUPair pair : query.m_docList) pair.score(m_weight);
    m_eval.eval(query);

    // Step 2: accumulate the lambdas for each URL
    for (_QUPair pair : query.m_docList) {
      diff = 0;
      if (pair.m_worseURLs != null) {
        for (_QUPair worseURL : pair.m_worseURLs) { // force to moving up
          diff += Utils.logistic(worseURL.m_score - pair.m_score) * m_eval.delta(pair, worseURL);
          trainSize++;
        }
      }

      if (pair.m_betterURLs != null) {
        for (_QUPair betterURL : pair.m_betterURLs) { // force to moving down
          diff -= Utils.logistic(pair.m_score - betterURL.m_score) * m_eval.delta(betterURL, pair);
          trainSize++;
        }
      }

      // Step 3: update weight according to this URL
      if (diff != 0) {
        for (i = 0; i < pair.m_rankFv.length; i++) m_g[i] -= diff * pair.m_rankFv[i];
      }
    }

    return trainSize;
  }