![]() |
NeuZephyr
Simple DL Framework
|
Represents a Hard Sigmoid activation function node in a computational graph. More...
Public Member Functions | |
HardSigmoidNode (Node *input, Tensor::value_type alpha=0.2f, Tensor::value_type beta=0.5f) | |
Constructor to initialize a HardSigmoidNode for applying the Hard Sigmoid activation function. | |
void | forward () override |
Forward pass for the HardSigmoidNode to apply the Hard Sigmoid activation function. | |
void | backward () override |
Backward pass for the HardSigmoidNode 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 Hard Sigmoid activation function node in a computational graph.
The HardSigmoidNode
class applies the Hard Sigmoid activation function to the input tensor. The Hard Sigmoid function is a computationally efficient approximation of the sigmoid function and is defined as:
where alpha
and beta
control the slope and offset, respectively.
Key features:
0 <= alpha * x + beta <= 1
): This class is part of the nz::nodes
namespace and is used in models where efficiency is prioritized over precise non-linearity.
alpha
and beta
parameters default to 0.2
and 0.5
, respectively, but can be customized during construction.
|
explicit |
Constructor to initialize a HardSigmoidNode
for applying the Hard Sigmoid activation function.
The constructor initializes a HardSigmoidNode
, which applies the Hard Sigmoid activation function to an input tensor. It establishes a connection to the input node, initializes the output tensor, and sets the alpha
and beta
parameters as well as the node type.
input | A pointer to the input node. Its output tensor will have the Hard Sigmoid activation applied. |
alpha | The slope parameter for the linear part of the Hard Sigmoid function. Defaults to 0.2 . |
beta | The offset parameter for the Hard Sigmoid function. Defaults to 0.5 . |
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.alpha
and beta
parameters control the slope and offset of the Hard Sigmoid activation function, influencing the gradient flow and the range mapping.
|
overridevirtual |
Backward pass for the HardSigmoidNode
to compute gradients.
The backward()
method computes the gradient of the loss with respect to the input tensor by applying the derivative of the Hard Sigmoid activation function. The gradient computation is defined as:
where alpha
and beta
control the slope and offset of the Hard Sigmoid function.
HardSigmoidBackward
) 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 491 of file Nodes.cu.
|
overridevirtual |
Forward pass for the HardSigmoidNode
to apply the Hard Sigmoid activation function.
The forward()
method applies the Hard Sigmoid activation function element-wise to the input tensor. The result is stored in the output
tensor. The Hard Sigmoid function is defined as:
HardSigmoid
) is launched to compute the activation function in parallel on the GPU.output
tensor to ensure efficient GPU utilization.alpha
and beta
parameters, provided during construction, control the slope and offset of the linear part of the activation function.Implements nz::nodes::Node.
Definition at line 485 of file Nodes.cu.