LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
cache_prob_spm.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_PROB_SPM_H
6
#define LINE_API_CACHE_PROB_SPM_H
7
8
/**
9
* @file
10
* @ingroup api_cache
11
* Saddle-point approximation of the per-item cache hit probabilities.
12
*
13
* Templated port of matlab/src/api/cache/cache_prob_spm.m, cross-checked
14
* against jar/src/main/java/jline/api/cache/Cache_prob_rayint.java (the JAR's
15
* only implementation of this shape; see the note below).
16
*
17
* Same ratio-of-constants identity as cache_prob_erec,
18
*
19
* prob(i,1+j) = m(j) gamma(i,j) exp(lE_i - lE),
20
*
21
* with lE the log normalizing constant from cache_spm and lE_i the same
22
* quantity for the model with item i deleted and list j one slot smaller. The
23
* miss probability closes the row. Because both constants are approximations
24
* the rows only sum to one up to the saddle-point error, which is why the
25
* reference wraps the miss entry in abs().
26
*
27
* ARITHMETIC: transcendental, inherited from cache_spm.
28
*/
29
30
#include <cmath>
31
#include <cstddef>
32
#include <vector>
33
34
#include "
line/api/cache/cache_erec.h
"
35
#include "
line/api/cache/cache_spm.h
"
36
#include "
line/num/number.h
"
37
#include "
line/util/error.h
"
38
#include "
line/util/matrix.h
"
39
40
namespace
line
{
41
namespace
cache
{
42
43
/**
44
* @brief Saddle-point approximation of the per-item cache hit probabilities.
45
*
46
* @param gamma (n x h) access factors
47
* @param m (h) list capacities
48
* @return (n x (h+1)); column 0 miss, column 1+j hit in list j
49
*/
50
template
<
class
T>
51
Matrix<T>
cache_prob_spm
(
const
Matrix<T>
& gamma,
const
std::vector<int>& m) {
52
static_assert
(
num_traits<T>::has_transcendental
,
53
"cache_prob_spm requires transcendental arithmetic"
);
54
using
std::exp;
55
const
std::size_t n = gamma.
rows
();
56
const
std::size_t h = gamma.
cols
();
57
if
(h != m.size())
throw
InputError
(
"cache_prob_spm: gamma and m disagree on the list count"
);
58
59
const
T lE =
cache_spm
(gamma, m).lZ;
60
const
T zero =
num_traits<T>::from_int
(0);
61
const
T one =
num_traits<T>::from_int
(1);
62
63
Matrix<T>
prob(n, h + 1, zero);
64
for
(std::size_t i = 0; i < n; ++i) {
65
T hits = zero;
66
for
(std::size_t j = 0; j < h; ++j) {
67
std::vector<int> mj = m;
68
mj[j] -= 1;
69
const
T lEi =
cache_spm
(detail::gamma_without_row(gamma, i), mj).lZ;
70
const
T p =
71
num_traits<T>::from_int
(
static_cast<
long
>
(m[j])) * gamma(i, j) * exp(T(lEi - lE));
72
prob(i, j + 1) = p;
73
hits += p;
74
}
75
prob(i, 0) =
num_abs
(T(one - hits));
76
}
77
return
prob;
78
}
79
80
}
// namespace cache
81
}
// namespace line
82
83
#endif
// LINE_API_CACHE_PROB_SPM_H
cache_erec.h
Exact recursive normalizing constant of a multi-list cache model.
cache_spm.h
Saddle-point approximation of the cache normalizing constant.
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
line::Matrix
Definition
matrix.h:56
line::Matrix::cols
std::size_t cols() const
Definition
matrix.h:90
line::Matrix::rows
std::size_t rows() const
Definition
matrix.h:89
error.h
The exception types the port throws.
matrix.h
Dense matrix and non-owning view.
line::cache
Definition
cache_cost.h:42
line::cache::cache_spm
CacheSpmResult< T > cache_spm(const Matrix< T > &gamma_in, const std::vector< int > &m)
Saddle-point approximation of the cache normalizing constant.
Definition
cache_spm.h:152
line::cache::cache_prob_spm
Matrix< T > cache_prob_spm(const Matrix< T > &gamma, const std::vector< int > &m)
Saddle-point approximation of the per-item cache hit probabilities.
Definition
cache_prob_spm.h:51
line
Definition
aoi_dist2ph.h:52
line::num_abs
T num_abs(const T &v)
Definition
number.h:172
number.h
Number-type abstraction for the templated API port.
line::num_traits
Definition
number.h:111
include
line
api
cache
cache_prob_spm.h
Generated by
1.18.0