Deep Learning Algorithm Implementations 1.0.0
C++ implementations of fundamental deep learning algorithms
Loading...
Searching...
No Matches
dl::activation::Tanh Class Reference

Hyperbolic tangent (Tanh) activation function. More...

#include <functions.hpp>

Inheritance diagram for dl::activation::Tanh:
Collaboration diagram for dl::activation::Tanh:

Public Member Functions

double forward (double x)
 Compute tanh forward pass.
 
double backward (double x)
 Compute tanh derivative.
 
- Public Member Functions inherited from dl::activation::ActivationFunction
virtual ~ActivationFunction ()=default
 Virtual destructor for proper cleanup.
 

Detailed Description

Hyperbolic tangent (Tanh) activation function.

Tanh maps input values to the range (-1, 1), making it zero-centered which can help with gradient flow during training.

Mathematical definition:

  • Forward: f(x) = tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
  • Derivative: f'(x) = 1 - tanh²(x)
Note
Zero-centered output can improve convergence

Definition at line 110 of file functions.hpp.

Member Function Documentation

◆ backward()

double dl::activation::Tanh::backward ( double  x)

Compute tanh derivative.

Parameters
xInput value
Returns
1 - tanh²(x)

Definition at line 40 of file functions.cpp.

◆ forward()

double dl::activation::Tanh::forward ( double  x)

Compute tanh forward pass.

Parameters
xInput value
Returns
tanh(x)

Definition at line 34 of file functions.cpp.


The documentation for this class was generated from the following files: