You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change adss a `multinomial` method to the `Tensor` class, allowing
you to draw samples from a multinomial distribution. The multinomial
method accepts a tensor `input` and will produce an output `tensor` that
samples the `input` probabilities.
```
Num::Rand.set_seed(0)
input = [[0.5, 0.5], [0.5, 0.5]].to_tensor
a = Tensor.multinomial(input, 5)
puts a # => [[0, 1, 1, 0, 1], [1, 0, 1, 1, 0]]
input2 = [0.5, 0.5, 0.5, 0.5].to_tensor
b = Tensor.multinomial(input, 6)
puts b # => [3, 2, 1, 1, 0, 2]
```
The logic of this method is based on the equivalent `torch.multinomial`
method: https://pytorch.org/docs/stable/generated/torch.multinomial.html
Signed-off-by: Lucian Buzzo <[email protected]>
0 commit comments