|
| 1 | +.. SPDX-FileCopyrightText: 2024 Intel Corporation |
| 2 | +.. |
| 3 | +.. SPDX-License-Identifier: CC-BY-4.0 |
| 4 | +
|
| 5 | +.. _onemath_device_rng_geometric: |
| 6 | + |
| 7 | +geometric |
| 8 | +========= |
| 9 | + |
| 10 | +Generates geometrically distributed random values. |
| 11 | + |
| 12 | +.. rubric:: Description |
| 13 | + |
| 14 | +The ``geometric`` class object is used in the ``generate`` and function |
| 15 | +to provide geometrically distributed random numbers with probability ``p`` of a single trial success, |
| 16 | +where :math:`p \in R; 0 \leq p \leq 1`. |
| 17 | + |
| 18 | +The probability distribution is given by: |
| 19 | + |
| 20 | +.. math:: |
| 21 | +
|
| 22 | + P(X = k) = p * (1 - p)^k, k = \{0, 1, 2, ... \}. |
| 23 | +
|
| 24 | +The cumulative distribution function is as follows: |
| 25 | + |
| 26 | +.. math:: |
| 27 | +
|
| 28 | + F_p(x) = |
| 29 | + \begin{cases} |
| 30 | + 0, x < 0 \\ |
| 31 | + 1 - (1 - p)^{\lfloor x + 1 \rfloor}, x \ge 0 |
| 32 | + \end{cases} |
| 33 | +
|
| 34 | +
|
| 35 | +class geometric |
| 36 | +--------------- |
| 37 | + |
| 38 | +.. rubric:: Syntax |
| 39 | + |
| 40 | +.. code-block:: cpp |
| 41 | +
|
| 42 | + namespace oneapi::math::rng::device { |
| 43 | + template<typename IntType, typename Method> |
| 44 | + class geometric { |
| 45 | + public: |
| 46 | + using method_type = Method; |
| 47 | + using result_type = IntType; |
| 48 | +
|
| 49 | + geometric(); |
| 50 | + explicit geometric(float p); |
| 51 | + |
| 52 | + float p() const; |
| 53 | + }; |
| 54 | + } |
| 55 | +
|
| 56 | +
|
| 57 | +.. container:: section |
| 58 | + |
| 59 | + .. rubric:: Template parameters |
| 60 | + |
| 61 | + .. container:: section |
| 62 | + |
| 63 | + typename IntType |
| 64 | + Type of the produced values. Supported types: |
| 65 | + * ``std::int32_t`` |
| 66 | + * ``std::uint32_t`` |
| 67 | + * ``std::int64_t`` |
| 68 | + * ``std::uint64_t`` |
| 69 | + |
| 70 | + .. container:: section |
| 71 | + |
| 72 | + typename Method = oneapi::math::rng::geometric_method::by_default |
| 73 | + Transformation method, which will be used for generation. Supported types: |
| 74 | + |
| 75 | + * ``oneapi::math::rng::geometric_method::by_default`` |
| 76 | + * ``oneapi::math::rng::geometric_method::icdf`` |
| 77 | + |
| 78 | + See description of the methods in :ref:`Distributions methods template parameter<onemath_rng_distributions_template_parameter_onemath_rng_method_values>`. |
| 79 | + |
| 80 | +.. container:: section |
| 81 | + |
| 82 | + .. rubric:: Class Members |
| 83 | + |
| 84 | + .. list-table:: |
| 85 | + :header-rows: 1 |
| 86 | + |
| 87 | + * - Routine |
| 88 | + - Description |
| 89 | + * - `geometric()`_ |
| 90 | + - Default constructor |
| 91 | + * - `explicit geometric(float p)`_ |
| 92 | + - Constructor with parameters |
| 93 | + * - `float p() const`_ |
| 94 | + - Method to obtain probability `p` |
| 95 | + |
| 96 | +.. container:: section |
| 97 | + |
| 98 | + .. rubric:: Member types |
| 99 | + |
| 100 | + .. container:: section |
| 101 | + |
| 102 | + .. code-block:: cpp |
| 103 | +
|
| 104 | + geometric::method_type = Method |
| 105 | +
|
| 106 | + .. container:: section |
| 107 | + |
| 108 | + .. rubric:: Description |
| 109 | + |
| 110 | + The type which defines transformation method for generation. |
| 111 | + |
| 112 | + .. container:: section |
| 113 | + |
| 114 | + .. code-block:: cpp |
| 115 | +
|
| 116 | + geometric::result_type = IntType |
| 117 | +
|
| 118 | + .. container:: section |
| 119 | + |
| 120 | + .. rubric:: Description |
| 121 | + |
| 122 | + The type which defines type of generated random numbers. |
| 123 | + |
| 124 | +.. container:: section |
| 125 | + |
| 126 | + .. rubric:: Constructors |
| 127 | + |
| 128 | + .. container:: section |
| 129 | + |
| 130 | + .. _`geometric()`: |
| 131 | + |
| 132 | + .. code-block:: cpp |
| 133 | +
|
| 134 | + geometric::geometric() |
| 135 | +
|
| 136 | + .. container:: section |
| 137 | + |
| 138 | + .. rubric:: Description |
| 139 | + |
| 140 | + Default constructor for distribution, parameters set as `p` = 0.5f. |
| 141 | + |
| 142 | + .. container:: section |
| 143 | + |
| 144 | + .. _`explicit geometric(float p)`: |
| 145 | + |
| 146 | + .. code-block:: cpp |
| 147 | +
|
| 148 | + explicit geometric::geometric(float p) |
| 149 | +
|
| 150 | + .. container:: section |
| 151 | + |
| 152 | + .. rubric:: Description |
| 153 | + |
| 154 | + Constructor with parameters. `p` is a probability value. |
| 155 | + |
| 156 | + .. container:: section |
| 157 | + |
| 158 | + .. rubric:: Throws |
| 159 | + |
| 160 | + oneapi::math::invalid_argument |
| 161 | + Exception is thrown when :math:`p \ge 1.0f`, or :math:`p \leq 0.0f` |
| 162 | + |
| 163 | +.. container:: section |
| 164 | + |
| 165 | + .. rubric:: Characteristics |
| 166 | + |
| 167 | + .. container:: section |
| 168 | + |
| 169 | + .. _`float p() const`: |
| 170 | + |
| 171 | + .. code-block:: cpp |
| 172 | +
|
| 173 | + float geometric::p() const |
| 174 | +
|
| 175 | + .. container:: section |
| 176 | + |
| 177 | + .. rubric:: Return Value |
| 178 | + |
| 179 | + Returns the distribution parameter `p` - probability value. |
| 180 | + |
| 181 | +**Parent topic:** :ref:`onemath_device_rng_distributions` |
0 commit comments