Verify hat function and squeezes in a given unuran
generator
that implements a rejection method.
[Advanced] -- Verify rejection method.
unuran.verify.hat(unr, n=1e5, show=TRUE)
Ratio of number occurrences where the hat and squeezes violate the inequality and the sample size.
an unuran
object.
sample size. (integer)
whether the result is printed on the console. (boolean)
Josef Leydold and Wolfgang H\"ormann unuran@statmath.wu.ac.at.
UNU.RAN is a library of so called black-box algorithms. For algorithms based on the rejection method this means that hat and squeezes are created automatically during the setup. Obviously not all algorithms work for all distribution. Then usually the setup fails (which is good, since then one does not silently obtain a random sample from a distribution other then the requested.)
Although we have tested these algorithms with a lot of distributions (including those with extreme properties) there is still some (minor) chance that hat and squeezes are computed without any warnings, but are incorrect, i.e., the inequalities $$squeeze(x) \le density(x) \le hat(x)$$ are not satisfied for all \(x\). This might happen due to serious round-off errors for densities with extreme properties (e.g., sharp and narrow peaks). But it also might be caused by some incorrect additional information about the distribution given by the user which has not been detected by various checks during the setup. If one is unsure about his or her chosen generation method one can check these inequalities.
Routine unuran.verify.hat
allows to run generator unr
and check whether the two inequalities are violated. This is done for
every point \(x\) that is sampled from the hat distribution. This
includes also those points that are rejected.
The function counts the occurrences of such evaluations and
returns the ratio of this number and the sample size n
.
(It is thus a little bit too high since the total number of generated
but rejected points is not known.)
Yet, it does not provide any information about the magnitude of
violation of the inequality.
If show
is TRUE
then this routine prints this ratio and
some diagnostcs to the console.
Routine unuran.verify.hat
does not work for algorithms that do
not implement a rejection method.
unuran
.
## Create a generator object that implements a rejection method
unr <- tdrd.new(udnorm())
## Verify hat and squeeze
unuran.verify.hat(unr)
Run the code above in your browser using DataLab