LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
cache_build_item_graphs.m
1%{ @file cache_build_item_graphs.m
2 % @brief Per-item access graph aggregated over users; {} when linear/absent.
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Build per-item (h+1)x(h+1) access graphs from ACCOST.
9 %
10 % @details
11 % ACCOST is the per-(user,item) access graph cell{v,k} (each an (h+1)x(h+1)
12 % matrix). Returns a 1xN cell of per-item graphs aggregated over users by
13 % request rate, or {} when ACCOST is absent or the standard linear chain (so
14 % the caller keeps the refined/linear path). Row 1 is miss admission, row 1+i
15 % a hit in list i.
16%}
17function G = cache_build_item_graphs(accost, lambda, n, h)
18G = {};
19if isempty(accost)
20 return;
21end
22lin = zeros(h+1, h+1); lin(1, 2) = 1;
23for a = 1:(h-1), lin(a+1, a+2) = 1; end
24lin(h+1, h+1) = 1;
25u = size(accost, 1);
26Gc = cell(1, n);
27isLinear = true;
28for k = 1:n
29 num = zeros(h+1, h+1); den = 0;
30 for v = 1:u
31 wv = sum(lambda(v, k, 1));
32 if ~isfinite(wv), wv = 0; end
33 gvk = accost{v, k};
34 if isempty(gvk), continue; end
35 num = num + wv * gvk;
36 den = den + wv;
37 end
38 if den > 0
39 gk = num / den;
40 else
41 gk = accost{1, k};
42 if isempty(gk), gk = lin; end
43 end
44 for a = 1:(h+1)
45 srow = sum(gk(a, :));
46 if srow > 0, gk(a, :) = gk(a, :) / srow; end
47 end
48 Gc{k} = gk;
49 if ~all(all(abs(gk - lin) < 1e-9))
50 isLinear = false;
51 end
52end
53if ~isLinear
54 G = Gc;
55end
56end