-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_computing.m
More file actions
59 lines (55 loc) · 1.8 KB
/
Copy pathfunction_computing.m
File metadata and controls
59 lines (55 loc) · 1.8 KB
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
function [transF, rewardF, obserF] = function_computing()
% Compute the MDP and POMDP functions
% Declare global variables
% See main.m
global sigma
global state num_state action num_action
% Create the state transition function and reward function
transF = zeros(num_state, num_state, num_action);
rewardF = zeros(num_state, num_action);
parfor ai = 1:num_action
par4TransF = zeros(num_state, num_state);
eta = zeros(1, num_state);
p = action(ai);
for si = 1:num_state
n = state(si);
% Compute η
eta(si) = dot(sigma(1:si), binopdf(0:n, n, p));
% Compute the reward function
rewardF(si, ai) = eta(si);
% Compute the state transition function
par4TransF(si, max(1, si-1)) = eta(si);
par4TransF(si, si) = 1 - eta(si);
end
transF(:, :, ai) = par4TransF;
end
% Create the observation function
obserF = zeros(num_state, num_state, 3, num_action);
parfor ai = 1:num_action
par4obserF = zeros(num_state, num_state, 3);
eta = zeros(1, num_state);
p = action(ai);
for si = 1:num_state
n = state(si);
% Compute η
eta(si) = dot(sigma(1:si), binopdf(0:n, n, p));
% Compute the observation function
for sj = 1:si
switch state(si) - state(sj)
case 0
if eta(si) < 1
% No feedback received
par4obserF(si, sj, 1) = (1 - p)^n / (1 - eta(si));
% NACK received
par4obserF(si, sj, 3) = 1 - par4obserF(si, sj, 1);
end
case 1
% ACK received
par4obserF(si, sj, 2) = 1;
otherwise
continue
end
end
end
obserF(:, :, :, ai) = par4obserF;
end