braindecode.modules.SafeLog#

class braindecode.modules.SafeLog(epsilon=1e-06)[source]#

Safe logarithm activation function module.

\(\text{SafeLog}(x) = \log\left(\max(x, \epsilon)\right)\)

Parameters:

epsilon (float, optional) – A small value to clamp the input tensor to prevent computing log(0) or log of negative numbers. Default is 1e-6.

Examples

>>> import torch
>>> from braindecode.modules import SafeLog
>>> module = SafeLog(epsilon=1e-6)
>>> inputs = torch.rand(2, 3)
>>> outputs = module(inputs)
>>> outputs.shape
torch.Size([2, 3])

Methods

extra_repr()[source]#

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

Return type:

str

forward(x)[source]#

Forward pass of the SafeLog module.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Output tensor after applying safe logarithm.

Return type:

torch.Tensor