Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simultaneously update U and V, and U[i] multiplication on dV like described in paper #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions climf.py
Expand Up @@ -54,7 +54,7 @@ def objective(data,U,V,lbda):
F += log(1-g(f[k]-f[j]))
return F

def update(data,U,V,lbda,gamma):
def update(data,Uo,Vo,lbda,gamma):
"""update user/item factors using stochastic gradient ascent
params:
data : scipy csr sparse matrix containing user->(item,count)
Expand All @@ -63,18 +63,22 @@ def update(data,U,V,lbda,gamma):
lbda : regularization constant lambda
gamma: learning rate
"""
U = Uo.copy()
V = Vo.copy()

for i in xrange(len(U)):
dU = -lbda*U[i]
f = precompute_f(data,U,V,i)
for j in f:
dV = g(-f[j])-lbda*V[j]
dV = g(-f[j])
for k in f:
dV += dg(f[j]-f[k])*(1/(1-g(f[k]-f[j]))-1/(1-g(f[j]-f[k])))*U[i]
V[j] += gamma*dV
dV += dg(f[j]-f[k])*(1/(1-g(f[k]-f[j]))-1/(1-g(f[j]-f[k])))
dV = dV*U[i]-lbda*V[j]
Vo[j] += gamma*dV
dU += g(-f[j])*V[j]
for k in f:
dU += (V[j]-V[k])*dg(f[k]-f[j])/(1-g(f[k]-f[j]))
U[i] += gamma*dU
Uo[i] += gamma*dU

def compute_mrr(data,U,V,test_users=None):
"""compute average Mean Reciprocal Rank of data according to factors
Expand Down