LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
moment_binotrans.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_MOMENT_MOMENT_BINOTRANS_H
6
#define LINE_API_MOMENT_MOMENT_BINOTRANS_H
7
8
/**
9
* @file
10
* @ingroup api_moment
11
* Binomial transform with alternating signs.
12
*
13
* Templated port of matlab/src/api/moment/moment_binotrans.m.
14
*
15
* Applied to a moment sequence m_i = E[X^i] it returns the moments of the unit
16
* DOWNSHIFT, y_i = E[(X-1)^i]. It is NOT an involution -- an easy thing to
17
* assume from the alternating signs, and wrong: its inverse is
18
* moment_binotransinv, the unsigned transform.
19
*
20
* Every operation is integer or rational, so the exact instantiation returns
21
* the transform with no rounding at all. That matters more here than almost anywhere else in the API:
22
* the alternating binomial sums of the moment conversions cancel
23
* catastrophically in double arithmetic once the order grows.
24
*/
25
26
#include <vector>
27
28
#include "
line/num/number.h
"
29
#include "
line/util/error.h
"
30
#include "
line/util/matrix.h
"
31
#include "
line/util/population.h
"
32
33
namespace
line
{
34
namespace
moment
{
35
36
/** y_i = sum_k (-1)^(i-k) C(i,k) x_k. */
37
template
<
class
T>
38
std::vector<T>
moment_binotrans
(
const
std::vector<T>& x) {
39
const
std::size_t n = x.size();
40
std::vector<T> y(n,
num_traits<T>::from_int
(0));
41
for
(std::size_t i = 0; i < n; ++i)
42
for
(std::size_t k = 0; k <= i; ++k) {
43
const
T term =
num_nck<T>
(
static_cast<
int
>
(i),
static_cast<
int
>
(k)) * x[k];
44
y[i] += ((i - k) % 2 == 0) ? term : -term;
45
}
46
return
y;
47
}
48
49
}
// namespace moment
50
}
// namespace line
51
52
#endif
error.h
The exception types the port throws.
matrix.h
Dense matrix and non-owning view.
line::moment
Definition
moment_apply.h:28
line::moment::moment_binotrans
std::vector< T > moment_binotrans(const std::vector< T > &x)
y_i = sum_k (-1)^(i-k) C(i,k) x_k.
Definition
moment_binotrans.h:38
line
Definition
aoi_dist2ph.h:52
line::num_nck
T num_nck(int n, int k)
Binomial coefficient as a value of T, by the Pascal recurrence.
Definition
population.h:87
number.h
Number-type abstraction for the templated API port.
population.h
Population-vector enumeration and combinatorics.
line::num_traits
Definition
number.h:111
include
line
api
moment
moment_binotrans.h
Generated by
1.18.0