Module Activation#
activation
#
| CLASS | DESCRIPTION |
|---|---|
TemperedSigmoid |
Tempered sigmoid activation function with learnable temperature parameter. |
TemperedSine |
Tempered sine activation function with learnable temperature parameter. |
ShiftedSoftplus |
Shifted Softplus activation function. |
SmoothedShiftedSoftplus |
Smoothed shifted softplus (SSP) activation function. |
Classes#
TemperedSigmoid(beta: float = 1.0, dtype: torch.dtype = torch.float32)
#
Bases: Module
Tempered sigmoid activation function with learnable temperature parameter.
Applies sigmoid with a learnable temperature scaling: \(\mathrm{sigmoid}(\beta X)\).
| PARAMETER | DESCRIPTION |
|---|---|
beta
|
Temperature parameter for scaling input.
TYPE:
|
dtype
|
Data type for the temperature parameter.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
forward |
Apply tempered sigmoid activation. |
Source code in spectre/module/activation.py
TemperedSine(beta: float = 1.0, dtype: torch.dtype = torch.float32)
#
Bases: Module
Tempered sine activation function with learnable temperature parameter.
Applies sine with a learnable temperature scaling: \(\sin(\beta X)\).
| PARAMETER | DESCRIPTION |
|---|---|
beta
|
Temperature parameter for scaling input.
TYPE:
|
dtype
|
Data type for the temperature parameter.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
forward |
Apply tempered sine activation. |
Source code in spectre/module/activation.py
ShiftedSoftplus(beta: float = 1.0, threshold: float = 20.0)
#
Bases: Softplus
Shifted Softplus activation function.
Applies Softplus activation shifted to ensure f(0) = 0. This improves training stability by centering the activation around zero.
| PARAMETER | DESCRIPTION |
|---|---|
beta
|
Softplus beta parameter.
TYPE:
|
threshold
|
Threshold for switching to linear approximation.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
forward |
Apply shifted softplus activation. |
Source code in spectre/module/activation.py
SmoothedShiftedSoftplus(alpha: float = 0.5, beta: float = 0.5, dtype: torch.dtype = torch.float32, device: torch.device | str | None = None)
#
Bases: Module
Smoothed shifted softplus (SSP) activation function.
Custom activation function implementing: \(\log(\alpha \exp(X) + \beta)\). Provides smooth transitions and improved gradient flow.
Note: This is different from ShiftedSoftplus - SSP uses a custom formula
while ShiftedSoftplus shifts the standard softplus to ensure f(0) = 0.
| PARAMETER | DESCRIPTION |
|---|---|
alpha
|
Exponential scaling parameter. Must be positive.
TYPE:
|
beta
|
Additive constant parameter. Must be positive.
TYPE:
|
dtype
|
Data type of the input tensor.
TYPE:
|
device
|
Device to run computations on. If None, automatically selects CUDA if available, otherwise CPU.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
forward |
Apply SSP activation function. |
Source code in spectre/module/activation.py
Functions#
forward(X: torch.Tensor) -> torch.Tensor
#
Apply SSP activation function.