-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLRUgLRUComparison.m
81 lines (73 loc) · 1.76 KB
/
LRUgLRUComparison.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
% Generates figure 1
% Set all parameters
alpha = .8;
n = 10000;
chunks = 5;
C = 1000;
sizeType = 4;
pop = zipf_rand(n,alpha,n);
pop = sort(pop,'descend');
shape = 2;
scale = 300;
k = 1/shape;
sig = scale*k;
theta = sig/k;
sizes = ones(1,n) * chunks;
biggest = max(sizes);
totpop = sum(pop);
lambda = 1;
clen = 120;
fileLen = clen*chunks;
i = 1;
while i <= n
sizes(i) = round(gprnd(k,sig,theta)/clen);
if sizes(i) <= round(3600/clen)
i = i+1;
end
end
if sizeType == 2
sizes = sort(sizes,'descend');
elseif sizeType == 3
sizes = sort(sizes,'ascend');
elseif sizeType == 4
sizes = ones(1,n) .* fileLen/clen;
end
%% Solve for tc
disp('Solving for root')
func = @(t) timeapproxgLRU(t,n,pop,sizes)-C;
funcLRU = @(t) timeapproxLRU(t,n,pop,sizes)-C;
options = optimset('TolX', 10^(-16));
tc = fzero(func,0,options)
options = optimset('TolX', 10^(-16));
tcLRU = fzero(funcLRU,0,options)
%% Define Hit rate Function
prob = zeros(1,n);
probLRU = zeros(1,n);
hitrate = @(t,pop,k) expcdf(t,1/pop).^k;
for i = 1:n
prob(i) = hitrate(tc,pop(i),1);
probLRU(i) = hitrate(tcLRU,pop(i),1);
end
proball = zeros(1,n);
proballLRU = zeros(1,n);
for i = 1:n
proball(i) = hitrate(tc,pop(i),sizes(i));
end
%% Plot
hold off
plot(1:n,prob, 'b-','LineWidth',1.5);
xlabel('Popularity Ranking')
ylabel('Probability')
% ylim([0 1])
hold on
plot(1:n,probLRU,'k--','LineWidth',1.5)
hold on
plot(1:n,proball, 'r:','LineWidth',1.5);
set(gca,'fontsize',16)
legend('gLRU - A', 'LRU - A',...
'gLRU - F');
filename = strcat('LRUvgLRU_n_',string(n),'_alpha_', ...
string(alpha),'_C_',string(C),'_chunks_',string(chunks),...
'sizeType',string(sizeType),'.png');
fig = gcf;
print(fig,'-dpng',filename{1})