LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
moment_tail.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_TAIL_H
6#define LINE_API_MOMENT_MOMENT_TAIL_H
7
8/**
9 * @file
10 * @ingroup api_moment
11 * Binomial moments from tail moments and the inverse.
12 *
13 * Templated port of matlab/src/api/moment/moment_binomial_from_tail.m and
14 * moment_tail_from_binomial.m. These are the only edges of the house of moments
15 * whose table is UPPER triangular, so both directions read the WHOLE remaining
16 * sequence: b_i depends on t_i,...,t_n. Truncating the input therefore
17 * truncates the information, not just the output order.
18 *
19 * Reference:
20 * A. Heindl and A. van de Liefvoort. Moment conversions for discrete
21 * distributions. PMCCS, 2003.
22 */
23
24#include <vector>
25
27#include "line/num/number.h"
28#include "line/util/error.h"
29#include "line/util/matrix.h"
30
31namespace line {
32namespace moment {
33
34/** b_i = sum_{k>=i} C(k-1,i-1) t_k. */
35template <class T>
36std::vector<T> moment_binomial_from_tail(const std::vector<T>& t) {
37 if (t.empty()) throw InputError("moment_binomial_from_tail: t must be nonempty");
39 moment_housematrix<T>(MomentEdge::BinomialFromTail, static_cast<int>(t.size()) - 1), t);
40}
41
42/** t_i = sum_{k>=i} (-1)^(k-i) C(k-1,i-1) b_k. */
43template <class T>
44std::vector<T> moment_tail_from_binomial(const std::vector<T>& b) {
45 if (b.empty()) throw InputError("moment_tail_from_binomial: b must be nonempty");
47 moment_housematrix<T>(MomentEdge::TailFromBinomial, static_cast<int>(b.size()) - 1), b);
48}
49
50} // namespace moment
51} // namespace line
52
53#endif
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
Dense matrix and non-owning view.
Conversion matrix of one edge of the house of moments.
Matrix< T > moment_housematrix(MomentEdge edge, int n)
(n+1)x(n+1) conversion table of the given edge.
std::vector< T > moment_tail_from_binomial(const std::vector< T > &b)
ti = sum{k>=i} (-1)^(k-i) C(k-1,i-1) b_k.
Definition moment_tail.h:44
std::vector< T > moment_apply_full(const Matrix< T > &A, const std::vector< T > &v)
Full matrix-vector product, needed because the tail edges are upper triangular.
std::vector< T > moment_binomial_from_tail(const std::vector< T > &t)
bi = sum{k>=i} C(k-1,i-1) t_k.
Definition moment_tail.h:36
Number-type abstraction for the templated API port.