(w, n, x, p, y)
| 82 | # w: updated model |
| 83 | # n: updated count |
| 84 | def update_w(w, n, x, p, y): |
| 85 | for i in x: |
| 86 | # alpha / (sqrt(n) + 1) is the adaptive learning rate heuristic |
| 87 | # (p - y) * x[i] is the current gradient |
| 88 | # note that in our case, if i in x then x[i] = 1 |
| 89 | w[i] -= (p - y) * alpha / (sqrt(n[i]) + 1.) |
| 90 | n[i] += 1. |
| 91 | |
| 92 | return w, n |
| 93 | |
| 94 | |
| 95 | # training and testing ####################################################### |