Variational Bayes for GLMAR model - Update gamma and get w_dev, wk_mean FORMAT [slice] = spm_vb_gamma (Y,slice) Y [T x N] time series slice data structure containing the following fields: %W% Will Penny and Nelson Trujillo-Barreto %E%
0001 function [slice] = spm_vb_gamma (Y,slice) 0002 % Variational Bayes for GLMAR model - Update gamma 0003 % and get w_dev, wk_mean 0004 % FORMAT [slice] = spm_vb_gamma (Y,slice) 0005 % 0006 % Y [T x N] time series 0007 % slice data structure containing the following fields: 0008 % 0009 % %W% Will Penny and Nelson Trujillo-Barreto %E% 0010 0011 if slice.verbose 0012 disp('Updating gamma'); 0013 end 0014 0015 N = slice.N; 0016 k = slice.k; 0017 k = slice.k; 0018 0019 Bk = kron(diag(slice.mean_alpha),slice.D); 0020 B = slice.Hw*Bk*slice.Hw'; 0021 0022 for n=1:N, 0023 % Block matrices Bnn [k x k] and Bni [k x k*(N-1)] 0024 block_n = [(n-1)*k+1:n*k]; 0025 Bnn = B(block_n,block_n); 0026 % Equation 17 in paper VB2 0027 for j=1:k, 0028 slice.gamma(j,n)= 1-slice.w_cov{n}(j,j)*Bnn(j,j); 0029 slice.b(j,n)=Bnn(j,j); 0030 end 0031 % Record Standard Deviation of parameter estimates 0032 % to be used in Taylor series approximation to posterior 0033 slice.w_dev(:,n) = sqrt(diag(slice.w_cov{n})); 0034 end 0035 slice.gamma_tot=sum(slice.gamma,2); 0036 slice.wk_mean = reshape(slice.w_mean,k,N);