Skip to content

Commit

Permalink
Doc: adjust help text and fix mlint.
Browse files Browse the repository at this point in the history
SVN r8160
  • Loading branch information
gllmflndn committed Oct 1, 2021
1 parent 43c91fb commit 46a13f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 43 deletions.
31 changes: 13 additions & 18 deletions spm_BMS_F.m
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
function [F_samp,F_bound] = spm_BMS_F (alpha,lme,alpha0)
function [F_samp,F_bound] = spm_BMS_F(alpha,lme,alpha0)
% Compute two lower bounds on model evidence p(y|r) for group BMS
% FORMAT [F_samp,F_bound] = spm_BMS_F(alpha,lme,alpha0)
%
% FORMAT [F_samp,F_bound] = spm_BMS_smpl_me (alpha,lme,alpha0)
%
% INPUT:
% alpha parameters of p(r|y)
% lme array of log model evidences
% alpha - parameters of p(r|y)
% lme - array of log model evidences
% rows: subjects
% columns: models (1..Nk)
% alpha0 priors of p(r)
% alpha0 - priors of p(r)
%
% OUTPUT:
% F_samp - sampling estimate of <ln p(y_n|r>
% F_bound - lower bound on lower bound of <ln p(y_n|r>
% F_samp - sampling estimate of <ln p(y_n|r)>
% F_bound - lower bound on lower bound of <ln p(y_n|r)>
%
% REFERENCE: See appendix in
% Reference:
% Stephan KE, Penny WD, Daunizeau J, Moran RJ, Friston KJ
% Bayesian Model Selection for Group Studies. NeuroImage (under review)
% Bayesian Model Selection for Group Studies. Neuroimage 2009 46(4):1004-17
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Copyright (C) 2008-2021 Wellcome Centre for Human Neuroimaging

% Will Penny
% $Id: spm_BMS_F.m 2507 2008-11-30 14:45:22Z klaas $
% $Id: spm_BMS_F.m 8160 2021-10-01 09:42:13Z guillaume $


alpha0 = sort(alpha0);
if alpha0(1) ~= alpha0(end)
error('Error in function spm_BMS_F: alpha0 should have identical values.')
error('alpha0 should have identical values.')
end
alpha0 = alpha0(1);

Expand All @@ -39,12 +36,10 @@

K = length(alpha);
F = 0;
for k = 1:K,
for k = 1:K
F = F - (alpha(k) - alpha0)*psi_diff(k) + gm(k);
end
F = F - gammaln(a_sum);

F_bound = F + s_bound;
F_samp = F + s_samp;

return
45 changes: 20 additions & 25 deletions spm_BMS_F_smpl.m
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
function [s_samp,s_bound] = spm_BMS_F_smpl (alpha,lme,alpha0)
% Get sample and lower bound approx. for model evidence p(y|r)
% in group BMS; see spm_BMS_F.
function [s_samp,s_bound] = spm_BMS_F_smpl(alpha,lme,alpha0)
% Get sample and lower bound approx. for model evidence p(y|r) in group BMS
% FORMAT [s_samp,s_bound] = spm_BMS_F_smpl(alpha,lme,alpha0)
%
% FORMAT [s_samp,s_bound] = spm_BMS_F_smpl (alpha,lme,alpha0)
%
% REFERENCE: See appendix in
% See spm_BMS_F.m for details.
%
% Reference:
% Stephan KE, Penny WD, Daunizeau J, Moran RJ, Friston KJ
% Bayesian Model Selection for Group Studies. NeuroImage (under review)
% Bayesian Model Selection for Group Studies. Neuroimage 2009 46(4):1004-17
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Copyright (C) 2008-2021 Wellcome Centre for Human Neuroimaging

% Will Penny
% $Id: spm_BMS_F_smpl.m 2626 2009-01-20 16:30:08Z maria $
% $Id: spm_BMS_F_smpl.m 8160 2021-10-01 09:42:13Z guillaume $


% prevent numerical problems
max_val = log(realmax('double'));
for i=1:size(lme,1),
lme(i,:) = lme(i,:) - mean(lme(i,:));
for k = 1:size(lme,2),
lme(i,k) = sign(lme(i,k)) * min(max_val,abs(lme(i,k)));
end
for i=1:size(lme,1)
lme(i,:) = lme(i,:) - mean(lme(i,:));
for k = 1:size(lme,2)
lme(i,k) = sign(lme(i,k)) * min(max_val,abs(lme(i,k)));
end
end

% Number of samples per alpha bin (0.1)
Expand All @@ -30,16 +30,16 @@
% (see Dirichlet entry in Wikipedia or Ferguson (1973) Ann. Stat. 1,
% 209-230)
Nk = length(alpha);
for k = 1:Nk,
for k = 1:Nk
alpha_samp(:,k) = spm_gamrnd(alpha(k),1,Nsamp,1);
end

Ni = size(lme,1);
for i = 1:Ni,
for i = 1:Ni
s_approx(i) = sum((alpha./sum(alpha)).*lme(i,:));

s(i) = 0;
for n = 1:Nsamp,
for n = 1:Nsamp
s(i) = s(i) + si_fun(alpha_samp(n,:),lme(i,:));
end
s(i) = s(i)/Nsamp;
Expand All @@ -49,16 +49,11 @@

s_samp = sum(s);

return


%=========================================================================
function [si] = si_fun (alpha,lme)
%==========================================================================
function [si] = si_fun(alpha,lme)
% Check a lower bound
% FORMAT [si] = si_fun (alpha,lme)
% FORMAT [si] = si_fun(alpha,lme)

esi = sum((exp(lme).*alpha)/sum(alpha));
si = log(esi);

return

0 comments on commit 46a13f6

Please sign in to comment.