Example #1
0
 public boolean update() {
   zeroFill(im_grad);
   zeroFill(um_grad);
   int cnt = 0;
   iter.reset();
   while (iter.hasNext()) {
     cnt++;
     Rating r = iter.next();
     double rdiff = r.rate - product(userMatrix[r.user], itemMatrix[r.movie]);
     for (int f = 0; f < factorNum; f++) {
       um_grad[r.user][f] += -rdiff * itemMatrix[r.movie][f] + userReg * userMatrix[r.user][f];
       im_grad[r.movie][f] += -rdiff * userMatrix[r.user][f] + itemReg * itemMatrix[r.movie][f];
     }
   }
   while (this.learningRate > 1e-10) {
     test_update(um_grad, im_grad);
     double next_like = likelihood(um_next, im_next);
     System.out.println(cur_like + " " + next_like + " " + learningRate);
     if (next_like > cur_like) {
       next();
       this.learningRate *= 1.25;
       this.cur_like = next_like;
       return true;
     } else {
       this.learningRate *= 0.5;
     }
   }
   return false;
 }
Example #2
0
 public double likelihood(double users[][], double items[][]) {
   double ret = 0.0;
   iter.reset();
   while (iter.hasNext()) {
     Rating r = iter.next();
     double rdiff = r.rate - product(users[r.user], items[r.movie]);
     ret += rdiff * rdiff;
   }
   double reg = userReg * norm(users) + itemReg * norm(items);
   return -(ret + reg);
 }