(w, n, x, p, y)
| 66 | # w: updated model |
| 67 | # n: updated count |
| 68 | def update_w(w, n, x, p, y): |
| 69 | for i in x: |
| 70 | # alpha / (sqrt(n) + 1) is the adaptive learning rate heuristic |
| 71 | # (p - y) * x[i] is the current gradient |
| 72 | # note that in our case, if i in x then x[i] = 1 |
| 73 | w[i] -= (p - y) * alpha / (sqrt(n[i]) + 1.) |
| 74 | n[i] += 1. |
| 75 | |
| 76 | return w, n |
| 77 | |
| 78 | |
| 79 | # training and testing ####################################################### |