TDR is an acceptance/rejection method that uses the concavity of a
transformed density to construct hat function and squeezes automatically.
Most universal algorithms are very slow compared to algorithms that are
specialized to that distribution. Algorithms that are fast have a slow
setup and require large tables. The aim of this universal method is to
provide an algorithm that is not too slow and needs only a short setup.
This method can be applied to univariate and unimodal continuous
distributions with T-concave density function. See [1] and [2] for
more details.
Parameters:
distobject
An instance of a class with pdf and dpdf methods.
pdf: PDF of the distribution. The signature of the PDF is
expected to be: defpdf(self,x:float)->float. i.e.
the PDF should accept a Python float and
return a Python float. It doesn’t need to integrate to 1 i.e.
the PDF doesn’t need to be normalized.
dpdf: Derivative of the PDF w.r.t x (i.e. the variate). Must
have the same signature as the PDF.
modefloat, optional
(Exact) Mode of the distribution. Default is None.
centerfloat, optional
Approximate location of the mode or the mean of the distribution.
This location provides some information about the main part of the
PDF and is used to avoid numerical problems. Default is None.
domainlist or tuple of length 2, optional
The support of the distribution.
Default is None. When None:
If a support method is provided by the distribution object
dist, it is used to set the domain of the distribution.
Otherwise the support is assumed to be \((-\infty, \infty)\).
c{-0.5, 0.}, optional
Set parameter c for the transformation function T. The
default is -0.5. The transformation of the PDF must be concave in
order to construct the hat function. Such a PDF is called T-concave.
Currently the following transformations are supported:
If an integer, it defines the number of construction points. If it
is array-like, the elements of the array are used as construction
points. Default is 30.
use_darsbool, optional
If True, "derandomized adaptive rejection sampling" (DARS) is used
in setup. See [1] for the details of the DARS algorithm. Default
is True.
max_squeeze_hat_ratiofloat, optional
Set upper bound for the ratio (area below squeeze) / (area below hat).
It must be a number between 0 and 1. Default is 0.99.
A NumPy random number generator or seed for the underlying NumPy random
number generator used to generate the stream of uniform random numbers.
If random_state is None (or np.random), the numpy.random.RandomState
singleton is used.
If random_state is an int, a new RandomState instance is used,
seeded with random_state.
If random_state is already a Generator or RandomState instance then
that instance is used.
Hörmann, Wolfgang. "A rejection technique for sampling from
T-concave distributions." ACM Transactions on Mathematical
Software (TOMS) 21.2 (1995): 182-193
[3]
W.R. Gilks and P. Wild (1992). Adaptive rejection sampling for
Gibbs sampling, Applied Statistics 41, pp. 337-348.
Notice that the PDF doesn’t integrate to 1. As this is a rejection based
method, we need not have a normalized PDF. To initialize the generator,
we can use:
Domain can be very useful to truncate the distribution but to avoid passing
it every time to the constructor, a default domain can be set by providing a
support method in the distribution object (dist):