SROU is based on the ratio-of-uniforms method that uses universal inequalities to construct
a (universal) bounding rectangle. It works for T-concave distributions with
T(x)=−1/x.
Notice that the PDF does not integrate to 1. We can either pass the exact
area under the PDF during initialization of the generator or an upper
bound to the exact area under the PDF. Also, it is recommended to pass
the mode of the distribution to speed up the setup:
The main advantage of the method is a fast setup. This can be beneficial when one
repeatedly needs to generate small to moderate samples of a distribution with
different shape parameters. In such a situation, the setup step of
sampling.NumericalInverseHermite or sampling.NumericalInversePolynomial will
lead to poor performance. As an example, assume we are interested to generate
100 samples for the Gamma distribution with 1000 different shape parameters
given by np.linspace(1.5,5,1000).
>>> importmath>>> importwarnings>>> classGammaDist:... def__init__(self,p):... self.p=p... defpdf(self,x):... returnx**(self.p-1)*np.exp(-x)...>>> urng=np.random.default_rng()>>> p=np.linspace(1.5,5,1000)>>> res=np.empty((1000,100))>>> foriinrange(1000):... dist=GammaDist(p[i])... rng=SimpleRatioUniforms(dist,mode=p[i]-1,... pdf_area=math.gamma(p[i]),... random_state=urng)... withwarnings.catch_warnings():... warnings.filterwarnings("ignore",RuntimeWarning,"invalid value encountered in double_scalars")... warnings.filterwarnings("ignore",RuntimeWarning,"overflow encountered in exp")... res[i]=rng.rvs(100)