Search in sources :

Example 1 with structures._QUPair

use of structures._QUPair in project IR_Base by Linda-sunshine.

the class LambdaRank method gradientUpdate.

// for lambdaRank
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;
}
Also used : structures._QUPair(structures._QUPair)

Example 2 with structures._QUPair

use of structures._QUPair in project IR_Base by Linda-sunshine.

the class LambdaRankWorker method gradientUpdate.

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;
}
Also used : structures._QUPair(structures._QUPair)

Example 3 with structures._QUPair

use of structures._QUPair in project IR_Base by Linda-sunshine.

the class MAP_Evaluator method setQuery.

@Override
public void setQuery(_Query query) {
    super.setQuery(query);
    m_P = 0;
    for (_QUPair d : m_query.m_docList) if (d.m_y > 0)
        m_P++;
    if (m_P > 0)
        updateDeltas();
}
Also used : structures._QUPair(structures._QUPair)

Example 4 with structures._QUPair

use of structures._QUPair in project IR_Base by Linda-sunshine.

the class MAP_Evaluator method updateDeltas.

@Override
public void updateDeltas() {
    super.updateDeltas();
    // create cache for delta
    HashMap<_QUPair, Double> change = null;
    _QUPair qu1, qu2;
    double delta;
    for (int i = 0; i < m_size; i++) {
        qu1 = m_query.m_docList.get(i);
        if (change == null)
            change = new HashMap<_QUPair, Double>();
        delta = 1.0 / (i + 1.0);
        for (int j = i + 1; j < m_size; j++) {
            qu2 = m_query.m_docList.get(j);
            if (// make a difference
            qu1.m_y != qu2.m_y)
                // absolute diff
                change.put(qu2, delta / m_P);
            delta += 1.0 / (j + 1.0);
        }
        if (change.size() > 0) {
            m_deltas.put(qu1, change);
            change = null;
        }
    }
}
Also used : structures._QUPair(structures._QUPair) HashMap(java.util.HashMap)

Example 5 with structures._QUPair

use of structures._QUPair in project IR_Base by Linda-sunshine.

the class NDCG_Evaluator method setQuery.

@Override
public void setQuery(_Query query) {
    // every time we want to evaluate new queries
    super.setQuery(query);
    ArrayList<Integer> labels = new ArrayList<Integer>(m_size);
    for (_QUPair qu : m_query.m_docList) labels.add(qu.m_y);
    Collections.sort(labels, Collections.reverseOrder());
    // calculate iDCG
    m_iDCG = 0;
    for (int i = 0; i < Math.min(labels.size(), m_k); i++) m_iDCG += m_gain[labels.get(i)] * m_discount[i];
    updateDeltas();
}
Also used : structures._QUPair(structures._QUPair) ArrayList(java.util.ArrayList)

Aggregations

structures._QUPair (structures._QUPair)11 structures._Query (structures._Query)5 ArrayList (java.util.ArrayList)2 Evaluator (Ranker.evaluator.Evaluator)1 MAP_Evaluator (Ranker.evaluator.MAP_Evaluator)1 NDCG_Evaluator (Ranker.evaluator.NDCG_Evaluator)1 HashMap (java.util.HashMap)1 MyPriorityQueue (structures.MyPriorityQueue)1 structures._Doc (structures._Doc)1 structures._RankItem (structures._RankItem)1