Last active
June 2, 2020 23:03
-
-
Save Mehdi-Amine/29795d4872cc0a0aa6aa10c61f445d07 to your computer and use it in GitHub Desktop.
Sigmoid prime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
#----------- Implementing the math -----------# | |
def sigmoid_prime(z): | |
return sigmoid(z) * (1 - sigmoid(z)) | |
z = torch.tensor([[2.], [-3.]], requires_grad=True) | |
sig_p = sigmoid_prime(z) | |
#----------- Using Pytorch autograd -----------# | |
torch_sig.backward(torch.tensor([[1.], [1.]])) | |
#----------- Comparing outputs -----------# | |
print(f"Pytorch Sigmoid': \n{z.grad} \nOur Sigmoid': \n{sig_p}") | |
''' | |
Out: | |
Pytorch Sigmoid': | |
tensor([[0.1050],[0.0452]]) | |
Our Sigmoid': | |
tensor([[0.1050],[0.0452]]) | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment