I am trying to implement an algorithm for a Social Recommender System. The algorithm predicts the rating given to an item by a user, using the global reputation of the user and a similarity matrix. I am using matrix factorization to find the values of latent factors of user and item. I am using gradient descent algorithm. I have taken learning rate=0.0001, no of latent factors=10.
The value of cost function after each iteration is not following any pattern i.e. i am getting random values of cost function after each iteration.
What could be the possible reasons for this?
here is the algorithm
function [U,V,J] = algorithm(I,C,A,F,sim,n,m)
[U,V,k,delta,x1,x2]=parameters(n,m);
J=zeros(100,1);
count=1;
ntemp=zeros(n,k);
mtemp=zeros(m,k);
Jprev=Inf;
Jcurr=costFunc(U,V,I,C,A,sim,F,n,m,x1,x2);
J(count)=Jcurr;
count=count+1;
temp0=zeros(1,k);
temp1=zeros(1,k);
while(count<=100)
%Jprev-Jcurr>(10^(-6)) %convergence condition
for i=1:n
for j=1:m
temp0=temp0+(I(i,j)*C(i)*((U(i,:)*V(j,:)')-A(i,j)))*V(j,:);
end
for p=1:n
if F(i,p)==1
temp1=temp1+sim(i,p)*(U(i,:)-U(p,:));
end
end
ntemp(i,:)=U(i,:)-delta*(temp0+(U(i,:)*x1)+(temp1*x2));
end
temp0=zeros(1,k);
temp1=zeros(1,k);
for i=1:m
for j=1:n
temp0=temp0+(I(j,i)*C(j)*((U(j,:)*V(i,:)')-A(j,i)))*U(j,:);
end
mtemp(i,:)=V(i,:)-delta*(temp0+(x1*V(i,:)));
end
U=ntemp;
V=mtemp;
Jprev=Jcurr;
Jcurr=costFunc(U,V,I,C,A,sim,F,n,m,x1,x2);
J(count)=Jcurr;
count=count+1;
end
end
here is the cost function
function [temp0,temp1,J] = costFunc(U,V,I,C,A,sim,F,n,m,x1,x2)
J=0;
temp0=0;
temp1=0;
for i=1:n
for j=1:m
temp1=temp1+I(i,j)*C(i)*((A(i,j)-U(i,:)*V(j,:)')^2);
end
end
for i=1:n
for j=i:n
if F(i,j)==1
temp0=temp0+sim(i,j)*norm(U(i,:)-U(j,:),'fro');
end
end
end
J=temp1+x2*temp0+x1*(norm(U,'fro')+norm(V,'fro'));
J=J/2;
end
here is the parameter function
function [U,V,k,delta,x1,x2] = parameters(n,m)
k=10; %no of latent factors
U=rand(n,k); %user latent factor matrix
V=rand(m,k); %item latent factor matrix
delta=0.00001; %learning rate
x1=0.001; %regularization parameter
x2=0.001; %regularization parameter for similarity
end