Implementation of Bernoulli distribution


(To Tu Cuong) #1

Hi everybody,

I am exploring Pytorch code. I manage to run the code in debug mode.


   m = Bernoulli(torch.tensor([0.3]))
    s = m.sample()  # 30% chance 1; 70% chance 0
    print('a sample: ', s)

    # calling directly
    print('calling directly torch.bernoulli()', torch.bernoulli(torch.Tensor([0.3])))

I tried to find where torch.bernoulli was implemented but couldn’t find it. Pycharm just indicates this is a built-in function.

Thank you for your time!


#2

You can find Bernoulli and other distributions in torch.distributions.


(To Tu Cuong) #3

torch.distributions.Bernoulli called torch.bernoulli(), which, I think, is implemented using C++.


#4

Sorry, I clearly misunderstood your question,
I thought you are looking for the documentation.

I think the source code can be found here:


(To Tu Cuong) #5

Thanks for your help! (sorry for the late thanks)