Skip to content

Instantly share code, notes, and snippets.

@Mehdi-Amine
Last active June 2, 2020 23:05
Show Gist options
  • Save Mehdi-Amine/bec9579144e2837efe357bddf6d8dfc9 to your computer and use it in GitHub Desktop.
Save Mehdi-Amine/bec9579144e2837efe357bddf6d8dfc9 to your computer and use it in GitHub Desktop.
Sigmoid function or logistic function
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