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;
}
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;
}
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();
}
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;
}
}
}
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();
}
Aggregations