The OpenD Programming Language

mir.random.flex

Flex module that allows to sample from arbitrary random distributions.

Members

Functions

flex
auto flex(F0 f0, F1 f1, F2 f2, S c, S[] points, S rho, int maxApproxPoints)
auto flex(Pdf pdf, F0 f0, F1 f1, F2 f2, S c, S[] points, S rho, int maxApproxPoints)
auto flex(F0 f0, F1 f1, F2 f2, S[] cs, S[] points, S rho, int maxApproxPoints)
auto flex(Pdf pdf, F0 f0, F1 f1, F2 f2, S[] cs, S[] points, S rho, int maxApproxPoints)
auto flex(Pdf pdf, FlexInterval!S[] intervals)

The Transformed Density Rejection with Inflection Points (Flex) algorithm can sample from arbitrary distributions given its density function f, its first two derivatives and a partitioning into intervals with at most one inflection point. The partitioning needs to be mutually exclusive and sorted.

flexIntervals
FlexInterval!S[] flexIntervals(F0 f0, F1 f1, F2 f2, S[] cs, S[] points, S rho, int maxApproxPoints)

Calculate the intervals for the Flex algorithm for a T_c family given its density function, the first two derivatives and a valid start partitioning. The Flex algorithm will try to split the intervals until a chosen efficiency rho is reached.

flexInverse
S flexInverse(S x, S c)

Compute inverse transformation of a T_c family given point x. Based on Table 1, column 3 of Botts et al. (2013).

Structs

Flex
struct Flex(S, Pdf)

Data body of the Flex algorithm. Can be used to sample from the distribution.

FlexInterval
struct FlexInterval(S)

Reduced version of Interval. Contains only the necessary information needed in the generation phase.

Meta

Authors

Sebastian Wilzbach, Ilya Yaroshenko

This module is available in the extended configuration.

The Transformed Density Rejection with Inflection Points (Flex) algorithm can sample from arbitrary distributions given (1) its log-density function f, (2) its first two derivatives and (3) a partitioning into intervals with at most one inflection point.

These can be easily found by plotting f''. Inflection points can be identified by observing at which points f'' is 0 and an inflection interval which is defined by two inflection points can either be:

  • $(D g(x)) is entirely concave (f'' is entirely negative)
  • $(D g(x)) is entirely convex (f'' is entirely positive)
  • $(D g(x)) contains one inflection point (f'' intersects the x-axis once)

It is not important to identify the exact inflection points, but the user input requires:

  • Continuous density function $(D g(x)) .
  • Continuous differentiability of $(D g(x)) except in a finite number of points which need to have a one-sided derivative.
  • Doubled continuous differentiability of $(D g(x)) except in a finite number of points which need to be inflection points.
  • At most one inflection point per interval

Internally the Flex algorithm transforms the distribution with a special transformation function and constructs for every interval a linear hat function that majorizes the pdf and a linear squeeze function that is majorized by the pdf from the user-defined, mutually-exclusive partitioning.

Efficiency rho

In further steps the algorithm splits those intervals until a chosen efficiency rho between the ratio of the sum of all hat areas to the sum of all squeeze areas is reached. For example an efficiency of 1.1 means that 10 / 110 of all drawn uniform numbers don't match the target distribution and need be resampled. A higher efficiency constructs more intervals, and thus requires more iterations and a longer setup phase, but increases the speed of sampling.

Unbounded intervals

In each unbounded interval the transformation and thus the density must be concave and strictly monotone.

Transformation function (T_c)

The Flex algorithm uses a family of T_c transformations:

  • `T_0(x) = log(x)
  • `T_c(x) = sign(c) * x^c

Thus c has the following properties

  • Decreasing c may decrease the number of inflection points
  • For unbounded domains, c > -1 is required
  • For unbounded densities, c must be sufficiently small, but should be great than -1. A common choice is -0.5
  • c=0 is the pure log transformation and thus decreases the vulnerability for under- and overflows

References: Botts, Carsten, Wolfgang Hörmann, and Josef Leydold. "Transformed density rejection with inflection points." Statistics and Computing 23.2 (2013): 251-260.