LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
cache_erec.m
1%{ @file cache_erec.m
2 % @brief Recursive computation of the normalizing constant for cache models
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Computes the normalizing constant for cache models recursively
9 %
10 % @details
11 % This function recursively computes the normalizing constant E for
12 % cache models with given item popularity probabilities and cache capacity.
13 %
14 % @par Syntax:
15 % @code
16 % E = cache_erec(gamma, m)
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
24 % </table>
25 %
26 % @par Returns:
27 % <table>
28 % <tr><th>Name<th>Description
29 % <tr><td>E<td>Normalizing constant
30 % </table>
31%}
32function E=cache_erec(gamma,m)
33E = sub_cache_erec(gamma,m,length(gamma));
34end
35
36function E=sub_cache_erec(gamma,m,k)
37h=length(m);
38if sum(m)==0
39 E=1;
40 return
41end
42if sum(m)>k || min(m)<0
43 E=0;
44 return
45end
46
47if k==1 && sum(m)==1
48 j = find(m);
49 E=gamma(1,j);
50 return
51end
52E = sub_cache_erec(gamma,m,k-1);
53for j=1:h
54 if m(j)>0
55 E = E + gamma(k,j)*m(j)*sub_cache_erec(gamma,oner(m,j),k-1);
56 end
57end
58end