|
| 1 | +.. SPDX-FileCopyrightText: 2024 Intel Corporation |
| 2 | +.. |
| 3 | +.. SPDX-License-Identifier: CC-BY-4.0 |
| 4 | +
|
| 5 | +.. _onemkl_device_rng_beta: |
| 6 | + |
| 7 | +beta |
| 8 | +==== |
| 9 | + |
| 10 | + |
| 11 | +Generates beta distributed random numbers. |
| 12 | + |
| 13 | +.. rubric:: Description |
| 14 | + |
| 15 | +The ``beta`` class object is used in the ``generate`` function to provide |
| 16 | +random numbers with beta distribution that has shape parameters :math:`p` and :math:`q`, |
| 17 | +displacement :math:`\alpha` and scale parameter :math:`(b, \beta)`, where :math:`p`, :math:`q`. |
| 18 | +:math:`\alpha`, :math:`\beta` :math:`\in R; p > 0; q > 0; \beta > 0`. |
| 19 | + |
| 20 | +The probability distribution is given by: |
| 21 | + |
| 22 | +.. math:: |
| 23 | +
|
| 24 | + f_{p, q, \alpha, \beta}(x) = \left\{ \begin{array}{rcl} \frac{1}{B(p, q) * \beta^{p + q - 1}}(x - a)^{p - 1}*(\beta + \alpha - x)^{q - 1}, \alpha \leq x < \alpha + \beta \\ 0, x < \alpha, x \ge \alpha + \beta \end{array}\right. |
| 25 | +
|
| 26 | +The cumulative distribution function is as follows: |
| 27 | + |
| 28 | +.. math:: |
| 29 | +
|
| 30 | + F_{a, b}(x) = \left\{ \begin{array}{rcl} 0, x < \alpha \\ \int^x_{\alpha}\frac{1}{B(p, q) * \beta^{p + q - 1}}(y - \alpha)^{p - 1}*(\beta + \alpha - y)^{q - 1}dy, \alpha \leq x < \alpha + \beta, x \in R \\ 1, x \ge \alpha + \beta \end{array}\right. |
| 31 | +
|
| 32 | +
|
| 33 | +Where :math:`B(p, 1)` is the complete beta function. |
| 34 | + |
| 35 | +class beta |
| 36 | +---------- |
| 37 | + |
| 38 | +.. rubric:: Syntax |
| 39 | + |
| 40 | +.. code-block:: cpp |
| 41 | +
|
| 42 | + namespace oneapi::mkl::rng::device { |
| 43 | + template<typename RealType, typename Method> |
| 44 | + class beta { |
| 45 | + public: |
| 46 | + using method_type = Method; |
| 47 | + using result_type = RealType; |
| 48 | +
|
| 49 | + beta(); |
| 50 | + explicit beta(RealType p, RealType q, RealType a, RealType b); |
| 51 | +
|
| 52 | + RealType p() const; |
| 53 | + RealType q() const; |
| 54 | + RealType a() const; |
| 55 | + RealType b() const; |
| 56 | + std::size_t count_rejected_numbers() const; |
| 57 | + }; |
| 58 | + } |
| 59 | +
|
| 60 | +
|
| 61 | +.. container:: section |
| 62 | + |
| 63 | + .. rubric:: Template parameters |
| 64 | + |
| 65 | + .. container:: section |
| 66 | + |
| 67 | + typename RealType |
| 68 | + Type of the produced values. Supported types: |
| 69 | + |
| 70 | + * ``float`` |
| 71 | + * ``double`` |
| 72 | + |
| 73 | + .. container:: section |
| 74 | + |
| 75 | + typename Method |
| 76 | + Generation method. The type is unspecified. |
| 77 | + |
| 78 | + |
| 79 | +.. container:: section |
| 80 | + |
| 81 | + .. rubric:: Class Members |
| 82 | + |
| 83 | + .. list-table:: |
| 84 | + :header-rows: 1 |
| 85 | + |
| 86 | + * - Routine |
| 87 | + - Description |
| 88 | + * - `beta()`_ |
| 89 | + - Default constructor |
| 90 | + * - `explicit beta(RealType p, RealType q, RealType a, RealType b)`_ |
| 91 | + - Constructor with parameters |
| 92 | + * - `RealType p() const`_ |
| 93 | + - Method to obtain shape ``p`` |
| 94 | + * - `RealType q() const`_ |
| 95 | + - Method to obtain shape ``q`` |
| 96 | + * - `RealType a() const`_ |
| 97 | + - Method to obtain displacement :math:`\alpha` |
| 98 | + * - `RealType b() const`_ |
| 99 | + - Method to obtain scale parameter :math:`\beta` |
| 100 | + * - `size_t count_rejected_numbers() const`_ |
| 101 | + - Method to obtain amount of random numbers that were rejected during |
| 102 | + the last ``generate`` function call. If no ``generate`` calls, ``0`` is returned. |
| 103 | + |
| 104 | +.. container:: section |
| 105 | + |
| 106 | + .. rubric:: Member types |
| 107 | + |
| 108 | + .. container:: section |
| 109 | + |
| 110 | + .. code-block:: cpp |
| 111 | +
|
| 112 | + beta::method_type = Method |
| 113 | +
|
| 114 | + .. container:: section |
| 115 | + |
| 116 | + .. rubric:: Description |
| 117 | + |
| 118 | + The type which defines transformation method for generation. |
| 119 | + |
| 120 | + .. container:: section |
| 121 | + |
| 122 | + .. code-block:: cpp |
| 123 | +
|
| 124 | + beta::result_type = RealType |
| 125 | +
|
| 126 | + .. container:: section |
| 127 | + |
| 128 | + .. rubric:: Description |
| 129 | + |
| 130 | + The type which defines type of generated random numbers. |
| 131 | + |
| 132 | +.. container:: section |
| 133 | + |
| 134 | + .. rubric:: Constructors |
| 135 | + |
| 136 | + .. container:: section |
| 137 | + |
| 138 | + .. _`beta()`: |
| 139 | + |
| 140 | + .. code-block:: cpp |
| 141 | +
|
| 142 | + beta::beta() |
| 143 | +
|
| 144 | + .. container:: section |
| 145 | + |
| 146 | + .. rubric:: Description |
| 147 | + |
| 148 | + Default constructor for distribution, parameters set as |
| 149 | + ``p`` = 1.0, ``q`` = 1.0, :math:`\alpha` = 0.0, :math:`\beta` = 1.0. |
| 150 | + |
| 151 | + .. container:: section |
| 152 | + |
| 153 | + .. _`explicit beta(RealType p, RealType q, RealType a, RealType b)`: |
| 154 | + |
| 155 | + .. code-block:: cpp |
| 156 | +
|
| 157 | + explicit beta::beta(RealType p, RealType q, RealType a, RealType b) |
| 158 | +
|
| 159 | + .. container:: section |
| 160 | + |
| 161 | + .. rubric:: Description |
| 162 | + |
| 163 | + Constructor with parameters. ``p`` and ``q`` are shapes, :math:`\alpha` is a displacement, :math:`\beta` is a scale parameter. |
| 164 | + |
| 165 | + .. container:: section |
| 166 | + |
| 167 | + .. rubric:: Throws |
| 168 | + |
| 169 | + oneapi::mkl::invalid_argument |
| 170 | + Exception is thrown when :math:`p \leq 0`, or :math:`q \leq 0`, or :math:`\beta \leq 0` |
| 171 | + |
| 172 | +.. container:: section |
| 173 | + |
| 174 | + .. rubric:: Characteristics |
| 175 | + |
| 176 | + .. container:: section |
| 177 | + |
| 178 | + .. _`RealType p() const`: |
| 179 | + |
| 180 | + .. code-block:: cpp |
| 181 | +
|
| 182 | + RealType beta::p() const |
| 183 | +
|
| 184 | + .. container:: section |
| 185 | + |
| 186 | + .. rubric:: Return Value |
| 187 | + |
| 188 | + Returns the distribution parameter ``p`` - shape. |
| 189 | + |
| 190 | + .. container:: section |
| 191 | + |
| 192 | + .. _`RealType q() const`: |
| 193 | + |
| 194 | + .. code-block:: cpp |
| 195 | +
|
| 196 | + RealType beta::q() const |
| 197 | +
|
| 198 | + .. container:: section |
| 199 | + |
| 200 | + .. rubric:: Return Value |
| 201 | + |
| 202 | + Returns the distribution parameter ``q`` - shape. |
| 203 | + |
| 204 | + .. container:: section |
| 205 | + |
| 206 | + .. _`RealType a() const`: |
| 207 | + |
| 208 | + .. code-block:: cpp |
| 209 | +
|
| 210 | + RealType beta::a() const |
| 211 | +
|
| 212 | + .. container:: section |
| 213 | + |
| 214 | + .. rubric:: Return Value |
| 215 | + |
| 216 | + Returns the distribution parameter :math:`\alpha` - displacement. |
| 217 | + |
| 218 | + .. container:: section |
| 219 | + |
| 220 | + .. _`RealType b() const`: |
| 221 | + |
| 222 | + .. code-block:: cpp |
| 223 | +
|
| 224 | + RealType beta::b() const |
| 225 | +
|
| 226 | + .. container:: section |
| 227 | + |
| 228 | + .. rubric:: Return Value |
| 229 | + |
| 230 | + Returns the distribution parameter :math:`\beta` - scale parameter value. |
| 231 | + |
| 232 | + .. container:: section |
| 233 | + |
| 234 | + .. _`size_t count_rejected_numbers() const`: |
| 235 | + |
| 236 | + .. code-block:: cpp |
| 237 | +
|
| 238 | + std::size_t beta::count_rejected_numbers() const |
| 239 | +
|
| 240 | + .. container:: section |
| 241 | + |
| 242 | + .. rubric:: Return Value |
| 243 | + |
| 244 | + Returns the amount of random numbers that were rejected during |
| 245 | + the last ``generate`` function call. If no ``generate`` calls, ``0`` is returned. |
| 246 | + |
| 247 | +**Parent topic:** :ref:`onemkl_device_rng_distributions` |
0 commit comments