torch.distributions.Categorical

afshin67: <p>Hi,</p>
<p>Is there any C++ API with same functionality as <code>torch.distributions.Categorical</code>?<br>
I found <code>torch::::multinomial</code> that has same input parameters (<code>const Tensor &amp;self, int64_t num_samples, bool replacement = false, Generator *generator = nullptr</code>), but it does not have <code>sample</code> or <code>log_prob</code> APIs.</p>
<p>Thanks,<br>
Afshin</p>

Maverobot: <p>Bump this… It would be nice if someone can answer this question.</p>

glaringlee: <p>Hi, we don’t have c++ apis for distributions at this point. But we do plan to add distributions support in cpp in the future.</p>

cruzas: <p>Hi <a class="mention" href="/u/glaringlee">@glaringlee</a>,</p>
<p>Thank you for clarifying this.</p>
<p>Separately from this topic, but somewhat related, the implementation for torch.distributions.Normal appears to be here: <a href="https://github.com/pytorch/pytorch/blob/master/torch/distributions/normal.py" rel="nofollow noopener">normal.py</a>. In the <code>sample()</code> function, on line 63, there is a call to <code>torch.normal()</code>. I have not been able to find the implementation for it. Do you think you could provide a link to the file defining <code>torch.normal()</code>?</p>

glaringlee: <p><a class="mention" href="/u/cruzas">@cruzas</a><br>
That’s a binding function which actually pointing to our c++ implementation, entry point is here:<br>
‘<a href="https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/Distributions.cpp#L286" rel="nofollow noopener">https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/Distributions.cpp#L286</a>’<br>
The cpu implementation is here:<br>
<a href="https://github.com/pytorch/pytorch/blob/5ab36ec98ba28b61ac3be57427d67ad8e1f0bab4/aten/src/ATen/native/cpu/DistributionTemplates.h#L173" rel="nofollow noopener">https://github.com/pytorch/pytorch/blob/5ab36ec98ba28b61ac3be57427d67ad8e1f0bab4/aten/src/ATen/native/cpu/DistributionTemplates.h#L173</a><br>
The gpu implementation is here:<br>
<a href="https://github.com/pytorch/pytorch/blob/34523b70c1369024f805a0480bc39a5f21e64a03/aten/src/ATen/native/cuda/DistributionTemplates.h#L407" rel="nofollow noopener">https://github.com/pytorch/pytorch/blob/34523b70c1369024f805a0480bc39a5f21e64a03/aten/src/ATen/native/cuda/DistributionTemplates.h#L407</a></p>

cruzas: <p>Hi <a class="mention" href="/u/glaringlee">@glaringlee</a>,</p>
<p>Thank you very much, seeing the implementation was very useful for me.<br>
Would you also be able to point me to the implementation of the <code>.log_prob()</code> implementation for the normal distribution?</p>
<p>I assumed it is computed as the logarithm of the probability density function. I would like to clarify if that’s the case.</p>
<p>Thank you for your help.</p>

cruzas: <p>Hi <a class="mention" href="/u/glaringlee">@glaringlee</a>,</p>
<p>Now that I remember, I had actually found the implementation for <code>.log_prob()</code> some time ago <a href="https://github.com/pytorch/pytorch/blob/eae1ed99a35eac4e7b6daf7123136e832c50a158/torch/distributions/normal.py#L70" rel="nofollow noopener">here</a>.</p>
<p>Thank you!</p>

afshin67: <p>Are now any of <code>sample</code> or <code>log_prob</code> APIs implemented?</p>