-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_leapfrog_fed.m
170 lines (147 loc) · 4.86 KB
/
run_leapfrog_fed.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
% Fedor Iskhakov, University Technology Sidney
% John Rust, University of Maryland
% Bertel Schjerning, University of Copenhagen
% Sidney, March 2012
close all;
%% COMPILE
%if false
if true
fprintf('Compiling... ');
tic
mex -largeArrayDims leapfrog.c -DMAXEQB=3 -DPRINTeqbloop=1 -DPRINTeqbstr=0
tc=toc; fprintf('Compiled model in %1.10f (seconds)\n\n',tc);
end
%% PARAMETERS
% load defaults
setup;
% > time differential
%mp.dt=1;
% > investment cost
mp.k1=5.2;
mp.k2=0;
% > eta
mp.eta=0;
%mp.sigma=10;
% > technological progress
mp.c_tr=-.75;
mp.onestep=1;
mp.beta_a=0.8;
mp.beta_b=0.4;
% > transition probability for turns (standard indexing: from in rows, to in colums)
%mp.tpm=[.1 .9;
% .9 .1];
mp.tpm=[0 1;
1 0];
% > number of grid points
par.nC=150;
%LOAD parameters from file
%load('../runs/SM-nc-eta-pr-step/results_run00061.mat');
%desc='(1) DTP';
%mp=mp_run00061;
%par=par_run00061;
%sw=sw_run00061;
%clear *_run00061;
%load('../runs/SM-nc-eta-pr-step/results_run00062.mat');
%desc='(2) MSTP';
%mp=mp_run00062;
%par=par_run00062;
%sw=sw_run00062;
%clear *_run00062;
desc='';
% recalculate depend parameters
[par mp]=f_update_params(par,mp);
%MONOPOLY SOLUTION
mpm=mp;
mpm.tpm=[1 0; 1 0];
swm.alternate=true;
swm.analytical=true;
swm.esr=5;
% swm.esr=99;
% swm.esrstart=0;
% swm.esrmax=1;
swm.esrmax=1;
swm.esrstart=0;
[a,b,gmon,c]=leapfrog(par,mpm,swm);
mon=gmon(par.nC).solution(1,7)+gmon(par.nC).solution(1,9);
sp=simul.setup(par); %run setup for simulation module
sp.T=floor(1.5*par.maxit);
simmon=simul.sequence(gmon,sp,mpm,par,1); % Sumulate sequences
clear a b c swm sp;
%% MODEL SWITCHES
sw.alternate=true; %alternate move or simultanious move game
sw.analytical=true; %analytical solution of eta>0 simultanous move game
sw.esr=99; %equilibrium selection rule to be used: see setup.m or esr.c
%sw.esr=5; %ESR1
%sw.esr=3; %HighCostInvestMix
sw.esrmax=100000; %run N feasible eqstrings
%sw.esrmax=1; %run N feasible eqstrings
sw.esrstart=0; %index of the first eqstring
% sw.esrstart=243;
% sw.esrmax=1;
%sw.esrstart=[0 0 0 0 0 0 0 1 2 2 0 1 2 0 0 1 0 0 0 0 0 1 2 0 1 0 0 0 1 0]; %leapfrogging
%sw.esrstart=[0 0 0 0 0 0 0 1 0 0 2 1 0 2 2 1 0 0 0 0 0 1 0 2 1 0 0 0 1 0]; %anti-leapfrogging
%sw.esrstart=[0 0 0 0 0 0 0 1 0 0 2 1 0 2 2 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0]; %anti-leapfrogging as ran by esr=6
%sw.esrmax=1;
%% RUN LRS LOOP ONCE
%if false
if true
fprintf('Parameters:\n')
disp(par);
disp(mp);
disp(sw);
fprintf('Transition probability for m:\n')
disp(mp.tpm);
tic;
[bne, br, g, eqbstr, moncmp]=leapfrog(par,mp,sw,gmon); %monopoly g structure for underinvestment checks
ts=toc;
fprintf('Solved model in %1.10f (seconds)\n',ts);
eqbstr(:,isnan(eqbstr(1,:)))=[];
eqbstr=eqbstr';
moncmp=moncmp';
%Efficiency
%eqbstr(:,8)=1-eqbstr(:,8)/mon;
eqbstr(:,8)=eqbstr(:,8)/mon;
if sw.alternate
d=analyse(eqbstr,'alt');
d=analyse(eqbstr,'notab','alt');
else
d=analyse(eqbstr);
d=analyse(eqbstr,'notab');
end
eqbsum=graph.EqbstrPlot (eqbstr,[2 2],mon,mp,sw,'Pay-off map for all found equilibria');
%for the figures in the paper:
%skip long title by passing [] in place of mp
graph.EqbstrPlot(eqbstr,[8 8],mon,mp,sw,desc);
%graph.EqbstrPlot(eqbstr,2,mon,[],sw,desc);
%graph.EqbstrPlot(eqbstr,[5 2],mon,[],sw,['(2) ' desc ': pure equilibria']);
%graph.EqbstrPlot(eqbstr,[6 2],mon,[],sw,['(3) ' desc ': symmetric equilibria']);
if 1
%SIMULATE
sp=simul.setup(par); % Run setup for simulation module
sp.T=floor(1.5*par.maxit);
s=simul.sequence(g,sp,mp,par,sw.alternate); % Sumulate sequences
graph.CostSequence(s, mp, 'Duopoly equilibrium realization'); % plot sequences realized costs
% graph.ProfitSequence(s, mp, 'Duopoly profits'); % plot sequences realized costs
graph.CostSequence(simmon, mpm, 'Monopoly equilibrium realization'); % plot sequences realized costs
end
end
%% RUN MODLE ONCE and save results to disk
if false
%if true
[bne, br, g, eqbstr]=RunLeap(mp,par,sw,'-DMAXEQB=3 -DPRINTeqbloop=0 -DPRINTeqbstr=0');
end
%% RUN MovieMaker
if false
%if true
dr ='../../../movies/';
%dr='';
%moviemaker (par,mp,sw,'mp.k1',[0 100],[dr 'eqb.k1.n5']);
%moviemaker (par,mp,sw,'mp.tpm(1,1)',[1 0],[dr 'eqb.tpm.n5']);
moviemaker (par,mp,sw,'mp.eta',[0.5 0],[dr 'eqb.eta.n5.half2zero'],[1 12]);
%moviemaker (par,mp,sw,'mp.df',[.8 .99999],[dr 'eqb.df.n5']);
%screen play
%moviemaker (par,mp,sw,'mp.eta',[.5 0],'',[1 12]);
%moviemaker (par,mp,sw,'mp.beta_a',[0.001 .5],'');
%moviemaker (par,mp,sw,'mp.c_tr',[0.001 .1],'');
end
clear tc ts;