binomial

Contents

binomial#

Class is used for generation of binomially distributed integer types random numbers.

Description

The class object is used in the oneapi::math::rng::generate() function to provide random numbers binomially distributed with a number of independent Bernoulli trials \(m\), and with probability \(p\) of a single trial success, where \(p \in R; 0 \leq p \leq 1, m \in N\).

A binomially distributed variate represents the number of successes in \(m\) independent Bernoulli trials with probability of a single trial success \(p\).

The probability distribution is given by:

\[P(X = k) = C^k_{m}p^k(1 - p)^{m - k}, k \in \{0, 1, ... , m\}\]

The cumulative distribution function is as follows:

\[\begin{split}F_{m, p}(x) = \left\{ \begin{array}{rcl} 0, x < 0 \\ \sum^{\lfloor x \rfloor}_{k = 0} C^k_{m}p^k(1 - p)^{m - k}, 0 \leq x < m, x \in R \\ 1, x \ge m \end{array}\right.\end{split}\]

class binomial#

Syntax

namespace oneapi::math::rng {
template<typename IntType = std::int32_t, typename Method = binomial_method::by_default>
class binomial {
public:
    using method_type = Method;
    using result_type = IntType;
    binomial();
    explicit binomial(std::int32_t ntrial, double p);
    std::int32_t ntrial() const;
    double p() const;
};
}

Template parameters

typename IntType
Type of the produced values. Supported types:
  • std::int32_t

typename Method = oneapi::math::rng::binomial_method::by_default

Transformation method, which will be used for generation. Supported types:

  • oneapi::math::rng::binomial_method::by_default

  • oneapi::math::rng::binomial_method::btpe

See description of the methods in Distributions methods template parameter.

Class Members

Routine

Description

binomial()

Default constructor

explicit binomial(std::int32_t ntrial, double p)

Constructor with parameters

std::int32_t ntrial() const

Method to obtain number of independent trials m

double p() const

Method to obtain success probability of a single trial p

Member types

binomial::method_type = Method

Description

The type which defines transformation method for generation.

binomial::result_type = IntType

Description

The type which defines type of generated random numbers.

Constructors

binomial::binomial()

Description

Default constructor for distribution, parameters set as m = 5, p = 0.5.

explicit binomial::binomial(std::int32_t ntrial, double p)

Description

Constructor with parameters. ntrial is the number of independent trials, p is the success probability of a single trial.

Throws

oneapi::math::invalid_argument

Exception is thrown when \(p > 1.0\), or \(p < 0.0\), or \(ntrial < 1\)

Characteristics

std::int32_t binomial::ntrial() const

Return Value

Returns the distribution parameter m - number of independent trials.

double binomial::p() const

Return Value

Returns the distribution parameter p - success probability of a single trial.

Parent topic: Host Distributions