Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class GBPRRecommender extends MatrixFactorizationRecommender {
protected void setup() throws LibrecException {
super.setup();

regBias = conf.getDouble("rec.bias.regularization", 0.01);

itemBiases = new DenseVector(numItems);
itemBiases.init();

Expand All @@ -78,7 +80,7 @@ protected void setup() throws LibrecException {
}

@Override
protected void trainModel() throws LibrecException {
protected void trainModel() throws LibrecException {
for (int iter = 1; iter <= numIterations; iter++) {

loss = 0.0d;
Expand Down Expand Up @@ -141,9 +143,11 @@ protected void trainModel() throws LibrecException {
// update bi, bj
double posBiasValue = itemBiases.get(posItemIdx);
itemBiases.add(posItemIdx, learnRate * (deriValue - regBias * posBiasValue));
loss += regBias * posBiasValue * posBiasValue;

double negBiasValue = itemBiases.get(negItemIdx);
itemBiases.add(negItemIdx, learnRate * (-deriValue - regBias * negBiasValue));
loss += regBias * negBiasValue * negBiasValue;

// update Pw
double averageWeight = 1.0 / groupSet.size();
Expand All @@ -158,6 +162,8 @@ protected void trainModel() throws LibrecException {
double deltaGroup = rho * averageWeight * posItemFactorValue + (1 - rho) * delta * posItemFactorValue - delta * negItemFactorValue;
tempUserFactors.add(groupUserIdx, factorIdx, learnRate * (deriValue * deltaGroup - regUser * groupUserFactorValue));

loss += regUser * groupUserFactorValue * groupUserFactorValue;

sumGroup[factorIdx] += groupUserFactorValue;
}
}
Expand All @@ -170,9 +176,11 @@ protected void trainModel() throws LibrecException {

double posDelta = rho * averageWeight * sumGroup[factorIdx] + (1 - rho) * userFactorValue;
tempItemFactors.add(posItemIdx, factorIdx, learnRate * (deriValue * posDelta - regItem * posItemFactorValue));

loss += regItem * posItemFactorValue * posItemFactorValue;

double negDelta = -userFactorValue;
tempItemFactors.add(negItemIdx, factorIdx, learnRate * (deriValue * negDelta - regItem * negItemFactorValue));
loss += regItem * negItemFactorValue * negItemFactorValue;
}
}

Expand Down