LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
cache_miss_spm.m
1%{ @file cache_miss_spm.m
2 % @brief Computes miss rates using saddle-point method
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Computes cache miss rates using saddle-point approximation
9 %
10 % @details
11 % This function computes global, per-user, and per-item miss rates for
12 % cache models using the saddle-point method (SPM).
13 %
14 % @par Syntax:
15 % @code
16 % [M, MU, MI, pi0, lE] = cache_miss_spm(gamma, m, lambda)
17 % @endcode
18 %
19 % @par Parameters:
20 % <table>
21 % <tr><th>Name<th>Description
22 % <tr><td>gamma<td>Item popularity probabilities
23 % <tr><td>m<td>Cache capacity vector
24 % <tr><td>lambda<td>(Optional) Arrival rates per user per item
25 % </table>
26 %
27 % @par Returns:
28 % <table>
29 % <tr><th>Name<th>Description
30 % <tr><td>M<td>Global miss rate
31 % <tr><td>MU<td>Per-user miss rate
32 % <tr><td>MI<td>Per-item miss rate
33 % <tr><td>pi0<td>Per-item miss probability
34 % <tr><td>lE<td>Log of normalizing constant
35 % </table>
36%}
37function [M,MU,MI,pi0,lE]=cache_miss_spm(gamma,m,lambda)
38% M: global miss rate
39% MU: per-user miss rate
40% MI: per-item miss rate
41ma=m; ma(1)=ma(1)+1;
42[~,lE,xi] = cache_spm(gamma,m);
43[~,lEa,~] = cache_spm(gamma,ma);
44M = exp(lEa - lE);
45if nargin>2
46 u=size(lambda,1);
47 n=size(lambda,2);
48 %h=size(lambda,3)-1;
49 pi0=zeros(1,n);
50 % compute MU
51 MU=zeros(u,1);
52 if nargout>1
53 for k=1:n
54 if sum(gamma(k,:))>0
55 [~,lE1(k)]=cache_spm(gamma(setdiff(1:n,k),:),m,xi);
56 pi0(k) = exp(lE1(k) - lE);
57 if pi0(k)>1 || pi0(k)<0 % try to recompute xi
58 [~,lE1(k)]=cache_spm(gamma(setdiff(1:n,k),:),m);
59 pi0(k) = exp(lE1(k) - lE);
60 end
61 for v=1:u
62 MU(v) = MU(v) + lambda(v,k,1)*pi0(k);
63 end
64 end
65 end
66 end
67 % compute MI
68 if nargout>2
69 MI=zeros(n,1);
70 for k=1:n
71 if sum(gamma(k,:))>0
72 MI(k) = MI(k) + sum(lambda(:,k,1))*exp(lE1(k)-lE);
73 else
74 MI(k)=0;
75 end
76 end
77 end
78end
79end