#include <NR.hpp>
Static Public Member Functions | |
template<class V > | |
static Array | array (const V &sourcev) |
template<class V , typename = std::enable_if_t<!CompileTimeUtils::isNumericArgList<V>()>> | |
static void | assign (Array &targetv, const V &sourcev) |
template<typename... Values, typename = std::enable_if_t<sizeof...(Values) != 0 && CompileTimeUtils::isFloatArgList<Values...>()>> | |
static void | assign (Array &targetv, Values... values) |
static double | buildLinearGrid (Array &xv, double xmin, double xmax, int n) |
static void | buildLogGrid (Array &xv, double xmin, double xmax, int n) |
static void | buildPowerLawGrid (Array &xv, double xmin, double xmax, int n, double ratio) |
static void | buildSymmetricPowerLawGrid (Array &xv, double xmin, double xmax, int n, double ratio) |
static void | buildZeroLogGrid (Array &xv, double xmin, double xmax, int n) |
static double | cdf (Array &Pv, const Array &pv) |
template<typename Functor > | |
static double | cdf (Array &Pv, int n, Functor pv) |
template<double interpolateFunction> | |
static double | cdf (Array &xv, Array &pv, Array &Pv, const Array &inxv, const Array &inpv, Range xrange) |
static double | cdf2 (bool loglog, const Array &xv, Array &pv, Array &Pv) |
template<double interpolateFunction> | |
static Array | clampedResample (const Array &xresv, const Array &xoriv, const Array &yoriv) |
template<double interpolateFunction> | |
static double | clampedValue (double x, const Array &xv, const Array &yv) |
static double | interpolateLinLin (double x, double x1, double x2, double f1, double f2) |
static double | interpolateLogLin (double x, double x1, double x2, double f1, double f2) |
static double | interpolateLogLog (double x, double x1, double x2, double f1, double f2) |
static int | locate (const Array &xv, double x) |
template<typename T > | |
static int | locate (const std::vector< T > &xv, const T &x) |
static int | locateBasicImpl (const Array &xv, double x, int n) |
static int | locateClip (const Array &xv, double x) |
static int | locateFail (const Array &xv, double x) |
template<double interpolateFunction> | |
static Array | resample (const Array &xresv, const Array &xoriv, const Array &yoriv) |
static void | reverse (Array &xv, size_t blocksize=1) |
static void | sort (Array &xv) |
template<typename T > | |
static void | sort (std::vector< T > &xv) |
template<typename T > | |
static void | unique (std::vector< T > &xv) |
template<double interpolateFunction> | |
static double | value (double x, const Array &xv, const Array &yv) |
Static Private Member Functions | |
template<typename... Values> | |
static void | assignValues (size_t index, Array &target, double value, Values... values) |
static void | assignValues (size_t, Array &) |
This static class contains a collection of functions that operate on Array objects and on std::vector<T> objects where T is some numeric type. Most implementations are provided inline in the header.
|
inlinestatic |
This template function converts the source sequence to an Array object and returns the result. This template function works for any source container type with indexed random access (specifically including std::vector), and for any item types, as long as the source items can be assigned to or converted to double.
|
inlinestatic |
This template function assigns the source sequence to the destination array, resizing the destination array if necessary. This template function works for any source container type with indexed random access (specifically including std::vector), and for any item types, as long as the source items can be assigned to or converted to double.
|
inlinestatic |
This template function assigns the floating point values specified as its arguments to the destination array, resizing the destination array if necessary.
|
inlinestatic |
This function builds a linear grid over the specified range
The function returns the bin width, i.e. the distance between two adjacent border points, given by
|
inlinestatic |
This function builds a logarithmic grid over the specified range
|
inlinestatic |
This function builds a power-law grid over the specified range
with
|
inlinestatic |
This function builds a symmetrical power-law grid over the specified range
with
On the other hand, if
with again
|
inlinestatic |
This function builds a grid with its first bin starting at zero, and subsequent logarithmic border points over the specified range
Given a discrete distribution over
this function builds the corresponding normalized cumulative distribution
with
|
inlinestatic |
Given a discrete distribution over
this function builds the corresponding normalized cumulative distribution
with
|
inlinestatic |
Given the tabulated values for a continuous probability distribution, this function constructs both the normalized probability density function (pdf) and the corresponding normalized cumulative distribution function (cdf) within a given range. The incoming distribution is specified by the inxv and inpv arrays and does not need to be normalized. The specified xrange must overlap the incoming grid, but it does not need to coincide with it. The function constructs a new grid xv that matches the given range and then constructs both the normalized pdf pv and the normalized cdf Pv corresponding to this new grid. It returns the factor used to normalize the distributions.
The outer grid points of the new grid match the specified range, and therefore usually do not occur in the incoming grid. The pv values for those new grid points are interpolated using the function specified as template argument. The interpolation functions provided by this namespace can be passed as a template argument for this purpose.
The interpolation function specified as a template argument also determines the integration mechanism used to calculate the cdf. If the NR::interpolateLogLog() function is specified, it is assumed that the pdf behaves as a power-law between any two grid points, and the integration is performed accordingly. In all other cases, piece-wise linear behavior is assumed and regular trapezium-rule integration is used.
This function calculates the normalized cdf Pv for the given axis grid xv and corresponding unnormalized pdf pv. It also normalizes the incoming pdf pv and returns the normalization factor. This non-template function is not implemented inline (1) to avoid code-duplication and (2) to avoid propagating the dependencies (includes) of the implementation to all NR users.
If the loglog flag is false, piece-wise linear behavior of both the pdf and cdf is assumed and regular trapezium-rule integration is used. If the loglog flag is true, it is assumed that the pdf is linear in log-log space between any two grid points (equivalent to power-law behavior), and the integration is performed accordingly, as described below.
Consider the pdf values
The area under the curve is then
where
|
inlinestatic |
This template function resamples the function values
|
inlinestatic |
This template function returns the interpolated function value
If
The function assumes that the specified arrays contain the same number of elements, that they each contain at least two elements, and that
|
inlinestatic |
This function computes the interpolated value of a one-dimensional function, given its values at the edges of an interval. Both the axes coordinate
|
inlinestatic |
This function computes the interpolated value of a one-dimensional function, given its values at the edges of an interval. The axes coordinate
|
inlinestatic |
This function computes the interpolated value of a one-dimensional function, given its values at the edges of an interval. The coordinates on both axes are interpolated logarithmically, and thus all arguments must have positive values. If the function values
|
inlinestatic |
The locate(), locateClip() and locateFail() functions perform a binary search on the ordered sequence of double values in an array. There are subtle differences between the various "locate" functions, as decribed below. All functions assume that the specified array contains at least two elements, and that all elements are sorted in ascending order. If this is not the case, the result is undefined. The algorithm is adapted from the Numerical Recipes in C++ handbook. The array passed as the first function argument specifies an ordered sequence
Function | | | Comments (note that there are |
locate() | Out-of-range values are indicated with a corresponding out-of-range index | ||
locateClip() | Out-of-range values are considered to be inside the corresponding outermost bin | ||
locateFail() | Out-of-range values are indicated with a negative index |
|
inlinestatic |
This template function quickly performs a binary search on an ordered sequence of items provided as a std::vector<T>. It works for any item type T that implements the less-than operator (including the built-in numeric types). Given a sequence
|
inlinestatic |
This function is an implementation detail and not intended for public use. See the description of the locate() function for more information.
|
inlinestatic |
This function performs a binary search on the ordered sequence of double values in an array. See the description of the locate() function for more information.
|
inlinestatic |
This function performs a binary search on the ordered sequence of double values in an array. See the description of the locate() function for more information.
|
inlinestatic |
This template function resamples the function values
|
static |
This function reverses blocks of values in the specified array. The number of values in the array must be an integer multiple of the specified block size. If not, the behavior is undefined.
|
inlinestatic |
This function sorts the values in the specified array.
|
inlinestatic |
This template function sorts a sequence of items given as a std::vector<T> where T is any built-in or user-defined type that implements the less-than operator (including the standard numeric types).
|
inlinestatic |
This template function sorts and removes duplicates from a sequence of items given as a std::vector<T> where T is any built-in or user-defined type that implements the less-than operator (including the standard numeric types).
|
inlinestatic |
This template function returns the interpolated function value
If
The function assumes that the specified arrays contain the same number of elements, that they each contain at least two elements, and that