RandomLib  1.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Public Member Functions | List of all members
RandomLib::ExactPower< bits > Class Template Reference

Sample exactly from a power distribution. More...

#include <RandomLib/ExactPower.hpp>

Public Member Functions

template<class Random >
RandomNumber< bits > operator() (Random &r, unsigned n) const
 

Detailed Description

template<int bits = 1>
class RandomLib::ExactPower< bits >

Sample exactly from a power distribution.

Sample exactly from power distribution (n + 1) xn for x in (0,1) and integer n ≥ 0 using infinite precision. The template parameter bits specifies the number of bits in the base used for RandomNumber (i.e., base = 2bits).

This class uses some mutable RandomNumber objects. So a single ExactPower object cannot safely be used by multiple threads. In a multi-processing environment, each thread should use a thread-specific ExactPower object. In addition, these should be invoked with thread-specific random generator objects.

Template Parameters
bitsthe number of bits in each digit.

Definition at line 35 of file ExactPower.hpp.

Member Function Documentation

template<int bits>
template<class Random >
RandomNumber< bits > RandomLib::ExactPower< bits >::operator() ( Random r,
unsigned  n 
) const

Return the random deviate with a power distribution, (n + 1) xn for x in (0,1) and integer n ≥ 0. Returned result is a RandomNumber with base 2bits. For bits = 1, the number of random bits in the result and consumed are as follows:

 n    random bits
     result  consumed
 0   0        0
 1   2        4
 2   2.33     6.67
 3   2.67     9.24
 4   2.96    11.71
 5   3.20    14.11
 6   3.41    16.45
 7   3.59    18.75
 8   3.75    21.01
 9   3.89    23.25
10   4.02    25.47

The relative frequency of the results with bits = 1 and n = 2 can be is shown by the histogram

powerhist.png

The base of each rectangle gives the range represented by the corresponding binary number and the area is proportional to its frequency. A PDF version of this figure here. This allows the figure to be magnified to show the rectangles for all binary numbers up to 9 bits.

Template Parameters
Randomthe type of the random generator.
Parameters
[in,out]ra random generator.
[in]nthe power.
Returns
the random sample.

Definition at line 79 of file ExactPower.hpp.


The documentation for this class was generated from the following file: