Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [r] = baseline2(u,v,au0,av0,bu0,bv0,bbu0,bbv0,abu0,abv0,al0,bl0,train,N,nbu,nbv)
- %UNTITLED3 Summary of this function goes here
- % Detailed explanation goes here
- rsave=0;
- r=0;
- nbatch=size(train,1)/N;
- sv=size(v,1);
- su=size(u,1);
- alu=gamrnd(au0,bu0);
- alv=gamrnd(av0,bv0);
- albu=gamrnd(abu0,bbu0);
- albv=gamrnd(abv0,bbv0);
- lam=gamrnd(al0,bl0);
- d=size(u,2);
- bu=0.01*randn(nbu);
- bv=0.01*randn(nbv);
- %ub=double(train((batch-1)*N+1:batch*N,4));
- %vb=double(train((batch-1)*N+1:batch*N,5));
- %rb=double(train((batch-1)*N+1:batch*N,3));
- ub=train(:,4);
- vb=train(:,5);
- rb=train(:,3);
- listub=unique(ub); % List of users in the batch
- listvb=unique(vb); % List of items in the batch
- nbub=size(listub,1); % Number of different users in the batch
- nbvb=size(listvb,1); % Number of diferent items in the batch
- for i=1:350
- clear ru;
- clear rv;
- rv=randsample(listvb,nbvb); % To choose the items in a random order
- for j=1:nbvb
- clear mu;
- clear sigma;
- sigma=zeros(d,d);
- mu=0;
- f=find(vb==rv(j));
- for k=1:size(f,1)
- sigma=sigma+u(ub(k),:)'*u(ub(k),:);
- end
- sigma=inv(alv*eye(d)+lam*sigma);
- mu=sigma*lam*(u(ub(f),:)'*(rb(f)-bu(ub(f))-bv(vb(f))));
- v(rv(j),:)=mvnrnd(mu,sigma); % We sample the items features according to (8)
- clear mu;
- clear sigma;
- sigma=1/(albv+size(f,1)*lam);
- mu=sigma*lam*sum(rb(f)-diag(u(ub(f),:)*v(vb(f),:)')-bu(ub(f)));
- bv(rv(j))=normrnd(mu,sigma); % We sample the items' biases according to (9)
- end
- ru=randsample(listub,nbub); % To choose the users in a random order
- for j=1:nbub
- clear mu;
- clear sigma;
- sigma=zeros(d,d);
- mu=0;
- f=find(ub==ru(j));
- for k=1:size(f,1)
- sigma=sigma+v(vb(k),:)'*v(vb(k),:);
- end
- sigma=inv(alu*eye(d)+lam*sigma);
- mu=sigma*lam*(v(vb(f),:)'*(rb(f)-bv(vb(f))-bu(ub(f))));
- u(ru(j),:)=mvnrnd(mu,sigma); % We sample the users features according to (8)
- clear mu;
- clear sigma;
- sigma=1/(albu+size(f,1)*lam);
- mu=sigma*lam*sum(rb(f)-diag(u(ub(f),:)*v(vb(f),:)')-bv(vb(f)));
- bu(ru(j))=normrnd(mu,sigma); % We sample the users' biases according to (9)
- end
- alu=gamrnd(au0+nbub*d/2,bu0+sum(sum(u(listub,:).^2))/2); % We sample the priors according to (10),(11) and (12)
- alv=gamrnd(av0+nbvb*d/2,bv0+sum(sum(v(listvb,:).^2))/2);
- albu=gamrnd(abu0+nbub/2,bbu0+sum(bu(listub).^2)/2);
- albv=gamrnd(abv0+nbvb/2,bbv0+sum(bv(listvb).^2)/2);
- lam=gamrnd(al0+size(rb,1)/2,bl0+sum((rb-diag(u(ub,:)*v(vb,:)')-bu(ub)-bv(vb)).^2));
- if (i>50)
- rsave=rsave+u*v'+repmat(bu,1,nbvb)+repmat(bv',nbub,1);
- r=1/(i-50)*rsave;
- end
- i
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement