-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrownian_bridge_demo.m
103 lines (59 loc) · 1.59 KB
/
brownian_bridge_demo.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function [] = brownian_bridge_demo()
% Author: Ari Pakman
%% prepare parameters to call sampler
T=100;
sigma2=1; %noise level
V0 = -40;
VT=-20;
L = 15500;
% low noise
X1s=bb_call_sampler(T,sigma2,V0,VT,L);
% high noise
sigma2=5;
X2s=bb_call_sampler(T,sigma2,V0,VT,L);
B=500; % burn-in samples to discard
%% plot
col=[1 0.78 0.80]; % pinkish
fig=figure(85);
clf
hold on
subplot(1,2,1);
hold on
qu1=quantile(X1s(:,B:end),.25,2);
qu2=quantile(X1s(:,B:end),.5,2);
qu3=quantile(X1s(:,B:end),.75,2);
lower = [V0 qu1' VT];
median = [V0 qu2' VT];
higher = [V0 qu3' VT];
sample_path1= [V0 X1s(:,3000)' VT];
plot(0:T, sample_path1, '--k', 'MarkerSize',6)
ciplot(lower,higher, 0:T,col);
plot(0:T, sample_path1, '--k', 'MarkerSize',6)
plot(0:T,median, 'b', 'MarkerSize',6)
ylim([V0-8 VT]);
box
xl=xlabel('t');
set(xl, 'FontName', 'Arial', 'FontSize', 12);
xl=legend( 'Sample path', '.25, .5 and .75 quantiles');
set(xl, 'FontName', 'Arial', 'FontSize', 7, 'Location', 'NorthWest');
subplot(1,2,2);
cla
hold on
qu1=quantile(X2s(:,B:end),.25,2);
qu2=quantile(X2s(:,B:end),.5,2);
qu3=quantile(X2s(:,B:end),.75,2);
lower = [V0 qu1' VT];
median = [V0 qu2' VT];
higher = [V0 qu3' VT];
sample_path2= [V0 X2s(:,3100)' VT];
plot(0:T, sample_path2, '--k', 'MarkerSize',6)
ciplot(lower,higher, 0:T,col);
plot(0:T,median, 'b', 'MarkerSize',6)
ylim([V0-8 VT]);
plot(0:T, sample_path2, '--k', 'MarkerSize',6)
xl=xlabel('t');
set(xl, 'FontName', 'Arial', 'FontSize', 12);
xl=legend( 'Sample path', '.25, .5 and .75 quantiles');
set(xl, 'FontName', 'Arial', 'FontSize', 7, 'Location', 'NorthWest');
box
end