LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
retrieval_fpi.m
1%{ @file retrieval_fpi.m
2 % @brief Fixed-point iteration (FPI) heuristic for delayed-hit (list-based) caches
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Approximates miss, hit and delayed-hit metrics of a delayed-hit cache via FPI
9 %
10 % @details
11 % Implements the fixed-point heuristic of the paper (Sec. "Fixed-Point
12 % Heuristic", eqs. theta/xi/pi/pi_0/phi_FPI) for a list-based cache with delayed
13 % hits whose retrieval system has one IS station (s=0) and r PS stations
14 % (s=1,...,r). The heuristic truncates the regular perturbation expansion at 0th
15 % order (pi_{i,l}(m-1_j) ~ pi_{i,l}(m)) and solves the resulting nonlinear system
16 % by successive substitution. Iteration t -> t+1:
17 %
18 % D_i = 1 + lambda_i*eta_{0,i} + sum_{s=1}^r lambda_i*eta_{s,i}*(1 + sum_{k!=i} phi_{s,k})
19 % theta_{ij} = gamma_{ij} / D_i
20 % xi_j = m_j / sum_k theta_{kj} (1 - sum_l pi_{kl})
21 % pi_{ij} = theta_{ij} xi_j / (1 + sum_l theta_{il} xi_l)
22 % pi_{i0} = (1 - sum_j pi_{ij}) / D_i
23 % phi_{si} = lambda_i*eta_{s,i}*(1 + sum_{k!=i} phi_{s,k}) pi_{i0} (s=1..r)
24 % phi_{0i} = lambda_i*eta_{0,i} pi_{i0}
25 %
26 % where phi_{s,k} is the delayed-hit probability of item k at PS station s. (The
27 % paper writes phi_{r,k} in eqs. theta_FPI/phi_FPI, but the exact recursion it
28 % approximates, eq. theta RS, uses the per-station index s; the two coincide for
29 % a single PS station.) The solution satisfies the balance
30 % pi_{i0} + sum_s phi_{si} + sum_j pi_{ij} = 1. Output orientation matches
31 % retrieval_metrics for direct comparison.
32 %
33 % @par Syntax:
34 % @code
35 % [pmiss, phit, pdh] = retrieval_fpi(m, lambda, eta, gamma)
36 % [pmiss, phit, pdh] = retrieval_fpi(m, lambda, eta, gamma, max_iter, tol)
37 % @endcode
38 %
39 % @par Parameters:
40 % <table>
41 % <tr><th>Name<th>Description
42 % <tr><td>m<td>Cache list capacities (1 x h)
43 % <tr><td>lambda<td>Per-item arrival rates (1 x n)
44 % <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)). A PS column models any symmetric/identical-rate single-server discipline (PS, SIRO, FCFS, LCFS-PR), all treated alike via the mean-field sharing slowdown.
45 % <tr><td>gamma<td>Access factors gamma(i,j)=gamma_{i,j}, (n x h)
46 % <tr><td>max_iter<td>Maximum number of iterations (default 1e5)
47 % <tr><td>tol<td>Convergence tolerance on relative change (default 1e-6)
48 % </table>
49 %
50 % @par Returns:
51 % <table>
52 % <tr><th>Name<th>Description
53 % <tr><td>pmiss<td>Miss ratios pi_{i,0}, (1 x n)
54 % <tr><td>phit<td>Hit ratios pi_{i,j}, (h x n)
55 % <tr><td>pdh<td>Delayed-hit probabilities phi_{s,i} for s=0,...,r, ((r+1) x n)
56 % </table>
57%}
58function [pmiss,phit,pdh]=retrieval_fpi(m,lambda,eta,gamma,max_iter,tol)
59if nargin < 5 || isempty(max_iter), max_iter = 1000; end
60if nargin < 6 || isempty(tol), tol = 1e-6; end
61
62n = numel(lambda);
63m = m(:).';
64h = numel(m);
65r = size(eta,2) - 1;
66lambda = lambda(:); % n x 1
67eta0 = eta(:,1); % n x 1 (IS station s=0)
68etaPS = eta(:,2:end); % n x r (PS stations s=1..r)
69
70% initial guess (paper Sec. Fixed-Point Heuristic)
71phi = ones(r+1,n) / ((h+1)*(r+2)); % phi(s+1,i), s=0..r
72pij = ones(h,n) / (h+1); % pij(j,i)
73pi0 = ones(1,n) / ((h+1)*(r+2)); % pi0(i)
74
75for t = 1:max_iter
76 % per-station PS-sharing factor F(s,i) = 1 + sum_{k!=i} phi_{s,k}
77 % (the paper writes phi_{r,k}, but the exact recursion eq. theta RS uses the
78 % station index s; for a single PS station the two coincide.)
79 F = ones(r, n);
80 for s = 1:r
81 phis = phi(s+1,:);
82 F(s,:) = 1 + (sum(phis) - phis);
83 end
84
85 D = 1 + lambda.*eta0; % n x 1
86 for s = 1:r
87 D = D + lambda .* etaPS(:,s) .* F(s,:).';
88 end
89
90 theta = gamma ./ D; % n x h
91
92 oneminus = (1 - sum(pij,1)).'; % n x 1 (uses pij^[t])
93 xi = zeros(1,h);
94 for j = 1:h
95 xi(j) = m(j) / sum(theta(:,j).*oneminus);
96 end
97
98 txi = theta .* xi; % n x h
99 pij_new = (txi ./ (1 + sum(txi,2))).'; % h x n
100
101 pi0_new = (1 - sum(pij_new,1)) ./ D.'; % 1 x n
102
103 phi_new = zeros(r+1,n);
104 phi_new(1,:) = (lambda.*eta0).' .* pi0_new; % phi_{0,i}
105 for s = 1:r
106 phi_new(s+1,:) = (lambda.*etaPS(:,s)).' .* F(s,:) .* pi0_new; % phi_{s,i}
107 end
108
109 % convergence: max relative change in miss, hit, delayed-hit ratios
110 delta = max([reldiff(pi0_new,pi0), reldiff(pij_new,pij), reldiff(phi_new,phi)]);
111
112 pij = pij_new;
113 pi0 = pi0_new;
114 phi = phi_new;
115
116 if ~isfinite(delta)
117 line_warning(mfilename,'FPI diverged (non-finite iterate) at iteration %d.\n', t);
118 break
119 end
120 if delta < tol
121 break
122 end
123 if t == max_iter
124 line_warning(mfilename,'FPI did not converge within %d iterations (last rel. change %.2e).\n', max_iter, delta);
125 end
126end
127
128pmiss = pi0;
129phit = pij;
130pdh = phi;
131end
132
133function d = reldiff(a,b)
134denom = max(abs(b(:)));
135if denom == 0
136 denom = 1;
137end
138d = max(abs(a(:)-b(:))) / denom;
139end