LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
fj_xmax_emma.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_FJ_XMAX_EMMA_H
6#define LINE_API_FJ_XMAX_EMMA_H
7
8/**
9 * @file
10 * @ingroup api_fj
11 * EMMA (Extreme-value Maximum Moment Approximation) to the expected maximum
12 * of K i.i.d. samples.
13 *
14 * Templated port of matlab/src/api/fj/fj_xmax_emma.m, cross-checked against
15 * FJ_xmax.fj_xmax_emma in jar/src/main/java/jline/api/fj/FJ_xmax.java
16 * (identical; both use the same rounded constant phi = 0.570376, which is
17 * exp(-exp(-gamma)) to six places).
18 *
19 * exponential: E[Y_K] = -(1/mu) ln(1 - phi^{1/K})
20 * general: E[Y_K] = F^{-1}(phi^{1/K})
21 *
22 * static_assert(num_traits<T>::has_transcendental) -- a real root phi^{1/K}
23 * and a log. The general form takes the quantile function as a callable, so
24 * the caller supplies whatever inverse CDF it has.
25 */
26
27#include <functional>
28
30#include "line/num/number.h"
31#include "line/util/error.h"
32
33namespace line {
34namespace fj {
35
36/**
37 * Exponential branch.
38 *
39 * @param K number of samples, K >= 1
40 * @param mu rate of the exponential, > 0
41 */
42template <class T>
43T fj_xmax_emma(unsigned K, const T& mu) {
45 "fj_xmax_emma requires transcendental arithmetic");
46 detail::require_positive_K(K, "fj_xmax_emma");
47 if (mu <= num_traits<T>::from_int(0)) throw InputError("fj_xmax_emma: the rate mu must be positive");
48 const T one = num_traits<T>::from_int(1);
49 const T phi = num_traits<T>::from_double(0.570376);
50 const T root = detail::num_pow(phi, T(one / num_traits<T>::from_int(static_cast<long>(K))));
51 return -(one / mu) * detail::num_log(T(one - root));
52}
53
54/**
55 * General branch: the caller supplies the quantile function F^{-1}.
56 *
57 * @param K number of samples, K >= 1
58 * @param Finv inverse CDF of the branch distribution
59 */
60template <class T>
61T fj_xmax_emma(unsigned K, const std::function<T(const T&)>& Finv) {
63 "fj_xmax_emma requires transcendental arithmetic");
64 detail::require_positive_K(K, "fj_xmax_emma");
65 if (!Finv) throw InputError("fj_xmax_emma: the inverse CDF must be callable");
66 const T one = num_traits<T>::from_int(1);
67 const T phi = num_traits<T>::from_double(0.570376);
68 return Finv(T(detail::num_pow(phi, T(one / num_traits<T>::from_int(static_cast<long>(K))))));
69}
70
71} // namespace fj
72} // namespace line
73
74#endif // LINE_API_FJ_XMAX_EMMA_H
InputError(const std::string &what)
Definition error.h:39
The exception types the port throws.
Shared return types and arithmetic helpers for the templated fork-join port.
T fj_xmax_emma(unsigned K, const T &mu)
Exponential branch.
Number-type abstraction for the templated API port.