|
|
classdef gymGame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
properties
|
|
|
|
|
|
|
|
|
T;
|
|
|
a_star;
|
|
|
p;
|
|
|
r;
|
|
|
|
|
|
|
|
|
lambda;
|
|
|
min_cost;
|
|
|
beta;
|
|
|
betatilde;
|
|
|
b;
|
|
|
mu;
|
|
|
|
|
|
|
|
|
utilities;
|
|
|
t1_utility;
|
|
|
utilities_tilde;
|
|
|
att;
|
|
|
avg_att;
|
|
|
avg_costs;
|
|
|
avg_t1_att;
|
|
|
prob_success;
|
|
|
prob_att_c_b;
|
|
|
prob_att_day;
|
|
|
|
|
|
|
|
|
prob_att_r;
|
|
|
att_r;
|
|
|
change_att_r;
|
|
|
benefits_r;
|
|
|
costs_r;
|
|
|
net_surplus_r;
|
|
|
surplus_r;
|
|
|
|
|
|
|
|
|
spec;
|
|
|
|
|
|
end
|
|
|
|
|
|
properties (Constant)
|
|
|
|
|
|
seed = 12345;
|
|
|
rounds = 10000;
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
methods
|
|
|
|
|
|
function obj = gymGame(properties, parameters, min_cost, title)
|
|
|
|
|
|
|
|
|
obj.T = properties.T;
|
|
|
obj.a_star = properties.a_star;
|
|
|
obj.p = properties.p;
|
|
|
|
|
|
|
|
|
obj.lambda = parameters.lambda;
|
|
|
obj.min_cost = min_cost;
|
|
|
obj.beta = parameters.beta;
|
|
|
obj.betatilde = parameters.betatilde;
|
|
|
obj.b = parameters.b;
|
|
|
obj.mu = parameters.mu;
|
|
|
|
|
|
|
|
|
obj.spec = title;
|
|
|
|
|
|
|
|
|
obj = obj.compute_utilities();
|
|
|
|
|
|
|
|
|
obj = obj.simulate_behavior();
|
|
|
|
|
|
end
|
|
|
|
|
|
function obj = compute_utilities(obj)
|
|
|
|
|
|
V_n = NaN([obj.a_star+1 obj.T]);
|
|
|
V_tilde = NaN([obj.a_star+1 obj.T]);
|
|
|
|
|
|
|
|
|
for g = 0:obj.a_star
|
|
|
g1 = g + 1;
|
|
|
V_n(g1,obj.T) = obj.compute_T_utility(g, 'actual');
|
|
|
V_tilde(g1,obj.T) = obj.compute_T_utility(g, 'perceived');
|
|
|
end
|
|
|
|
|
|
|
|
|
for period = 1:obj.T-1
|
|
|
|
|
|
t = obj.T - period;
|
|
|
start = max(obj.a_star - t + 1, 0);
|
|
|
|
|
|
|
|
|
for g = start:obj.a_star
|
|
|
g1 = g + 1;
|
|
|
|
|
|
|
|
|
delta_V_tilde = V_tilde(max(g1-1,1),t+1) - V_tilde(g1,t+1);
|
|
|
delta_V_n = V_n(max(g1-1,1),t+1) - V_n(g1,t+1);
|
|
|
|
|
|
|
|
|
V_tilde(g1,t) = (obj.F(obj.betatilde.*(obj.b + delta_V_tilde)).* ...
|
|
|
(obj.b + delta_V_tilde)) + V_tilde(g1,t+1) - ...
|
|
|
obj.C(obj.betatilde.*(obj.b + delta_V_tilde));
|
|
|
|
|
|
|
|
|
V_n(g1,t) = (obj.F(obj.beta.*(obj.b + delta_V_tilde)).* ...
|
|
|
(obj.b + delta_V_n)) + V_n(g1,t+1) - ...
|
|
|
obj.C(obj.beta.*(obj.b + delta_V_tilde));
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
obj.utilities = V_n;
|
|
|
obj.t1_utility = V_n(obj.a_star+1,1);
|
|
|
obj.utilities_tilde = V_tilde;
|
|
|
|
|
|
end
|
|
|
|
|
|
function V_T = compute_T_utility(obj, g, focus)
|
|
|
|
|
|
|
|
|
|
|
|
if strcmp(focus, 'actual')
|
|
|
|
|
|
B = obj.beta;
|
|
|
|
|
|
elseif strcmp(focus, 'perceived')
|
|
|
|
|
|
B = obj.betatilde;
|
|
|
|
|
|
end
|
|
|
|
|
|
if g == 0
|
|
|
|
|
|
V_T = (obj.F(B.*obj.b).*obj.b) - obj.C(B.*obj.b);
|
|
|
|
|
|
elseif g == 1
|
|
|
|
|
|
V_T = (obj.F(B.*(obj.b + obj.p)).*obj.b) - ...
|
|
|
obj.C(B.*(obj.b + obj.p)) - ...
|
|
|
((1 - obj.F(B.*(obj.b + obj.p))).*obj.p);
|
|
|
|
|
|
else
|
|
|
|
|
|
V_T = (obj.F(B.*obj.b).*obj.b) - obj.C(B.*obj.b) - obj.p;
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
function obj = simulate_behavior(obj)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rng(obj.seed);
|
|
|
obj.att = zeros(1,obj.rounds);
|
|
|
t1_att = obj.att;
|
|
|
att_day = zeros(obj.T,obj.rounds);
|
|
|
costs_day = zeros(obj.T,obj.rounds);
|
|
|
met_goal = zeros(1,obj.rounds);
|
|
|
obj.prob_att_c_b = zeros(1,obj.rounds);
|
|
|
|
|
|
for round = 1:obj.rounds
|
|
|
|
|
|
c = obj.cost_draws();
|
|
|
g = obj.a_star;
|
|
|
a = 0;
|
|
|
c_b = 0;
|
|
|
att_c_b = 0;
|
|
|
|
|
|
|
|
|
for t = 1:obj.T
|
|
|
g1 = g + 1;
|
|
|
|
|
|
if t == obj.T && (g == 0 || g >= 2)
|
|
|
|
|
|
if c(t) <= (obj.beta * obj.b)
|
|
|
|
|
|
|
|
|
g = max(g - 1, 0);
|
|
|
a = a + 1;
|
|
|
att_day(t,round) = 1;
|
|
|
costs_day(t,round) = c(t);
|
|
|
|
|
|
if c(t) > obj.b
|
|
|
|
|
|
att_c_b = att_c_b + 1;
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
elseif t == obj.T && g == 1
|
|
|
|
|
|
if c(t) <= (obj.beta * (obj.b + obj.p))
|
|
|
|
|
|
|
|
|
g = max(g - 1, 0);
|
|
|
a = a + 1;
|
|
|
att_day(t,round) = 1;
|
|
|
costs_day(t,round) = c(t);
|
|
|
|
|
|
if c(t) > obj.b
|
|
|
|
|
|
att_c_b = att_c_b + 1;
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
else
|
|
|
|
|
|
if c(t) <= (obj.beta * (obj.b + ...
|
|
|
obj.utilities_tilde(max(g1-1,1),t+1) - ...
|
|
|
obj.utilities_tilde(g1,t+1)))
|
|
|
|
|
|
|
|
|
g = max(g - 1, 0);
|
|
|
a = a + 1;
|
|
|
att_day(t,round) = 1;
|
|
|
costs_day(t,round) = c(t);
|
|
|
|
|
|
if c(t) > obj.b
|
|
|
|
|
|
att_c_b = att_c_b + 1;
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
if c(t) > obj.b
|
|
|
|
|
|
|
|
|
c_b = c_b + 1;
|
|
|
|
|
|
end
|
|
|
|
|
|
if t == 1 && g < obj.a_star
|
|
|
|
|
|
|
|
|
t1_att(round) = 1;
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
if g == 0
|
|
|
|
|
|
met_goal(round) = 1;
|
|
|
|
|
|
end
|
|
|
|
|
|
obj.att(round) = a;
|
|
|
obj.prob_att_c_b(round) = att_c_b ./ c_b;
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
obj.avg_att = mean(obj.att);
|
|
|
obj.avg_t1_att = mean(t1_att);
|
|
|
obj.prob_success = mean(met_goal);
|
|
|
obj.prob_att_c_b = mean(obj.prob_att_c_b);
|
|
|
obj.prob_att_day = sum(att_day,2) ./ obj.rounds;
|
|
|
obj.avg_costs = mean(sum(costs_day,1));
|
|
|
|
|
|
end
|
|
|
|
|
|
function obj = compute_incentive_behavior(obj, r)
|
|
|
|
|
|
|
|
|
|
|
|
obj.r = r;
|
|
|
|
|
|
|
|
|
obj.prob_att_r = obj.F(obj.beta .* (obj.b + r));
|
|
|
prob_att_no_r = obj.F(obj.beta .* (obj.b));
|
|
|
|
|
|
|
|
|
obj.att_r = obj.T .* obj.prob_att_r;
|
|
|
|
|
|
|
|
|
obj.change_att_r = obj.T .* (obj.prob_att_r - prob_att_no_r);
|
|
|
|
|
|
|
|
|
obj.benefits_r = obj.att_r .* obj.b;
|
|
|
|
|
|
|
|
|
obj.costs_r = obj.T .* obj.C(obj.beta .* (obj.b + r));
|
|
|
|
|
|
|
|
|
obj.net_surplus_r = obj.benefits_r - obj.costs_r;
|
|
|
|
|
|
|
|
|
obj.surplus_r = obj.net_surplus_r + (obj.att_r .* r);
|
|
|
|
|
|
end
|
|
|
|
|
|
function probability = F(obj, x)
|
|
|
|
|
|
|
|
|
z = x - obj.min_cost;
|
|
|
z = gymGame.minzero(z);
|
|
|
probability = 1 - exp(-obj.lambda.*z);
|
|
|
|
|
|
end
|
|
|
|
|
|
function density = f(obj, x)
|
|
|
|
|
|
|
|
|
|
|
|
z = x - obj.min_cost;
|
|
|
density = obj.lambda.*exp(-obj.lambda.*z);
|
|
|
density = density.*heaviside(heaviside(z));
|
|
|
|
|
|
end
|
|
|
|
|
|
function expectation = C(obj, x)
|
|
|
|
|
|
|
|
|
z = x - obj.min_cost;
|
|
|
z = gymGame.minzero(z);
|
|
|
expectation = (1 ./ obj.lambda).*(1 - exp(-obj.lambda.*z)) ...
|
|
|
- (z.*exp(-obj.lambda.*z)) + obj.min_cost.*obj.F(x);
|
|
|
|
|
|
end
|
|
|
|
|
|
function c = cost_draws(obj)
|
|
|
|
|
|
|
|
|
mean = 1 ./ obj.lambda;
|
|
|
c = exprnd(mean, [1 obj.T]) + obj.min_cost;
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
methods(Static)
|
|
|
|
|
|
function y = minzero(x)
|
|
|
|
|
|
|
|
|
y = x .* heaviside(heaviside(x));
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|