bernoulli

Contents

bernoulli#

Generates Bernoulli distributed random values.

Description

The bernoulli class object is used in the generate and function to provide Bernoulli distributed random numbers with probability p of a single trial success, where \(p \in R; 0 \leq p \leq 1\).

The probability distribution is given by:

\[P(X = 1) = p\]
\[P(X = 0) = 1 - p\]

The cumulative distribution function is as follows:

\[\begin{split}F_p(x) = \begin{cases} 0, & x < 0 \\ 1 - p, & 0 \leq x < 1, x \in R \\ 1, & x \geq 1 \end{cases}\end{split}\]

class bernoulli#

Syntax

namespace oneapi::math::rng::device {
  template<typename IntType, typename Method>
  class bernoulli {
  public:
    using method_type = Method;
    using result_type = IntType;

    bernoulli();
    explicit bernoulli(float p);

    float p() const;
  };
}

Template parameters

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

  • std::uint8_t

  • std::int16_t

  • std::uint16_t

  • std::int32_t

  • std::uint32_t

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

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

  • oneapi::math::rng::bernoulli_method::by_default

  • oneapi::math::rng::bernoulli_method::icdf

See description of the methods in Distributions methods template parameter.

Class Members

Routine

Description

bernoulli()

Default constructor

explicit bernoulli(float p)

Constructor with parameters

float p() const

Method to obtain probability p

Member types

bernoulli::method_type = Method

Description

The type which defines transformation method for generation.

bernoulli::result_type = IntType

Description

The type which defines type of generated random numbers.

Constructors

bernoulli::bernoulli()

Description

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

explicit bernoulli::bernoulli(float p)

Description

Constructor with parameters. p is a probability.

Throws

oneapi::math::invalid_argument

Exception is thrown when p > 1, or p < 0

Characteristics

float bernoulli::p() const

Return Value

Returns the distribution parameter p - probability.

Parent topic: Device Distributions