75 "cache_miss_asy is a tolerance-stopped fixed point and needs transcendental "
77 const std::size_t h = gamma.
rows();
78 const std::size_t n = gamma.
cols();
80 throw InputError(
"cache_miss_asy: gamma is list-major and disagrees with m on the list "
82 if (n == 0)
throw InputError(
"cache_miss_asy: no items");
88 for (std::size_t l = 0; l < h; ++l) {
89 if (m[l] < 0)
return one;
92 if (mtot == 0)
return one;
98 std::vector<T> prev(n, zero);
99 std::vector<T> next(n, zero);
103 for (
int iter = 0; iter < maxIter; ++iter) {
105 for (std::size_t k = 0; k < n; ++k) {
106 T numer = zero, denom = zero;
107 for (std::size_t l = 0; l < h; ++l) {
108 const int cap = m[l];
109 if (cap <= 0)
continue;
111 for (std::size_t j = 0; j < n; ++j)
112 if (j != k) pop.push_back(T(gamma(l, j) * T(one - prev[j])));
114 std::sort(pop.begin(), pop.end(), [](
const T& a,
const T& b) { return b < a; });
115 const std::size_t take =
116 std::min(
static_cast<std::size_t
>(cap), pop.size());
119 if (take <
static_cast<std::size_t
>(cap)) {
122 }
else if (take > 0) {
123 const T weakest = pop[take - 1];
124 if (T(gamma(l, k) * T(one - prev[k])) > weakest) notInCache = zero;
126 numer += gamma(l, k) * notInCache;
127 denom += gamma(l, k);
129 next[k] = denom > tiny ? T(numer / denom) : one;
134 for (std::size_t k = 0; k < n; ++k) {
135 const T d =
num_abs(T(pi[k] - prev[k]));
136 if (d > diff) diff = d;
138 if (diff < tolerance)
break;
141 T missRate = zero, totalRate = zero;
142 for (std::size_t l = 0; l < h; ++l) {
143 for (std::size_t k = 0; k < n; ++k) {
144 missRate += gamma(l, k) * pi[k];
145 totalRate += gamma(l, k);
148 return totalRate > tiny ? T(missRate / totalRate) : one;
T cache_miss_asy(const Matrix< T > &gamma, const std::vector< int > &m, int maxIter, const T &tolerance)
Asymptotic (large-cache) miss ratio by a rank-threshold fixed point.