Last active
June 2, 2020 23:05
-
-
Save Mehdi-Amine/bec9579144e2837efe357bddf6d8dfc9 to your computer and use it in GitHub Desktop.
Sigmoid function or logistic function
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(z): | |
return 1 / (1+torch.exp(-z)) | |
z = torch.tensor([[2.], [-3.]]) # Two neurons with different values | |
sig = sigmoid(z) | |
#----------- Using Pytorch -----------# | |
torch_sig = torch.sigmoid(z) | |
#----------- Comparing outputs -----------# | |
print(f"Pytorch Sigmoid: \n{torch_sig} \nOur Sigmoid: \n{sig}") | |
''' | |
Out: | |
Pytorch Sigmoid: | |
tensor([[0.8808],[0.0474]]) | |
Our Sigmoid: | |
tensor([[0.8808],[0.0474]]) | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment