![]() |
NeuZephyr
Simple DL Framework
|
Represents a Swish activation function node in a computational graph. More...
Public Member Functions | |
SwishNode (Node *input) | |
Constructor to initialize a SwishNode for applying the Swish activation function. | |
void | forward () override |
Forward pass for the SwishNode to apply the Swish activation function. | |
void | backward () override |
Backward pass for the SwishNode to compute gradients. | |
![]() | |
virtual void | print (std::ostream &os) const |
Prints the type, data, and gradient of the node. | |
void | dataInject (Tensor::value_type *data, bool grad=false) const |
Injects data into a relevant tensor object, optionally setting its gradient requirement. | |
template<typename Iterator > | |
void | dataInject (Iterator begin, Iterator end, const bool grad=false) const |
Injects data from an iterator range into the output tensor of the InputNode, optionally setting its gradient requirement. | |
void | dataInject (const std::initializer_list< Tensor::value_type > &data, bool grad=false) const |
Injects data from a std::initializer_list into the output tensor of the Node, optionally setting its gradient requirement. | |
Represents a Swish activation function node in a computational graph.
The SwishNode
class applies the Swish activation function to the input tensor. The Swish function is defined as:
It is a smooth, non-monotonic activation function that often outperforms ReLU in deep learning tasks.
Key features:
This class is part of the nz::nodes
namespace and is commonly used in advanced deep learning models to enhance performance over traditional activation functions.
|
explicit |
Constructor to initialize a SwishNode
for applying the Swish activation function.
The constructor initializes a SwishNode
, which applies the Swish activation function to an input tensor. It establishes a connection to the input node, initializes the output tensor, and sets the type of the node to "Swish".
input | A pointer to the input node. Its output tensor will have the Swish activation applied. |
inputs
vector to establish the connection in the computational graph.output
tensor is initialized with the same shape as the input tensor, and its gradient tracking is determined based on the input tensor's requirements.
|
overridevirtual |
Backward pass for the SwishNode
to compute gradients.
The backward()
method computes the gradient of the loss with respect to the input tensor by applying the derivative of the Swish activation function. The gradient computation is based on the formula:
where Sigmoid(x) = 1 / (1 + exp(-x))
.
SwishBackward
) is launched to compute the gradients in parallel on the GPU.output
tensor to compute the input gradient.requiresGrad
property is true.Implements nz::nodes::Node.
Definition at line 444 of file Nodes.cu.
|
overridevirtual |
Forward pass for the SwishNode
to apply the Swish activation function.
The forward()
method applies the Swish activation function element-wise to the input tensor. The result is stored in the output
tensor. The Swish function is defined as:
Swish
) is launched to compute the activation function in parallel on the GPU.output
tensor to optimize GPU performance.output
tensor for use in subsequent layers or operations.Implements nz::nodes::Node.
Definition at line 438 of file Nodes.cu.