-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbcmdp_plot_episode.m
67 lines (62 loc) · 1.79 KB
/
bcmdp_plot_episode.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
%plots the history of a given episode
function bcmdp_plot_episode(history,episode,bc,mdp)
%history will only have Xs and As and Rs...
X = history.Xs{episode};
A = history.As{episode};
R = history.Rs{episode};
if strcmpi(mdp.run_type,'dynamics')
Xdiff_ = abs(X(:,6:end)-X(:,1:end-5));
Xdiff = Xdiff_'*ones(bc.n,1);
j_end = find(Xdiff == 0,1,'first');
for i = 1:bc.n
%distinguish controlled agents
if i <= mdp.m
plot(X(i,1:j_end),':','Color',0.25+0.5*rand(3,1));
else
plot(X(i,1:j_end),'Color',0.25+0.5*rand(3,1));
end
hold on
end
title('Last Run');
xlabel('Time Steps');
ylabel('Opinion State, s');
hold off
else
% hold on
if strcmpi(mdp.reward_fn,'const')
j_end = find(R == 1,1,'first');
else
j_end = find(R == 0,1,'first');
end
if isempty(j_end)
j_end = bc.T;
end
subplot(3,1,1);
for i = 1:bc.n
%distinguish controlled agents
if i <= mdp.m
plot(X(i,1:j_end),':','Color',0.25+0.5*rand(3,1));
else
plot(X(i,1:j_end),'Color',0.25+0.5*rand(3,1));
end
hold on
end
title('Last Run');
xlabel('Time Steps');
ylabel('Opinion State, s');
hold off
% hold on
subplot(3,1,2);
for j = 1:bc.n
plot(A(j,1:j_end),'Color',0.25+0.5*rand(3,1));
hold on
end
xlabel('Time Steps');
ylabel('Action (Bribe), a');
hold off
subplot(3,1,3);
plot(R(1:j_end));
xlabel('Time Steps');
ylabel('Rewards');
end
end