-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresults_cont.m
243 lines (181 loc) · 7.47 KB
/
results_cont.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
% Results.m: generates graphs for section 4 in Iskhakov, Rust and Schjerning (2012)
% Fedor Iskhakov, University of New South Wales
% John Rust, University of Maryland
% Bertel Schjerning, University of Copenhagen
%% CLEAR MEMORY AND SWT SWITCHES
clc; clear; close all;
% to be modified by user
paperdir='/Users/bertelschjerning/Dropbox/IRS/leapfrogging/_IOpaper/current/0pdf/';
%%Switches
compile=1;
%% COMPILE
tic
if compile
fprintf('COMPILING... ');
tic
% mex -largeArrayDims$ leapfrog.c -DMAXEQB=3 -DPRINTeqbloop=1 -DPRINTeqbstr=0
mex -largeArrayDims leapfrog.c -DMAXEQB=3 -DPRINTeqbloop=1 -DPRINTeqbstr=0
tc=toc; fprintf('Compiled model in %1.10f (seconds)\n\n',tc);
end
% SET BECNHMARK PARAMETERS
setup;
% Adjustments to sw structure - see setup for description
sw.alternate=true; %alternate move or simultanious move game
sw.esr=5; %equilibrium selection rule to be used: see setup.m or esr.c %ESR:always play first equilibrium
mp.c_tr=-1;
mp.onestep=1;
mp.tpm=[0 1; 1 0];
mp.k2=0;
par.nC=25;
mp.nC=par.nC; % add nC to mp
% %%%%%%%%%%%%%%%%%%%
% %% FIGURE 4
% %%%%%%%%%%%%%%%%%%%
% mp.k1=5;
% for i=1:2;
% mpvec(i)=mp;
% swvec(i)=sw;
% end
% i=1; mpvec(i).c_tr=1;
% i=2; mpvec(i)=mp; swvec(i).esr=7; swvec(i).alternate=false;
% tit1(1)={'Panel (a): Non-monotonic tech. progress'}
% tit1(2)={'Panel (b): Simultaneous move'}
% tit2(1)={'Panel (c): Non-monotonic tech. progress'}
% tit2(2)={'Panel (d): Simultaneous move'}
% for i=1:numel(mpvec);
% par.nC=5;
% if swvec(i).alternate==false
% par.nC=5;
% end
% mpvec(i).nC=par.nC;
% % recalculate depend parameters
% mpvec(i).dt=5/par.nC; % 5 is top cost
% mpvec(i).df=exp(-0.05*mpvec(i).dt);
% par.pti=f_pti(mpvec(i), par);
% swvec(i).esr=99; %equilibrium selection rule to be used: see setup.m or esr.c
% swvec(i).esrmax=10000; %run N feasible eqstrings (set equal to 192736405 for n=5)
% swvec(i).esrstart=0; %
% %% SET MONOPOLY PARAMETERS
% mp_mon=mpvec(i);
% par_mon=par;
% sw_mon=swvec(i);
% mp_mon.tpm=[1 0; 1 0];
% sw_mon.alternate=true; % always solve alternate move to obtain monopoly profits
% sw_mon.esr=1; %equil5ibrium selection rule to be used: see setup.m or esr.c
% sw_mon.esrmax=1; %run N feasible eqstrings (set equal to 192736405 for n=5)
% %% SOLVE MONOPOLY MODEL
% [bne_mon, br_mon, g_mon, eqbstr_mon]=leapfrog(par_mon,mp_mon,sw_mon);
% v10_mon=g_mon(par.nC).solution(1,7);
% v20_mon=g_mon(par.nC).solution(1,9);
% %% SOLVE MODEL AT PARAMETRS mpvec(i), par, swvec(i)
% [bne, br, g, eqbstr, moncmp]=leapfrog(par,mpvec(i),swvec(i),g_mon);
% eqbstr(:,isnan(eqbstr(1,:)))=[];
% eqbstr=eqbstr';
% moncmp=moncmp';
% %Efficiency
% %eqbstr(:,8)=eqbstr(:,8)/(v10_mon+v20_mon);
% eqbstr(:,8)=eqbstr(:,8)/(v10_mon+v20_mon);
% [a, b]=graph.EqbstrPlot(eqbstr,[2 8],(v10_mon+v20_mon),[],sw,tit1{i});
% % title(tit1{i});
% set(gcf, 'PaperPosition', [0 0 6 6]);
% saveas(gcf, sprintf('%sTri_%d',paperdir, i), 'fig')
% saveas(gcf, sprintf('%sTri_%d.eps',paperdir, i), 'psc2')
% % d=analyse(eqbstr);
% dummystr = '[((eqbstr(:,3)~=0).*(eqbstr(:,4)~=0)) ((eqbstr(:,3)==0) | (eqbstr(:,4)==0))]';
% graphstring='graph.EqbstrCDFPlot(eqbstr,[0], dummystr, lbl ,mp,sw,tit2{i},0.5, mfig)';
% % graph.EqbstrCDFPlot(eqbstr,[0 -5 6 7], dummystr, {'vi ne 0','vi=0'} ,[],sw,tit2{i},1);
% graph.EqbstrCDFPlot(eqbstr,[0 7 -5 ], [], [] ,[],sw,tit2{i},1);
% % title(tit2{i});
% set(gcf, 'PaperPosition', [0 0 6 6]);
% saveas(gcf, sprintf('%sCDF_%d',paperdir, i), 'fig')
% saveas(gcf, sprintf('%sCDF_%d.eps',paperdir, i), 'psc2')
% end
%%%%%%%%%%%%%%%%%%%
%% FIGURE 6 and 7
%%%%%%%%%%%%%%%%%%%
%clear mpvec, swvec;
mp.k1=2;
for i=1:7;
mpvec(i)=mp;
swvec(i)=sw;
mpvec(i).k1=2;
mpvec(i).nC=250;
end
% Adjust mp structure - see setup for description
% FIGURE 6
i=1; mpvec(i).k1=2; mpvec(i).nC=100; swvec(i).esr=99; tit(i)={'Panel (a): Preemption and rent-dissipation'}
i=2; mpvec(i).k1=2; mpvec(i).nC=25; swvec(i).esr=99; tit(i)={'Panel (b): Underinvestment'}
i=3; mpvec(i).k1=.5; mpvec(i).nC=25; swvec(i).esr=99; tit(i)={'Panel (c): Leap-frogging'}
% FIGURE 7
i=4; mpvec(i).tpm=[0.5 0.5; 0.5 .5]; tit(i)={'Panel (a): Random alternating moves'}
i=5; mpvec(i).c_tr=2; tit(i)={'Panel (b): Non-monotonic tech. progress'}
%i=6; mpvec(i).c_tr=2; mpvec(i).onestep=0; tit(i)={'Panel (c): Non-monotonic multistep tech. progress'}
%i=7; mpvec(i)=mp; swvec(i).esr=7; swvec(i).alternate=false; tit(i)={'Panel (d): Simultaneous move'}
%i=6; swvec(i).esr=7; swvec(i).alternate=false; tit(i)={'Panel (d): Simultaneous move'}
i=6; swvec(i).esr=3; swvec(i).alternate=false; tit(i)={'Panel (d): Simultaneous move'}
%!rm randstream.mat
nMC=1000;
McOut=nan(nMC, 3, numel(mpvec));
%% FIGURE 6 and 7
for i=4:6;
% for i=1:2;
% recalculate depend parameters
par.nC=mpvec(i).nC; % add nC to mp
capT=floor(1.5*par.nC);
mpvec(i).dt=25/par.nC; % 5 is top cost
mpvec(i).df=exp(-0.05*mp.dt);
par.pti=f_pti(mpvec(i), par);
%% SET MONOPOLY PARAMETERS
mp_mon=mpvec(i);
par_mon=par;
sw_mon=swvec(i);
mp_mon.tpm=[1 0; 1 0];
sw_mon.alternate=true; % always solve alternate move to obtain monopoly profits
sw_mon.esr=1; %equil5ibrium selection rule to be used: see setup.m or esr.c
sw_mon.esrmax=1; %run N feasible eqstrings (set equal to 192736405 for n=5)
%% SOLVE MONOPOLY MODEL
[bne_mon, br_mon, g_mon, eqbstr_mon]=leapfrog(par_mon,mp_mon,sw_mon);
v10_mon=g_mon(par.nC).solution(1,7);
v20_mon=g_mon(par.nC).solution(1,9);
%% SOLVE MODEL AT PARAMETRS mpvec(i), par, swvec(i)
[bne, br, g, eqbstr]=leapfrog(par,mpvec(i),swvec(i));
for iMC=1:nMC;
%% Simulare sequences
sp=simul.setup(par); % Run setup for simulation module
sp.T=capT;
s=simul.sequence(g,sp, mpvec(i),par,swvec(i).alternate, 'randseed'); % Sumulate sequences
s_mon=simul.sequence(g_mon,sp, mp_mon,par,sw_mon.alternate, 'randseed'); % Sumulate sequences
simultan=(s.i1==s.i2).*(s.i1>0);
preempt=((s.c1>s.c2).*(s.i2>0) | (s.c2>s.c1).*(s.i1>0)) ;
leap=((s.c1>s.c2).*(s.i1>0) | (s.c2>s.c1).*(s.i2>0));
[s.i1 s.i2 s.c1 s.c2 simultan preempt leap];
% if i<=7;
% s.cmon=s_mon.c1;
% graph.CostSequence(s, mpvec(i), tit{i}, '', s_mon); % plot sequences realized costs
% else
% graph.CostSequence(s, mpvec(i), tit{i}, ''); % plot sequences realized costs
% end
% set(gcf, 'PaperPosition', [0 0 6 5]);
% saveas(gcf, sprintf('%sSeq_%d',paperdir, i), 'fig')
% saveas(gcf, sprintf('%sSeq_nC%d_%d.eps',paperdir, par.nC, i), 'psc2')
preempt_share=sum(preempt)/(sum((s.i1 +s.i2)>0)-1);
leap_share=sum(leap)/(sum((s.i1 +s.i2)>0)-1);
simul_share=sum(simultan)/(sum((s.i1 +s.i2)>0)-1);
McOut(iMC,:, i)=[simul_share preempt_share leap_share];
end
figure(i);
y=McOut(:,:,i)
xi=unique(y);
yi = histc(y,xi);
histc(y,xi)
cdfy=cumsum(yi)./repmat(sum(yi), size(yi,1),1)
stairs(xi, cdfy);
xlim([0 1]);
ylim([0 1]);
legend('Duplicative','Premptive','Leap-frogging', 'location', 'SouthEast');
title(tit{i})
set(gcf, 'PaperPosition', [0 0 6 5]);
saveas(gcf, sprintf('%sCDFSeq_%d',paperdir, i), 'fig')
saveas(gcf, sprintf('%sCDFSeq_nC%d_%d.eps',paperdir, par.nC, i), 'psc2')
end;
return