load ./Eg1simu.mat
who
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Eg1: MCMC sample and Log marginal likelihood estimation %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[GV]=makedecompgraph(adj_v_true);
[Gu]=makedecompgraph(adj_u_true);
%Set up Hyperparameters
[q,p,m]=size(Y_simu);
b=3; d=3; %D.F. of Prior U and V,
B=(b+2)*1*eye(q);
D=(d+2)*1*eye(p); %Prior Location matrix
burnin=2000;nmc=2000;
[U_afterburn,V_afterburn,K_u_afterburn,K_v_afterburn,loc_u_afterburn,loc_v_afterburn,v11,df_v11,log_marginal,log_marginal_u]=matrix_sample_logmargin(Y_simu,b,B,d,D,GV,Gu,adj_v_true,burnin,nmc);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%% Eg 1 Graph Search %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b=3; d=3; %D.F of Prior U and V
B=(b+2)*1*eye(q);
D=(d+2)*1*eye(p); %Prior Location matrix
indmx_v= reshape([1:p^2],p,p); % Uppermatrix index
upperind_v=indmx_v(triu(indmx_v,1)>0);
indmx_u= reshape([1:q^2],q,q); % Uppermatrix index
upperind_u=indmx_u(triu(indmx_u,1)>0);
adjv_init=eye(p);
adju_init=eye(q);
burnin=10;nmc=10; nmh=3
beta_v=2/(p-1);beta_u=2/(q-1); tedge_v=p*(p-1)/2;tedge_u=q*(q-1)/2;
[adjv_save,adju_save,log_post dec_decomp]=matrix_metroplis_d(Y_simu,adjv_init,adju_init,b,B,d,D,beta_v,beta_u,upperind_v,upperind_u,burnin,nmc,nmh);