-
Notifications
You must be signed in to change notification settings - Fork 0
/
mc_alter.m
45 lines (39 loc) · 868 Bytes
/
mc_alter.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
function [r, rr] = mc_alter(P, mu, sigma, T, k, dt, N)
p_inf = (P')^50;
p_inf = p_inf(:, 1);
r = zeros(T, 1);
for j = 1:N
if rand() <= p_inf(1)
r(1, j) = 0;
else
r(1, j) = 1;
end
end
r = zeros(T, N);
rr = zeros(floor(T/dt), 1);
cur = 0;
for t = 2:T
for j = 1:N
if r(t-1, j) == 0
if rand() <= P(1, 1)
continue
else
r(t, j) = exp(randn()*sigma + mu);
end
else
if rand() <= P(2, 1)
continue
else
r(t, j) = exp(randn()*sigma + mu);
end
end
end
if mod(t, dt) == 0
tmp = r(cur+1:cur+dt, :);
[tmp2, tmpr] = large_value_update(tmp, k);
rr(1 + floor(cur/dt)) = tmpr;
r(cur+1:cur+dt, :) = tmp2;
cur = cur + dt;
end
end
end