-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample2.m
54 lines (39 loc) · 1.38 KB
/
Example2.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
function Example2
%EXAMPLE2 Compute the accumulated measure a ttime T = 20.
times = zeros(1, 5);
Ns = zeros(1, 5);
for i = 1 : 5
% Load the matrix generated by Moebius.
Q = loadArm(sprintf('data/example2/Experiment_%d.arm', i));
n = size(Q, 1);
% Save the size of the model -- since these might change when we change
% the examples.
Ns(i) = n;
% We are interested in the accumulated measure at time 20
T = 20;
% This is the starting vector in the states
pi0 = zeros(1, n);
pi0(1) = 1;
% And we are interested in how much time we stay in the first state
v = zeros(n,1);
v(1:2:end) = 1;
% v = ones(n,1); v(1:2:end) = 0;
v = zeros(n,1);
% In this case it's easy to see that the reward will be this vector
% here.
v(4:2:end) = 1; v(end) = 1;
% This can be used to compute the reward
%for j = 1 : n
% if ~isempty(find(Q(j,:) == 0.1, 1))
% v(j) = 1;
% end
%end
% The following line might be uncommented to check that we are
% computing the right thing -- as of now we are interested in taking the timings.
f = funm_markov(pi0, Q, v, 'phi', T);
% Take the times
times(i) = timeit(@() funm_markov(pi0, Q, v, 'phi', T));
fprintf(' - N = %d, time: %e seconds (f = %e)\n', n, times(i), f);
end
dlmwrite('example2.dat', [ Ns', times' ], '\t');
end