[SPEC] Apply changes from release branch (#20986)
This commit is contained in:
parent
89494ab412
commit
bb3ed2d42e
@ -30,7 +30,7 @@ Given a list of probabilities x1, x2, ..., xn:
|
||||
|
||||
* For each probability x, replace it with a value :math:`e^{x}`.
|
||||
|
||||
* Create an array - discrete CDF (`Cumulative Distribution Function <https://en.wikipedia.org/wiki/Cumulative_distribution_function>`__) - the cumulative sum of those probabilities, ie. create an array of values where the ith value is the sum of the probabilities x1, ..., xi.
|
||||
* Create an array - discrete CDF (`Cumulative Distribution Function <https://hal.science/hal-00753950/file/PEER_stage2_10.1016%252Fj.spl.2011.03.014.pdf>`__) - the cumulative sum of those probabilities, ie. create an array of values where the ith value is the sum of the probabilities x1, ..., xi.
|
||||
* Divide the created array by its maximum value to normalize the cumulative probabilities between the real values in the range [0, 1]. This array is, by definition of CDF, sorted in ascending order, hence the maximum value is the last value of the array.
|
||||
* Randomly generate a sequence of double-precision floating point numbers in the range [0, 1].
|
||||
* For each generated number, assign the class with the lowest index for which the cumulative probability is less or equal to the generated value.
|
||||
@ -44,12 +44,12 @@ Given a list of probabilities x1, x2, ..., xn:
|
||||
|
||||
**Example computations**:
|
||||
|
||||
Example 1 - 1D tensor
|
||||
Example 1 - simple 2D tensor with one batch
|
||||
|
||||
* Let ``probs`` = ``[0.1, 0.5, 0.4]``, ``num_samples`` = 5, ``log_probs`` = false, ``with_replacement`` = true
|
||||
* CDF of ``probs`` = ``[0.1, 0.1 + 0.5, 0.1 + 0.5 + 0.4]`` = ``[0.1, 0.6, 1]``
|
||||
* Randomly generated floats = ``[0.2, 0.4, 0.6, 0.8, 1]``
|
||||
* Assigned classes = ``[1, 1, 1, 2, 2]``
|
||||
* Let ``probs`` = ``[[0.1, 0.5, 0.4]]``, ``num_samples`` = 5, ``log_probs`` = false, ``with_replacement`` = true
|
||||
* CDF of ``probs`` = ``[[0.1, 0.1 + 0.5, 0.1 + 0.5 + 0.4]]`` = ``[[0.1, 0.6, 1]]``
|
||||
* Randomly generated floats = ``[[0.2, 0.4, 0.6, 0.8, 1]]``
|
||||
* Assigned classes = ``[[1, 1, 1, 2, 2]]``
|
||||
|
||||
Example 2 - 2D tensor, log probabilities
|
||||
|
||||
@ -60,20 +60,20 @@ Example 2 - 2D tensor, log probabilities
|
||||
* Randomly generated floats = ``[[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1], [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]]``
|
||||
* Assigned classes = ``[[1, 1, 2, 2, 2, 2, 2, 2, 2, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]``
|
||||
|
||||
Example 3 - 1D tensor, without replacement
|
||||
Example 3 - 2D tensor, without replacement
|
||||
|
||||
* Let ``probs`` = ``[0.1, 0.5, 0.4]``, ``num_samples`` = 2, ``log_probs`` = false, ``with_replacement`` = false
|
||||
* CDF of ``probs`` = ``[0.1, 0.6, 1]``
|
||||
* Randomly generated floats = ``[0.3, 0.2]``
|
||||
* Let ``probs`` = ``[[0.1, 0.5, 0.4]]``, ``num_samples`` = 2, ``log_probs`` = false, ``with_replacement`` = false
|
||||
* CDF of ``probs`` = ``[[0.1, 0.6, 1]]``
|
||||
* Randomly generated floats = ``[[0.3, 0.2]]``
|
||||
* In a loop:
|
||||
|
||||
* For a value of 0.3, a class with idx ``1`` is selected
|
||||
* Therefore, in CDF, for every class starting with idx ``1`` subtract the probability of class at idx ``1`` = ``probs[1]`` = 0.5
|
||||
* CDF = ``[0.1, 0.6 - 0.5, 1.0 - 0.5]`` = ``[0.1, 0.1, 0.5]``
|
||||
* Normalize CDF by dividing by last value: CDF = ``[0.2, 0.2, 1.0]``
|
||||
* CDF = ``[[0.1, 0.6 - 0.5, 1.0 - 0.5]]`` = ``[[0.1, 0.1, 0.5]]``
|
||||
* Normalize CDF by dividing by last value: CDF = ``[[0.2, 0.2, 1.0]]``
|
||||
* Take the next randomly generated float, here 0.2, and repeat until all random samples have assigned classes. Notice that for ``sampled values`` <= 0.2, only the class with idx ``0`` can be selected, since the search stops at the index with the first value satisfying ``sample value`` <= ``CDF probability``
|
||||
|
||||
* Assigned classes = ``[1, 2]``
|
||||
* Assigned classes = ``[[1, 2]]``
|
||||
|
||||
|
||||
**Attributes**:
|
||||
@ -125,13 +125,13 @@ Example 3 - 1D tensor, without replacement
|
||||
|
||||
**Inputs**:
|
||||
|
||||
* **1**: ``probs`` - A 1D or 2D tensor of type `T_IN` and shape `[class_size]` or `[batch_size, class_size]` with probabilities. Allowed values depend on the *log_probs* attribute. The values are internally normalized to have values in the range of `[0, 1]` with the sum of all probabilities in the given batch equal to 1. **Required.**
|
||||
* **1**: ``probs`` - A 2D tensor of type `T_IN` and shape `[batch_size, class_size]` with probabilities. Allowed values depend on the *log_probs* attribute. The values are internally normalized to have values in the range of `[0, 1]` with the sum of all probabilities in the given batch equal to 1. **Required.**
|
||||
|
||||
* **2**: ``num_samples`` - A scalar or 1D tensor with a single element of type `T_SAMPLES` specifying the number of samples to draw from the multinomial distribution. **Required.**
|
||||
|
||||
**Outputs**:
|
||||
|
||||
* **1**: ``output``- A tensor with type specified by the attribute *convert_type* and shape depending on the rank of *probs*, either ``[num_samples]`` for one-dimensional *probs* or ``[batch_size, num_samples]`` for the two-dimensional one.
|
||||
* **1**: ``output``- A tensor with type specified by the attribute *convert_type* and shape ``[batch_size, num_samples]``.
|
||||
|
||||
**Types**
|
||||
|
||||
@ -139,7 +139,7 @@ Example 3 - 1D tensor, without replacement
|
||||
* **T_SAMPLES**: 32-bit or 64-bit integers.
|
||||
|
||||
|
||||
*Example 1: 1D input tensor.*
|
||||
*Example 1: 2D input tensor with one batch.*
|
||||
|
||||
.. code-block:: xml
|
||||
:force:
|
||||
@ -147,19 +147,21 @@ Example 3 - 1D tensor, without replacement
|
||||
<layer ... name="Multinomial" type="Multinomial">
|
||||
<data convert_type="f32", with_replacement="true", log_probs="false", global_seed="234", op_seed="148"/>
|
||||
<input>
|
||||
<port id="0" precision="FP32"> < !-- probs value: [0.1, 0.5, 0.4] -->
|
||||
<port id="0" precision="FP32"> < !-- probs value: [[0.1, 0.5, 0.4]] -->
|
||||
<dim>1</dim> < !-- batch size of 2 -->
|
||||
<dim>3</dim>
|
||||
</port>
|
||||
<port id="1" precision="I32"/> < !-- num_samples value: 5 -->
|
||||
</input>
|
||||
<output>
|
||||
<port id="3" precision="FP32" names="Multinomial:0">
|
||||
<dim>5</dim>
|
||||
<port id="3" precision="I32" names="Multinomial:0">
|
||||
<dim>1</dim> < !--dimension depends on input batch size -->
|
||||
<dim>5</dim> < !--dimension depends on num_samples -->
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
|
||||
*Example 2: 2D input tensor.*
|
||||
*Example 2: 2D input tensor with multiple batches.*
|
||||
|
||||
.. code-block:: xml
|
||||
:force:
|
||||
@ -174,14 +176,14 @@ Example 3 - 1D tensor, without replacement
|
||||
<port id="1" precision="I32"/> < !-- num_samples value: 10 -->
|
||||
</input>
|
||||
<output>
|
||||
<port id="3" precision="FP32" names="Multinomial:0">
|
||||
<port id="3" precision="I32" names="Multinomial:0">
|
||||
<dim>2</dim> < !--dimension depends on input batch size -->
|
||||
<dim>10</dim> < !--dimension depends on num_samples -->
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
|
||||
*Example 3: 1D input tensor without replacement.*
|
||||
*Example 3: 2D input tensor without replacement.*
|
||||
|
||||
.. code-block:: xml
|
||||
:force:
|
||||
@ -189,16 +191,18 @@ Example 3 - 1D tensor, without replacement
|
||||
<layer ... name="Multinomial" type="Multinomial">
|
||||
<data convert_type="f32", with_replacement="false", log_probs="false", global_seed="234", op_seed="148"/>
|
||||
<input>
|
||||
<port id="0" precision="FP32"> < !-- probs value: [0.1, 0.5, 0.4] -->
|
||||
<port id="0" precision="FP32"> < !-- probs value: [[0.1, 0.5, 0.4]] -->
|
||||
<dim>2</dim> < !-- batch size of 2 -->
|
||||
<dim>3</dim>
|
||||
</port>
|
||||
<port id="1" precision="I32"/> < !-- num_samples value: 2 -->
|
||||
</input>
|
||||
<output>
|
||||
<port id="3" precision="FP32" names="Multinomial:0">
|
||||
<port id="3" precision="I32" names="Multinomial:0">
|
||||
<dim>2</dim> < !-- batch size of 2 -->
|
||||
<dim>2</dim> < !-- 2 unique samples of classes -->
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
|
||||
@endsphinxdirective
|
||||
@endsphinxdirective
|
Loading…
Reference in New Issue
Block a user