Skip to content

Commit 6da6e9d

Browse files
authored
[oneMath][RNG] Add geometric distribution to Device API (#604)
Proposal to add geometric distribution to oneMath RNG Device API. Overview: API similar to existing Bernoulli distribution. Supported data types: 32 and 64 integer types. fix: changed notes style for RNG
1 parent 99b1cad commit 6da6e9d

File tree

3 files changed

+195
-3
lines changed

3 files changed

+195
-3
lines changed

source/elements/oneMath/source/domains/rng/device_api/device-distributions-template-parameter-method.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ Distributions Template Parameter Method
4949
* Left exponential tail
5050
* Right exponential tail
5151

52-
`NOTE:` Methods provided for exposition purposes.
52+
.. note::
53+
Methods provided for exposition purposes.

source/elements/oneMath/source/domains/rng/device_api/device-distributions.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ basic random number generators.
6060
- Description
6161
* - :ref:`onemath_device_rng_uniform_discrete`
6262
- integer
63-
- float
63+
- floating point
6464
- Uniform discrete distribution on the interval [``a,b``)
6565
* - :ref:`onemath_device_rng_bits`
6666
- integer
@@ -78,8 +78,17 @@ basic random number generators.
7878
- integer
7979
- integer
8080
- Bernoulli distribution
81+
* - :ref:`onemath_device_rng_geometric`
82+
- integer
83+
- floating point
84+
- Geometric distribution
85+
86+
.. note::
87+
In case of ``integer`` check desired distribution for supported data types.
8188

82-
`NOTE:` In case of ``integer`` check desired distribution for supported data types.
89+
.. note::
90+
Internal data type ``floating point`` size may vary depending on integer
91+
data type size.
8392

8493
**Parent topic:** :ref:`onemath_device_rng_routines`
8594

@@ -97,6 +106,7 @@ basic random number generators.
97106
device-rng-uniform-bits.rst
98107
device-rng-poisson.rst
99108
device-rng-bernoulli.rst
109+
device-rng-geometric.rst
100110
device-rng-beta.rst
101111
device-rng-gamma.rst
102112

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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

Comments
 (0)