The Optimization for my Recommender system:
min|| R - XY ||
R: Ratingmatrix
X: UserxFaktor
Y: FaktorxItem
stops working when i increase the size of the input. Just for clarification the code in short:
k = 3
n = 10 #5
m= 50 #10
R=np.array(np.arange(n*m)).reshape(n, m)
Z0 = np.array(np.random.random(n*k+k*m))
def whatineed (Z):
return np.linalg.norm(R - np.dot(Z[:(n*k)].reshape(n,k),Z[(n*k):].reshape(k,m)))
def VectorizeX(Matrix):
i, j = Matrix.shape
return (Matrix.reshape((i * j, 1), order='C'))
def VectorizeY(Matrix):
i, j = Matrix.shape
return (Matrix.reshape((i * j, 1), order='C'))
def gradZ(Z):
Xk = Z[:(n*k)].reshape((n,k), order='C')
Yk = Z[(n*k):].reshape((k,m), order='C')
grad_X = -np.dot(R - np.dot(Xk, Yk), Yk.T)
grad_Y = -np.dot(Xk.T, R - np.dot(Xk, Yk))
return np.concatenate((VectorizeX(grad_X), VectorizeY(grad_Y)), axis=0)
A = minimize(fun=whatineed, x0=Z0, jac=gradZ, method='L-BFGS-B', options={'disp': 1})
X = A.x[:(n*k)].reshape(n,k)
Y = A.x[(n*k):].reshape(k,m)
print(np.linalg.norm(R - np.dot(X,Y)))
the commented n, m are one example where it still works (GREAT). and then all of the sudden nothing. Below the error message
ABNORMAL_TERMINATION_IN_LNSRCH
Line search cannot locate an adequate point after 20 function
and gradient evaluations. Previous x, f and g restored.
Possible causes: 1 error in function or gradient evaluation;
2 rounding error dominate computation.
Cauchy time 0.000E+00 seconds.
Subspace minimization time 0.000E+00 seconds.
Line search time 0.000E+00 seconds.
Total User time 0.000E+00 seconds.
What caused this issue and what is the workaround?