multinomial

multinomial#

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

Description

The class object is used in the oneapi::math::rng::generate() function to provide n random numbers multinomially distributed, with independent trials \((ntrial, m)\) and possible mutually exclusive outcomes \(k\), with corresponding probabilities \(p_i\), where \(p_i \in R; 0 \leq p_i \leq 1; m, k \in N\).

The probability distribution is given by:

\[P(X_1 = x_1, ..., X_k = x_k) = \frac{m!}{\Pi^k_{i = 1}x_i!}\Pi^k_{i = 1}p_i^{x_i}, 0 \leq x_i \leq m, \sum^{k}_{i = 1}x_i = m\]

class multinomial#

Let SequenceContainerOrView be a type that can be one of C++ Sequence containers or C++ Views (span, mdspan). It’s implementation defined which type SequenceContainerOrView represents.

Syntax

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

Template parameters

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

  • std::uint32_t

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

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

  • oneapi::math::rng::multinomial_method::by_default

  • oneapi::math::rng::multinomial_method::poisson_icdf_based

See description of the methods in Distributions methods template parameter.

Class Members

Routine

Description

explicit multinomial(double ntrial, SequenceContainerOrView<double> p)

Constructor with parameters

std::int32_t ntrial() const

Method to obtain number of independent trials

SequenceContainerOrView<double> p() const

Method to obtain a probability parameter of possible outcomes

Member types

multinomial::method_type = Method

Description

The type which defines the transformation method for generation.

multinomial::result_type = IntType

Description

The type which defines the type of generated random numbers.

Constructors

explicit multinomial::multinomial(double ntrial, SequenceContainerOrView<double> p)

Description

Constructor with parameters. ntrial is a number of independent trials, p is a probability parameter.

Throws

oneapi::math::invalid_argument

Exception is thrown when \(ntrial < 0\), or \(p.size() < 1\)

Characteristics

std::int32_t multinomial::ntrial() const

Return Value

Returns the distribution parameter ntrial.

SequenceContainerOrView<double> multinomial::p() const

Return Value

Returns the distribution parameter p.

Parent topic: Host Distributions