LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
retrieval_mva.m
1%{ @file retrieval_mva.m
2 % @brief Exact MVA-style recursion for delayed-hit (list-based) cache metrics
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Computes exact miss, hit and delayed-hit metrics via the MVA recursion
9 %
10 % @details
11 % Implements the exact recursive characterization of the paper (Theorems
12 % "thm:arvthm" and "thm:pi_xi", and eq. motivation_to_pi0_FPI) that the FPI
13 % heuristic (retrieval_fpi) approximates. For a list-based cache with delayed
14 % hits whose retrieval system has one IS station (s=0) and r PS stations
15 % (s=1,...,r), with phi^{(k)}_{s,i} the delayed-hit probability of item i at
16 % station s in the system WITHOUT item k:
17 %
18 % theta_{ij}(m) = gamma_{ij} / (1 + lambda_i eta_{0,i}
19 % + sum_{s=1}^r lambda_i eta_{s,i}(1 + sum_{k!=i} phi^{(i)}_{s,k}(m-1_j)))
20 % xi_j(m) = m_j / sum_i theta_{ij}(m)(1 - pihit_i(m-1_j))
21 % pi_{ij}(m) = theta_{ij}(m) xi_j(m) (1 - pihit_i(m-1_j))
22 % pihit_i(m) = sum_j pi_{ij}(m)
23 % pi_{i0}(m) = (1 - pihit_i(m)) / (1 + lambda_i eta_{0,i}
24 % + sum_{s=1}^r lambda_i eta_{s,i}(1 + sum_{k!=i} phi^{(i)}_{s,k}(m)))
25 % phi_{sk}(m) = lambda_k pi_{k0}(m) eta_{s,k}(1 + sum_{i!=k} phi^{(k)}_{s,i}(m)) (s=1..r)
26 % phi_{0k}(m) = lambda_k eta_{0,k} pi_{k0}(m)
27 %
28 % The recursion terminates at the empty item set and at the empty cache
29 % (pihit_i = 0). This is exact and agrees with retrieval_nc / retrieval_metrics;
30 % it is memoized over (item-subset, capacity) with O(2^n n^2 h r prod_j(1+m_j))
31 % time, so it is feasible only for small systems (use retrieval_fpi otherwise).
32 %
33 % @par Syntax:
34 % @code
35 % [pmiss, phit, pdh] = retrieval_mva(m, lambda, eta, gamma)
36 % @endcode
37 %
38 % @par Parameters:
39 % <table>
40 % <tr><th>Name<th>Description
41 % <tr><td>m<td>Cache list capacities (1 x h)
42 % <tr><td>lambda<td>Per-item arrival rates (1 x n)
43 % <tr><td>eta<td>Fetching demands eta(i,s+1)=eta_{s,i} (column 1 = IS station s=0, columns 2..r+1 = PS stations), (n x (r+1))
44 % <tr><td>gamma<td>Access factors gamma(i,j)=gamma_{i,j}, (n x h)
45 % </table>
46 %
47 % @par Returns:
48 % <table>
49 % <tr><th>Name<th>Description
50 % <tr><td>pmiss<td>Miss ratios pi_{i,0}, (1 x n)
51 % <tr><td>phit<td>Hit ratios pi_{i,j}, (h x n)
52 % <tr><td>pdh<td>Delayed-hit probabilities phi_{s,i} for s=0,...,r, ((r+1) x n)
53 % </table>
54%}
55function [pmiss,phit,pdh]=retrieval_mva(m,lambda,eta,gamma)
56n = numel(lambda);
57m = m(:).';
58h = numel(m);
59r = size(eta,2) - 1;
60lambda = lambda(:).'; % 1 x n
61eta0 = eta(:,1).'; % 1 x n
62etaPS = eta(:,2:end); % n x r
63
64radix = m + 1;
65ncap = prod(radix);
66nmask = 2^n;
67
68done = false(nmask, ncap);
69PI0 = zeros(nmask, ncap, n);
70PIHIT = zeros(nmask, ncap, n);
71PIJ = zeros(nmask, ncap, n, h);
72PHI = zeros(nmask, ncap, n, r+1); % station index s=0..r -> page 1..r+1
73
74fullmask = nmask - 1;
75solve(fullmask, m);
76
77ci = capidx(m);
78pmiss = zeros(1,n);
79phit = zeros(h,n);
80pdh = zeros(r+1,n);
81for i = 1:n
82 pmiss(i) = PI0(fullmask+1, ci, i);
83 for j = 1:h
84 phit(j,i) = PIJ(fullmask+1, ci, i, j);
85 end
86 for s = 1:r+1
87 pdh(s,i) = PHI(fullmask+1, ci, i, s);
88 end
89end
90
91 function idx = capidx(c)
92 idx = 1; mul = 1;
93 for jj = 1:h
94 idx = idx + c(jj)*mul;
95 mul = mul*radix(jj);
96 end
97 end
98
99 function solve(mask, c)
100 ci_ = capidx(c);
101 if done(mask+1, ci_), return; end
102 if mask == 0
103 done(mask+1, ci_) = true;
104 return
105 end
106 active = find(bitget(mask, 1:n));
107
108 % boundary: when the cache can hold every active item (sum(c) >= |active|),
109 % all items are permanently cached -> pihit=1, pi0=0, phi=0 (no fetching).
110 if sum(c) >= numel(active)
111 for i = active
112 PIHIT(mask+1, ci_, i) = 1;
113 end
114 done(mask+1, ci_) = true;
115 return
116 end
117
118 % --- ensure dependencies are solved ---
119 for jj = 1:h
120 if c(jj) > 0
121 cj = c; cj(jj) = cj(jj) - 1;
122 solve(mask, cj);
123 for i = active
124 solve(bitset(mask, i, 0), cj);
125 end
126 end
127 end
128 for k = active
129 solve(bitset(mask, k, 0), c);
130 end
131
132 % --- theta, xi, pi_{ij} (cache recursion on m-1_j) ---
133 for jj = 1:h
134 if c(jj) > 0
135 cj = c; cj(jj) = cj(jj) - 1; cjx = capidx(cj);
136 theta = zeros(1,n);
137 for i = active
138 maski = bitset(mask, i, 0);
139 acc = 0;
140 for s = 1:r
141 sphi = 0;
142 for k = active
143 if k ~= i
144 sphi = sphi + PHI(maski+1, cjx, k, s+1);
145 end
146 end
147 acc = acc + lambda(i)*etaPS(i,s)*(1 + sphi);
148 end
149 theta(i) = gamma(i,jj) / (1 + lambda(i)*eta0(i) + acc);
150 end
151 sden = 0;
152 for i = active
153 sden = sden + theta(i)*(1 - PIHIT(mask+1, cjx, i));
154 end
155 xi_j = c(jj) / sden;
156 for i = active
157 PIJ(mask+1, ci_, i, jj) = theta(i)*xi_j*(1 - PIHIT(mask+1, cjx, i));
158 end
159 end
160 end
161
162 % --- pihit_i = sum_j pi_{ij} ---
163 for i = active
164 ph = 0;
165 for jj = 1:h
166 ph = ph + PIJ(mask+1, ci_, i, jj);
167 end
168 PIHIT(mask+1, ci_, i) = ph;
169 end
170
171 % --- pi_{i0} (uses phi^{(i)}(m) at same capacity) ---
172 for i = active
173 maski = bitset(mask, i, 0);
174 acc = 0;
175 for s = 1:r
176 sphi = 0;
177 for k = active
178 if k ~= i
179 sphi = sphi + PHI(maski+1, ci_, k, s+1);
180 end
181 end
182 acc = acc + lambda(i)*etaPS(i,s)*(1 + sphi);
183 end
184 PI0(mask+1, ci_, i) = (1 - PIHIT(mask+1, ci_, i)) / (1 + lambda(i)*eta0(i) + acc);
185 end
186
187 % --- phi_{sk}(m) ---
188 for k = active
189 maskk = bitset(mask, k, 0);
190 pi0k = PI0(mask+1, ci_, k);
191 PHI(mask+1, ci_, k, 1) = lambda(k)*eta0(k)*pi0k; % s = 0 (IS)
192 for s = 1:r
193 sphi = 0;
194 for i = active
195 if i ~= k
196 sphi = sphi + PHI(maskk+1, ci_, i, s+1);
197 end
198 end
199 PHI(mask+1, ci_, k, s+1) = lambda(k)*pi0k*etaPS(k,s)*(1 + sphi);
200 end
201 end
202
203 done(mask+1, ci_) = true;
204 end
205end