expm1() and sigmoid() in PyTorch

Buy Me a Coffee☕

*Memos:

My post explains log() and log1p().

My post explains log2() and log10().

My post explains
exp() and exp2().

expm1() can get the 0D or more D tensor of the zero or more elements by ex – 1 from the 0D or more D tensor of…


This content originally appeared on DEV Community and was authored by Super Kai (Kazuya Ito)

Buy Me a Coffee

*Memos:

expm1() can get the 0D or more D tensor of the zero or more elements by ex - 1 from the 0D or more D tensor of zero or more elements as shown below:

*Memos:

  • expm1() can be used with torch or a tensor.
  • The 1st argument(input) with torch or using a tensor(Required-Type:tensor of int, float, complex or bool).
  • There is out argument with torch(Optional-Type:tensor): *Memos:
    • out= must be used.
    • My post explains out argument.
  • *A float tensor is returned unless an input tensor is complex tensor.
  • torch.expm1() is the alias of torch.special.expm1().
  • The formula is y = ex - 1.
  • The graph in Desmos: Image description
import torch

my_tensor = torch.tensor([-2., -1., 0., 1., 2., 3.])

torch.expm1(input=my_tensor)
my_tensor.expm1()
# tensor([-0.8647, -0.6321, 0.0000, 1.7183, 6.3891, 19.0855])

my_tensor = torch.tensor([[-2., -1., 0.],
                          [1., 2., 3.]])
torch.expm1(input=my_tensor)
# tensor([[-0.8647, -0.6321, 0.0000],
#         [1.7183, 6.3891, 19.0855]])

my_tensor = torch.tensor([[-2, -1, 0],
                          [1, 2, 3]])
torch.expm1(input=my_tensor)
# tensor([[-0.8647, -0.6321, 0.0000],
#         [1.7183, 6.3891, 19.0855]])

my_tensor = torch.tensor([[-2.+0.j, -1.+0.j, 0.+0.j],
                          [1.+0.j, 2.+0.j, 3.+0.j]])
torch.expm1(input=my_tensor)
# tensor([[-0.8647+0.j, -0.6321+0.j, 0.0000+0.j],
#         [1.7183+0.j, 6.3891+0.j, 19.0855+0.j]])

my_tensor = torch.tensor([[True, False, True],
                          [False, True, False]])
torch.expm1(input=my_tensor)
# tensor([[1.7183, 0.0000, 1.7183],
#         [0.0000, 1.7183, 0.0000]])

sigmoid() can get the 0D or more D tensor of the zero or more elements by Sigmoid function from the 0D or more D tensor of zero or more elements as shown below:

*Memos:

  • sigmoid() can be used with torch or a tensor.
  • The 1st argument(input) with torch or using a tensor(Required-Type:tensor of int, float, complex or bool).
  • There is out argument with torch(Optional-Type:tensor): *Memos:
    • out= must be used.
    • My post explains out argument.
  • *A float tensor is returned unless an input tensor is complex tensor.
  • torch.sigmoid() is the alias of torch.special.expit().
  • You can also use torch.nn.Sigmoid().
  • The formula is y = 1 / (1 + e-x).
  • The graph in Desmos: Image description
import torch

my_tensor = torch.tensor([-2., -1., 0., 1., 2., 3.])

torch.sigmoid(input=my_tensor)
my_tensor.sigmoid()
# tensor([0.1192, 0.2689, 0.5000, 0.7311, 0.8808, 0.9526])

my_tensor = torch.tensor([[-2., -1., 0.],
                          [1., 2., 3.]])
torch.sigmoid(input=my_tensor)
# tensor([[0.1192, 0.2689, 0.5000],
#         [0.7311, 0.8808, 0.9526]])

my_tensor = torch.tensor([[-2, -1, 0],
                          [1, 2, 3]])
torch.sigmoid(input=my_tensor)
# tensor([[0.1192, 0.2689, 0.5000],
#         [0.7311, 0.8808, 0.9526]])

my_tensor = torch.tensor([[-2.+0.j, -1.+0.j, 0.+0.j],
                          [1.+0.j, 2.+0.j, 3.+0.j]])
torch.sigmoid(input=my_tensor)
# tensor([[0.1192+0.j, 0.2689+0.j, 0.5000+0.j],
#         [0.7311+0.j, 0.8808+0.j, 0.9526+0.j]])

my_tensor = torch.tensor([[True, False, True],
                          [False, True, False]])
torch.sigmoid(input=my_tensor)
# tensor([[0.7311, 0.5000, 0.7311],
#         [0.5000, 0.7311, 0.5000]])


This content originally appeared on DEV Community and was authored by Super Kai (Kazuya Ito)


Print Share Comment Cite Upload Translate Updates
APA

Super Kai (Kazuya Ito) | Sciencx (2024-09-03T15:57:40+00:00) expm1() and sigmoid() in PyTorch. Retrieved from https://www.scien.cx/2024/09/03/expm1-and-sigmoid-in-pytorch/

MLA
" » expm1() and sigmoid() in PyTorch." Super Kai (Kazuya Ito) | Sciencx - Tuesday September 3, 2024, https://www.scien.cx/2024/09/03/expm1-and-sigmoid-in-pytorch/
HARVARD
Super Kai (Kazuya Ito) | Sciencx Tuesday September 3, 2024 » expm1() and sigmoid() in PyTorch., viewed ,<https://www.scien.cx/2024/09/03/expm1-and-sigmoid-in-pytorch/>
VANCOUVER
Super Kai (Kazuya Ito) | Sciencx - » expm1() and sigmoid() in PyTorch. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/03/expm1-and-sigmoid-in-pytorch/
CHICAGO
" » expm1() and sigmoid() in PyTorch." Super Kai (Kazuya Ito) | Sciencx - Accessed . https://www.scien.cx/2024/09/03/expm1-and-sigmoid-in-pytorch/
IEEE
" » expm1() and sigmoid() in PyTorch." Super Kai (Kazuya Ito) | Sciencx [Online]. Available: https://www.scien.cx/2024/09/03/expm1-and-sigmoid-in-pytorch/. [Accessed: ]
rf:citation
» expm1() and sigmoid() in PyTorch | Super Kai (Kazuya Ito) | Sciencx | https://www.scien.cx/2024/09/03/expm1-and-sigmoid-in-pytorch/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.