-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunEconomiesOfScaleAnalysis.m
114 lines (83 loc) · 2.63 KB
/
runEconomiesOfScaleAnalysis.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
cd ~/OSM;
load('scope/topAmenities.mat','amenityTags');
load('scope/topPlaces.mat','places');
gridSize = 400;
sigma = 2;
%% Read population
p = length(places);
populationCount = zeros(1,p);
for i = 1:p
place = places{i};
try
populationCount(i) = sum(sum(getPopulationGrid(place,gridSize,sigma,true)));
catch error
% Do nothing
end
end
disp([num2str(sum(~populationCount)) ' places could not be resolved.']);
%% Read amenities
[amenityCount] = getAmenityCountByPlace(amenityTags,places);
%% Do calculations
x=log(populationCount(logical(populationCount)))';
y=[x log(amenityCount(logical(populationCount),:))];
%%
exists = [true(length(x),1) logical(amenityCount(logical(populationCount),:))];
%%
tags = {'symmetry' amenityTags{:}};
[~,m]=size(y);
markers = {'.' '+' 'o' '*' 'x' 's' 'd' '^' 'v' '>' '<' 'p' 'h'};
colours = {'k' 'g' 'r' 'b' 'c' 'm' 'y'};
markerNumber = 1;
colourNumber = 1;
plotNumber = 1;
range = [1 (1:10)+1];
legtxt = cell(length(range),1);
figure;
hold on;
[~,index]=sort(sum(exists,1),'descend');
for n = 1:m
thisX = x(exists(:,n));
thisY = y(exists(:,n),n);
if length(thisX) > 1
p = polyfit(thisX,thisY,1);
r = corrcoef(thisX,thisY);
k(n) = p(1); % Gradient
c(n) = r(2);
else
k(n) = 0;
c(n) = 0;
end
if find(ismember(range,n))
if markerNumber > length(markers)
markerNumber = 1;
end
if colourNumber > length(colours)
colourNumber = 2;
end
legtxt{plotNumber}=[ num2str(k(n),'%0.2f') ' = {\beta}_{' strrep(tags{n}, '_', ' ') '}'];
plot(thisX,thisY,[colours{colourNumber} markers{markerNumber}]);
markerNumber = markerNumber + 1;
colourNumber = colourNumber + 1;
plotNumber = plotNumber + 1;
end
end
legend(legtxt,'location','nw');
xlabel('log (Population)');
ylabel('log (SPOIs)');
lsline;
saveFigures = true;
if saveFigures
set(gcf,'Position', [0, 0, 600, 500]);
set(gcf, 'Color', 'w');
export_fig(['./figures/point/loglog-PopulationVsAmenity.pdf']);
end
%%
x1=populationCount(logical(populationCount))';
y1=[x1 amenityCount(logical(populationCount),:)];
p1=places(logical(populationCount));
texFile = 'extendedAmenity.tex';
latextable(y1(:,1:11),'format','%0.0f','horiz',strcat('\rotatebox{90}{', strrep(tags(1:11), '_', '\_')','}'),'vert',p1,'name',texFile,'Hline',[1],'Vline',[1]);
%%
[~,index]=sort(k,'descend');
texFile = 'gradient.tex';
latextable([k(index)' c(index)'],'format','%0.2f','vert',strcat('$\beta_{', strrep(tags(index)', '_', '\_')','}$'),'name',texFile,'Vline',[1]);