Tanh関数に似た形で、(学習不可能な)パラメータで勾配の大きさを調整できる活性化関数です。
正と負の入力に別々の指数関数を使い、パラメータの比 a/b・c/d で勾配が 0 に近づく速さを調整することで、勾配消失問題を最小化します。
出力は、
です。
活性化関数
更新日:
# PyTorch
import torch
import torch.nn as nn
class NN(nn.Module):
def __init__(self, a=1.0, b=1.0, c=1.0, d=1.0):
super().__init__()
self.a = a
self.b = b
self.c = c
self.d = d
def hexpo(self, x):
pos = -self.a * (torch.exp(-x / self.b) - 1)
neg = self.c * (torch.exp(x / self.d) - 1)
return torch.where(x >= 0, pos, neg)
def forward(self, x):
x = self.hexpo(x)
return x