-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlottingSamplesFromMCMC.m
76 lines (54 loc) · 1.47 KB
/
PlottingSamplesFromMCMC.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function PlottingSamplesFromMCMC()
% Code used to 95% credible intervals for fits to sine wave protocol from
% 1000 samples from MCMC chain as quoted in Model Calibration Section 2.2
% in the manuscript
model = 'hh';
protocol = {'sine_wave'};
exp_ref = '16713110';
temperature = 21.4;
seed=1;
rand('seed',seed)
[simulated_parameters,model_type] =modeldata(model);
cd ../MCMCResults
pathToFolder = '.';
files = dir(fullfile(pathToFolder,'*'));
C=[];
L=[];
% Identifies MCMC chain and likelihood values for experiment
for i = 1:numel(files)
k = regexp(files(i).name,['MCMCChain_',exp_ref,'_',model,'_',protocol{1}]);
if k>=1
C=importdata(files(i).name);
S=files(i).name;
mS = strrep(S, 'MCMCChain', 'MCMCLikelihood');
L=importdata(mS);
end
end
cd ..
cd Protocols
V=importdata([protocol{1},'_protocol.mat']);
cd ..
[i,v]=max(L);
best= C(v,:);
cd Code
B=SimulatingData(model_type,protocol,best,V,temperature);
for j =1:1000
n=randi(length(C));
I(:,j)=SimulatingData(model_type,protocol,C(n,:),V,temperature);
LL(j) = L(n);
end
[tmp,ind]=sort(LL);
J=I(ind,:);
% Calculate 95% credible intervals
m=floor(0.025*length(LL));
J=I(:,m:end-m);
plot(max(J,[],2))
hold on
plot(min(J,[],2))
hold on
plot(B,'K')
plot(abs(max(J,[],2)-min(J,[],2)))
% 95% credible interval in absolute terms
max(abs(max(J,[],2)-min(J,[],2)))
% 95% credible interval as percentage of current
max(abs(max(J,[],2)-min(J,[],2))./B)