LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
cache_miss_fpi.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_API_CACHE_MISS_FPI_H
6#define LINE_API_CACHE_MISS_FPI_H
7
8/**
9 * @file
10 * @ingroup api_cache
11 * Cache miss rates from the fixed-point multipliers.
12 *
13 * Templated port of matlab/src/api/cache/cache_miss_fpi.m, cross-checked
14 * against jar/src/main/java/jline/api/cache/Cache_miss_fpi.java.
15 *
16 * With xi from cache_xi_fp and S(i) = sum_l gamma(i,l) xi(l), the probability
17 * that item i is absent from the cache is pi0(i) = 1/(1+S(i)), so
18 *
19 * MI(i) = (sum_v lambda(v,i)) pi0(i), MU(v) = sum_i lambda(v,i) pi0(i),
20 * M = sum_i MI(i).
21 *
22 * ARITHMETIC: transcendental, inherited from cache_xi_fp.
23 *
24 * Note the miss probability used here, 1/(1+S), is the correct per-item form;
25 * it is NOT the 1 - sum_l pij(i,l) returned by cache_xi_fp, which is floored at
26 * 1e-14. The two agree up to that floor.
27 */
28
29#include <cstddef>
30#include <vector>
31
34#include "line/num/number.h"
35#include "line/util/error.h"
36#include "line/util/matrix.h"
37
38namespace line {
39namespace cache {
40
41/**
42 * @brief Cache miss rates from the fixed-point multipliers.
43 *
44 * @param gamma (n x h) access factors
45 * @param m (h) list capacities
46 * @param lambda (u x n) per-user per-item request rates
47 */
48template <class T>
49CacheMissResult<T> cache_miss_fpi(const Matrix<T>& gamma, const std::vector<int>& m,
50 const Matrix<T>& lambda) {
52 "cache_miss_fpi requires transcendental arithmetic");
53 const std::size_t n = gamma.rows();
54 const std::size_t h = gamma.cols();
55 if (lambda.cols() != n)
56 throw InputError("cache_miss_fpi: lambda and gamma disagree on the number of items");
57 const std::size_t u = lambda.rows();
58
59 const CacheXiFpResult<T> f = cache_xi_fp(gamma, m);
60 const T zero = num_traits<T>::from_int(0);
61 const T one = num_traits<T>::from_int(1);
62
64 r.pi0.assign(n, zero);
65 r.MI.assign(n, zero);
66 r.MU.assign(u, zero);
67 r.M = zero;
68
69 for (std::size_t i = 0; i < n; ++i) {
70 T s = zero;
71 for (std::size_t l = 0; l < h; ++l) s += gamma(i, l) * f.xi[l];
72 r.pi0[i] = one / (one + s);
73 T lam = zero;
74 for (std::size_t v = 0; v < u; ++v) lam += lambda(v, i);
75 r.MI[i] = lam * r.pi0[i];
76 r.M += r.MI[i];
77 for (std::size_t v = 0; v < u; ++v) r.MU[v] += lambda(v, i) * r.pi0[i];
78 }
79 return r;
80}
81
82} // namespace cache
83} // namespace line
84
85#endif // LINE_API_CACHE_MISS_FPI_H
Exact cache miss rates from the recursive normalizing constant.
Lagrange multipliers of a multi-list cache by fixed-point iteration.
InputError(const std::string &what)
Definition error.h:39
std::size_t cols() const
Definition matrix.h:90
std::size_t rows() const
Definition matrix.h:89
The exception types the port throws.
Dense matrix and non-owning view.
CacheXiFpResult< T > cache_xi_fp(const Matrix< T > &gamma, const std::vector< int > &m)
Lagrange multipliers of a multi-list cache by fixed-point iteration.
Definition cache_xi_fp.h:65
CacheMissResult< T > cache_miss_fpi(const Matrix< T > &gamma, const std::vector< int > &m, const Matrix< T > &lambda)
Cache miss rates from the fixed-point multipliers.
Number-type abstraction for the templated API port.
Return value of cache_miss, mirroring [M,MU,MI,pi0].
Definition cache_miss.h:49
std::vector< T > MI
(n) per-item miss rate; empty when no lambda given
Definition cache_miss.h:52
std::vector< T > MU
(u) per-user miss rate; empty when no lambda given
Definition cache_miss.h:51
std::vector< T > pi0
(n) per-item miss probability; empty when no lambda given
Definition cache_miss.h:53
Return value of cache_xi_fp, mirroring [xi,pi0,pij,it].
Definition cache_xi_fp.h:51
std::vector< T > xi
(h) Lagrange multipliers
Definition cache_xi_fp.h:52