IntArrayList users = (IntArrayList) datamodel.getUserIDs();
for (int u = 0; u < users.size(); u++) {
// initialize sumQE
// why use it???
PreferenceArray sumQE = new GenericUserPreferenceArray(
parameter_k);
// get userid
int userid = users.get(u);
nu = datamodel.getNumOfItemsRateByUser(userid);
Vector tmpitems = datamodel.getVectorOfItems(userid);
// calculate temp_Pu += sigma(yi)/sqrt(Nu);
PreferenceArray tempUserFactor = puTemp.get(userid);
PreferenceArray UserFactor = pusers.get(userid);
for (int k = 0; k < parameter_k; k++) {
Iterator<Element> itor = tmpitems.iterateNonZero();
double sum = 0.0;
while (itor.hasNext()) {
Element e = itor.next();
int itemid = e.index();
sum = sum + y.get(itemid).getValue(k);
}
float temp = (float) (UserFactor.getValue(k) + sum
/ Math.sqrt(nu));
tempUserFactor.setValue(k, temp);
sumQE.setValue(k, 0.0f);
}
// iterate to deal with items
Iterator<Element> itor = tmpitems.iterateNonZero();
while (itor.hasNext()) {
Element e = itor.next();
int itemid = e.index();
// actual rating and estimated rating
double rui = datamodel.getPreferenceValue(userid, itemid);
double pui = predictPreference(userid, itemid);
double eui = rui - pui;
rmse += eui * eui;
n++;
// update bias values
double tmp = busers.get(userid) + gamma1
* (eui - lamda6 * busers.get(userid));
busers.put(userid, tmp);
tmp = bitems.get(itemid) + gamma1
* (eui - lamda6 * bitems.get(itemid));
bitems.put(itemid, tmp);
// update user factor and movie factor vectors
PreferenceArray ItemFactor = qitems.get(itemid);
UserFactor = pusers.get(userid);
PreferenceArray puTempFactor = puTemp.get(userid);
for (int k = 0; k < parameter_k; k++) {
// user factor
float preval = UserFactor.getValue(k);
float temp = ItemFactor.getValue(k);
preval = (float) (preval + gamma2
* (eui * temp - lamda7 * preval));
UserFactor.setValue(k, preval);
// item factor
preval = ItemFactor.getValue(k);
temp = puTempFactor.getValue(k);
preval = (float) (preval + gamma2
* (eui * temp - lamda7 * preval));
ItemFactor.setValue(k, preval);
// Accumulate information for gradient steps on y_i
preval = sumQE.getValue(k);
preval += eui * ItemFactor.getValue(k);
sumQE.setValue(k, preval);
// // implicit factor test;
// PreferenceArray yFactor = y.get(itemid);
// preval = yFactor.getValue(k);
// preval += gamma2
// * (eui*ItemFactor.getValue(k)/Math.sqrt(nu) - lamda7
// * preval);
// yFactor.setValue(k, preval);
}
}
// implicit factor
itor = tmpitems.iterateNonZero();
while (itor.hasNext()) {
Element e = itor.next();
int itemid = e.index();
PreferenceArray yFactor = y.get(itemid);
for (int k = 0; k < parameter_k; k++) {
float preval = yFactor.getValue(k);
preval = (float) (preval + gamma2
* (sumQE.getValue(k) / Math.sqrt(nu) - lamda7
* preval));
yFactor.setValue(k, preval);
}
}
}