Skip to content

Commit

Permalink
Correcting few bug & time indices
Browse files Browse the repository at this point in the history
Not entirely sure of the t-1 dependence for UV factorization.
  • Loading branch information
krzakala committed Aug 12, 2015
1 parent fb561c3 commit f246285
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 215 deletions.
20 changes: 11 additions & 9 deletions LowRAMP_UV.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@

u_old=zeros(m,RANK);
v_old=zeros(n,RANK);
u_var=zeros(RANK,RANK);
v_var=zeros(RANK,RANK);
u_var=zeros(RANK,RANK);u_var_old=zeros(RANK,RANK);
v_var=zeros(RANK,RANK);v_var_old=zeros(RANK,RANK);

A_u=zeros(RANK,RANK);
B_u=zeros(m,RANK);
Expand All @@ -93,20 +93,21 @@
disp(PR);
old_free_nrg=-realmax('double');delta_free_nrg=0;


while ((diff>opt.conv_criterion)&&(t<opt.nb_iter))
%Keep old variable
A_u_old=A_u; A_v_old=A_v;
B_u_old=B_u; B_v_old=B_v;

%AMP iteration
B_u_new=(S*v)/sqrt(n)-u_old*v_var/(Delta);
B_u_new=(S*v)/sqrt(n)-u_old*v_var_old/(Delta);
A_u_new=v'*v/(n*Delta);
B_v_new=(S'*u)/sqrt(n)-v_old*(m*u_var/n)/(Delta);
B_v_new=(S'*u)/sqrt(n)-v_old*(m*u_var_old/n)/(Delta);
A_v_new=u'*u/(n*Delta);

%Keep old variables
u_old=u;
v_old=v;
u_old=u;u_var_old=u_var;
v_old=v;v_var_old=v_var;

%Iteration with fixed damping or learner one
pass=0;
Expand All @@ -128,8 +129,9 @@
end

[u,u_var,logu] = Fun_u(A_u,B_u);
[v,v_var,logv] = Fun_v(A_v,B_v);
[v,v_var,logv] = Fun_v(A_v,B_v);


%Compute the Free Entropy
minusDKL_u=logu+0.5*m*trace(A_u*u_var)+trace(0.5*A_u*u'*u)-trace(u'*B_u);
minusDKL_v=logv+0.5*n*trace(A_v*v_var)+trace(0.5*A_v*v'*v)-trace(v'*B_v);
Expand All @@ -139,10 +141,10 @@
free_nrg=(minusDKL_u+minusDKL_v+term_u+term_v+term_uv)/n;

if (t==0) delta_free_nrg=old_free_nrg-free_nrg;old_free_nrg=free_nrg; break; end
if (opt.damping>0) delta_free_nrg=old_free_nrg-free_nrg;old_free_nrg=free_nrg; break;end
if (opt.damping>=0) delta_free_nrg=old_free_nrg-free_nrg;old_free_nrg=free_nrg; break;end
%Otherwise adapative damping
if (free_nrg>old_free_nrg)
delta_free_nrg=old_free_nrg-free_nrg;old_free_nrg=free_nrg;
delta_free_nrg=old_free_nrg-free_nrg;
old_free_nrg=free_nrg;
pass=1;
else
Expand Down
190 changes: 0 additions & 190 deletions LowRAMP_UV_completion.m

This file was deleted.

12 changes: 7 additions & 5 deletions LowRAMP_XX.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
x=opt.signal+1e-4*randn(n,RANK);
end
x_old=zeros(n,RANK);
x_V=zeros(RANK,RANK);
x_V=zeros(RANK,RANK); x_V_old=zeros(RANK,RANK);


A=zeros(RANK,RANK);
B=zeros(n,RANK);
Expand All @@ -75,11 +76,12 @@
B_old=B;

%AMP iteration
B_new=(S*x)/sqrt(n)-x_old*x_V/(Delta);
B_new=(S*x)/sqrt(n)-x_old*x_V_old/(Delta);
A_new=x'*x/(n*Delta);

%Keep old variables
x_old=x;
x_V_old=x_V;

%Iteration with fixed damping or learner one
pass=0;
Expand All @@ -91,14 +93,14 @@

while (pass~=1)
if (t>0)
A=1./((1-damp)./A_old+damp./A_new);
A=(1-damp)*A_old+damp*A_new;
B=(1-damp)*B_old+damp*B_new;
else
A=A_new;
B=B_new;
end

[x,x_V,logZ] = Fun_a(A,B);%Community prior
[x,x_V,logZ] = Fun_a(A,B);

%Compute the Free Entropy
minusDKL=logZ+0.5*n*trace(A*x_V)+trace(0.5*A*x'*x)-trace(x'*B) ;
Expand All @@ -107,7 +109,7 @@
free_nrg=(minusDKL+term_x+term_xx)/n;

if (t==0) delta_free_nrg=old_free_nrg-free_nrg;old_free_nrg=free_nrg; break;end
if (opt.damping>0) delta_free_nrg=old_free_nrg-free_nrg;old_free_nrg=free_nrg;break;end
if (opt.damping>=0) delta_free_nrg=old_free_nrg-free_nrg;old_free_nrg=free_nrg;break;end
%Otherwise adapative damping
if (free_nrg>old_free_nrg)
delta_free_nrg=old_free_nrg-free_nrg;old_free_nrg=free_nrg;
Expand Down
2 changes: 1 addition & 1 deletion run_LowRAMP_UV.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Delta=1e-2;%Variance of the gaussian noise
RANK=3;%rank

fprintf(1,'Creating a signal of rank %d \n',RANK);
fprintf(1,'Creating a %dx%d signal of rank %d \n',m,n,RANK);
V = zeros(m,RANK);
for i=1:m
V(i,ceil(rand()*RANK))=1;
Expand Down
2 changes: 1 addition & 1 deletion run_LowRAMP_XX.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
pout = p - Delta/(RANK*sqrt(n));
pin = p + (1-1/RANK)*Delta/sqrt(n);

fprintf(1,'Creating a signal of rank %d \n',RANK);
fprintf(1,'Creating a %dx%d signal of rank %d \n',n,n,RANK);
X = zeros(n,RANK);
for i=1:n
X(i,ceil(rand()*RANK))=1;
Expand Down
13 changes: 4 additions & 9 deletions run_PCA.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
path(path,'./Subroutines');
m=500;n=100;%size of the vector U and V
m=1000;n=1000;%size of the vector U and V
Delta=1e-4;%Variance of the gaussian noise
RANK=3;%rank

fprintf(1,'Creating a signal of rank %d \n',RANK);
fprintf(1,'Creating a %dx%d signal of rank %d \n',m,n,RANK);
U = randn(m,RANK);
V = randn(n,RANK);

Expand All @@ -20,16 +20,11 @@
opt.damping=-1;%adaptive damping
opt.prior_u='Gauss'; opt.signal_u=U;
opt.prior_v='Gauss'; opt.signal_v=V;
opt.damping=0.2;
opt.verbose_n=1;
tic
[ u_ample,v_ample ] = LowRAMP_UV(S,Iinv,RANK,opt) ;
toc;
disp('Squared Reconstruction error');
disp('Squared Reconstruction error on the matrix');
mean2((u_ample*v_ample'/sqrt(n)-Y).^2)

tic
[ u_amp,v_amp ] = LowRAMP_UV_completion(S,Iinv,ones(size(S)),RANK,opt) ;
toc
disp('Squared Reconstruction error');
mean2((u_amp*v_amp'/sqrt(n)-Y).^2)

0 comments on commit f246285

Please sign in to comment.