-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_bias_vs_time.m
78 lines (61 loc) · 1.84 KB
/
example_bias_vs_time.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
function [Time,Prob,Err] = example_bias_vs_time()
% QSN package example
%
% Time for max. probability given bias for ring
% SPDX-FileCopyrightText: Copyright (C) 2011-2019, 2022 Frank C Langbein <frank@langbein.org>, Cardiff University
% SPDX-FileCopyrightText: Copyright (C) 2011-2019, 2022 SM Shermer <lw1660@gmail.com>, Swansea University
% SPDX-License-Identifier: AGPL-3.0-or-later
N = 13; % Ring size
B = [0 10.^[1:6]]; % Bias range
Tmax = 100000; % Max time
Tstep = 0.001; % Time step
Trange = 100; % Length of interval for step-wise check until Tmax
target = 6; % Target
bias_pos = 10; % Position for bias
Time = [];
Prob = [];
Err = [];
n = 1;
for k = 1:size(B,2)
bias = zeros(1,N);
bias(1,bias_pos) = B(k);
ring = qsn.QSN('ring',N,'XX',bias)
p_max = ring.prob();
tr_prob = [];
tr_time = [];
t = -1;
p = -1;
start_time = 0;
while start_time < Tmax
range_time = start_time:Tstep:start_time+Trange;
tr = ring.trace(1,target,range_time);
[pp,ind] = max(tr);
tr_prob = [tr_prob pp pp];
tr_time = [tr_time start_time start_time+Trange];
if pp > p
p = pp;
t = range_time(ind);
end
subplot(2,2,4);
plot(tr_time,tr_prob,'r');
title(sprintf('Current trace envelope, bias: %g',B(k)));
pause(0.1);
start_time = start_time + Trange;
end
Time(k) = t;
Prob(k) = p;
Err(k) = abs(p_max(1,target) - p);
lB = log10(B(1:k));
lB(1) = 0;
subplot(2,2,1);
plot(lB,Time(1:k),'g');
title('Time vs. log(Bias)');
subplot(2,2,2);
plot(lB,Prob(1:k),'g');
title('Probability vs. log(Bias)');
subplot(2,2,3);
plot(lB,Err(1:k),'r');
title('|p-max - p| vs. log(Bias)');
pause(0.1);
end
end