🎨 Format Python code with psf/black

This commit is contained in:
ndem0
2024-02-09 11:25:00 +00:00
committed by Nicola Demo
parent 591aeeb02b
commit cbb43a5392
64 changed files with 1323 additions and 955 deletions

View File

@@ -3,7 +3,7 @@ from torch.nn.parameter import Parameter
class AdaptiveTanh(torch.nn.Module):
'''
"""
Implementation of soft exponential activation.
Shape:
- Input: (N, *) where * means, any number of additional
@@ -18,26 +18,28 @@ class AdaptiveTanh(torch.nn.Module):
>>> a1 = soft_exponential(256)
>>> x = torch.randn(256)
>>> x = a1(x)
'''
"""
def __init__(self, alpha=None):
'''
"""
Initialization.
INPUT:
- in_features: shape of the input
- aplha: trainable parameter
aplha is initialized with zero value by default
'''
"""
super(AdaptiveTanh, self).__init__()
#self.in_features = in_features
# self.in_features = in_features
# initialize alpha
if alpha == None:
self.alpha = Parameter(
torch.tensor(1.0)) # create a tensor out of alpha
torch.tensor(1.0)
) # create a tensor out of alpha
else:
self.alpha = Parameter(
torch.tensor(alpha)) # create a tensor out of alpha
torch.tensor(alpha)
) # create a tensor out of alpha
self.alpha.requiresGrad = True # set requiresGrad to true!
@@ -48,11 +50,13 @@ class AdaptiveTanh(torch.nn.Module):
self.translate.requiresGrad = True # set requiresGrad to true!
def forward(self, x):
'''
"""
Forward pass of the function.
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))
)