#include <map>
#include <random>
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <math.h>
Go to the source code of this file.
|
| template<typename T > |
| T | round (T v, int n) |
| |
| template<typename T > |
| T | get_log1pexp_breakout_bound (const double precision, T f(T), const T lower=-1e6, const T upper=1e6) |
| | Tis takes a function f(x) and finds a bound B so that f(x) < precision for all x < B. This is useful in logsumexp where at compile time we don't bother adding if the addition will be too tiny. For instance: constexpr auto f = +[](T x) -> const double {return log1p(exp(x));}; const T bound = get_fx_compiletime_bound<T>(1e-6, f);. More...
|
| |
| template<typename T > |
| T | logplusexp (const T a, const T b) |
| |
| template<typename T > |
| T | logplusexp_full (const T a, const T b) |
| | logsumexp with no shortcuts for precision More...
|
| |
| template<typename t > |
| double | logsumexp (const t &v) |
| | Compute log(sum(exp(v)). For now, this just unrolls logplusexp, but we might consider the faster (standard) variant where we pull out the max. More...
|
| |
| template<typename t > |
| double | logsumexp (const std::vector< t > &v, double f(const t &)) |
| |
| template<typename T > |
| int | sgn (T val) |
| | Sign function. More...
|
| |
| template<typename T > |
| T | sgnlog (T val) |
| | The log of |val| but with sign preserved. More...
|
| |
| double | mylgamma (double v) |
| |
| double | mygamma (double v) |
| |
| double | lfactorial (double x) |
| |
| template<typename T > |
| T | inv_logit (const T z) |
| | logic / inverse logit are pretty useful More...
|
| |
| template<typename T > |
| T | logit (const T p) |
| |
| template<typename T > |
| T | weighted_quantile (std::vector< std::pair< T, double >> &v, double q) |
| |
|
| const double | LOG2 = log(2.0) |
| |
| const double | ROOT2 = sqrt(2.0) |
| |
| constexpr double | infinity = std::numeric_limits<double>::infinity() |
| |
| constexpr double | NaN = std::numeric_limits<double>::quiet_NaN() |
| |
| constexpr double | pi = M_PI |
| |
| constexpr double | tau = 2*pi |
| |
◆ _REENTRANT
◆ get_log1pexp_breakout_bound()
template<typename T >
| T get_log1pexp_breakout_bound |
( |
const double |
precision, |
|
|
T |
fT, |
|
|
const T |
lower = -1e6, |
|
|
const T |
upper = 1e6 |
|
) |
| |
Tis takes a function f(x) and finds a bound B so that f(x) < precision for all x < B. This is useful in logsumexp where at compile time we don't bother adding if the addition will be too tiny. For instance: constexpr auto f = +[](T x) -> const double {return log1p(exp(x));}; const T bound = get_fx_compiletime_bound<T>(1e-6, f);.
◆ inv_logit()
logic / inverse logit are pretty useful
◆ lfactorial()
| double lfactorial |
( |
double |
x | ) |
|
◆ logit()
◆ logplusexp()
template<typename T >
| T logplusexp |
( |
const T |
a, |
|
|
const T |
b |
|
) |
| |
◆ logplusexp_full()
template<typename T >
| T logplusexp_full |
( |
const T |
a, |
|
|
const T |
b |
|
) |
| |
logsumexp with no shortcuts for precision
- Parameters
-
- Returns
◆ logsumexp() [1/2]
template<typename t >
| double logsumexp |
( |
const t & |
v | ) |
|
Compute log(sum(exp(v)). For now, this just unrolls logplusexp, but we might consider the faster (standard) variant where we pull out the max.
- Parameters
-
- Returns
◆ logsumexp() [2/2]
template<typename t >
| double logsumexp |
( |
const std::vector< t > & |
v, |
|
|
double |
fconst t & |
|
) |
| |
◆ mygamma()
| double mygamma |
( |
double |
v | ) |
|
◆ mylgamma()
| double mylgamma |
( |
double |
v | ) |
|
◆ round()
◆ sgn()
Sign function.
- Parameters
-
- Returns
◆ sgnlog()
The log of |val| but with sign preserved.
- Parameters
-
- Returns
◆ weighted_quantile()
template<typename T >
| T weighted_quantile |
( |
std::vector< std::pair< T, double >> & |
v, |
|
|
double |
q |
|
) |
| |
approximate equality
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
template<typename T>
bool approx_eq(const T x, const T y, double prec=0.00001) {
return abs(x-y)<prec;
}
Weighted quantiles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
◆ infinity
| constexpr double infinity = std::numeric_limits<double>::infinity() |
◆ LOG2
| const double LOG2 = log(2.0) |
◆ NaN
| constexpr double NaN = std::numeric_limits<double>::quiet_NaN() |
◆ pi
| constexpr double pi = M_PI |
◆ ROOT2
| const double ROOT2 = sqrt(2.0) |
◆ tau
| constexpr double tau = 2*pi |