use of structures._UserReviewPair in project IR_Base by Linda-sunshine.
the class asyncMTLinAdapt method trainByReview.
void trainByReview() {
LinkedList<_UserReviewPair> reviewlist = new LinkedList<_UserReviewPair>();
double gNorm, gNormOld = Double.MAX_VALUE;
int predL, trueL, counter = 0;
_Review doc;
_CoLinAdaptStruct user;
// collect the training/adaptation data
for (int i = 0; i < m_userList.size(); i++) {
user = (_CoLinAdaptStruct) m_userList.get(i);
for (_Review r : user.getReviews()) {
if (r.getType() == rType.ADAPTATION || r.getType() == rType.TRAIN)
// we will only collect the training or adaptation reviews
reviewlist.add(new _UserReviewPair(user, r));
}
}
// sort them by timestamp
Collections.sort(reviewlist);
for (_UserReviewPair pair : reviewlist) {
user = (_CoLinAdaptStruct) pair.getUser();
// test the latest model before model adaptation
if (m_testmode != TestMode.TM_batch) {
doc = pair.getReview();
predL = predict(doc, user);
trueL = doc.getYLabel();
user.getPerfStat().addOnePredResult(predL, trueL);
}
// in batch mode we will not accumulate the performance during adaptation
gradientDescent(user, m_initStepSize, 1.0);
// test the gradient only when we want to debug
if (m_displayLv > 0) {
gNorm = gradientTest();
if (m_displayLv == 1) {
if (gNorm < gNormOld)
System.out.print("o");
else
System.out.print("x");
}
gNormOld = gNorm;
if (++counter % 120 == 0)
System.out.println();
}
}
}
Aggregations