Documentation for v0.1 version (#199)
* Adding Equations, solving typos * improve _code.rst * the team rst and restuctore index.rst * fixing errors --------- Co-authored-by: Dario Coscia <dariocoscia@dhcp-015.eduroam.sissa.it>
This commit is contained in:
committed by
Nicola Demo
parent
3f9305d475
commit
8b7b61b3bd
@@ -1,6 +1,7 @@
|
||||
import torch
|
||||
from torch.nn.parameter import Parameter
|
||||
|
||||
|
||||
class AdaptiveTanh(torch.nn.Module):
|
||||
'''
|
||||
Implementation of soft exponential activation.
|
||||
@@ -18,7 +19,8 @@ class AdaptiveTanh(torch.nn.Module):
|
||||
>>> x = torch.randn(256)
|
||||
>>> x = a1(x)
|
||||
'''
|
||||
def __init__(self, alpha = None):
|
||||
|
||||
def __init__(self, alpha=None):
|
||||
'''
|
||||
Initialization.
|
||||
INPUT:
|
||||
@@ -31,17 +33,19 @@ class AdaptiveTanh(torch.nn.Module):
|
||||
|
||||
# initialize alpha
|
||||
if alpha == None:
|
||||
self.alpha = Parameter(torch.tensor(1.0)) # create a tensor out of alpha
|
||||
self.alpha = Parameter(
|
||||
torch.tensor(1.0)) # create a tensor out of alpha
|
||||
else:
|
||||
self.alpha = Parameter(torch.tensor(alpha)) # create a tensor out of alpha
|
||||
|
||||
self.alpha.requiresGrad = True # set requiresGrad to true!
|
||||
self.alpha = Parameter(
|
||||
torch.tensor(alpha)) # create a tensor out of alpha
|
||||
|
||||
self.alpha.requiresGrad = True # set requiresGrad to true!
|
||||
|
||||
self.scale = Parameter(torch.tensor(1.0))
|
||||
self.scale.requiresGrad = True # set requiresGrad to true!
|
||||
self.scale.requiresGrad = True # set requiresGrad to true!
|
||||
|
||||
self.translate = Parameter(torch.tensor(0.0))
|
||||
self.translate.requiresGrad = True # set requiresGrad to true!
|
||||
self.translate.requiresGrad = True # set requiresGrad to true!
|
||||
|
||||
def forward(self, x):
|
||||
'''
|
||||
@@ -49,4 +53,6 @@ class AdaptiveTanh(torch.nn.Module):
|
||||
Applies the function to the input elementwise.
|
||||
'''
|
||||
x += self.translate
|
||||
return self.scale * (torch.exp(self.alpha * x) - torch.exp(-self.alpha * x))/(torch.exp(self.alpha * x) + torch.exp(-self.alpha * x))
|
||||
return self.scale * (torch.exp(self.alpha * x) - torch.exp(
|
||||
-self.alpha * x)) / (torch.exp(self.alpha * x) +
|
||||
torch.exp(-self.alpha * x))
|
||||
|
||||
Reference in New Issue
Block a user