Table of Contents

Class Tanh4D

Namespace
NeuralNetworks.Operations.ActivationFunctions
Assembly
NeuralNetworks.dll

Hyperbolic Tangent (Tanh) activation function for 4D tensors.

public class Tanh4D : ActivationFunction<float[,,,], float[,,,]>
Inheritance
Operation<float[,,,], float[,,,]>
Tanh4D
Inherited Members

Remarks

Formula: f(x) = tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x)) = (e^(2x) - 1) / (e^(2x) + 1)

Input Gradient Formula: ∂L/∂x = ∂L/∂y · (1 - f(x)²) = ∂L/∂y · (1 - tanh²(x))

Output Range: (-1, 1)

Description: The hyperbolic tangent function is a smooth, S-shaped curve that maps input values to the range (-1, 1). This variant operates on 4D tensors, commonly used in convolutional neural networks (CNNs) where the tensor dimensions typically represent [batch, channels, height, width].

Remarks: Functionally identical to Tanh2D but designed for 4D tensor operations typical in CNNs. Maintains the same mathematical properties including zero-centered outputs and susceptibility to vanishing gradients. The 4D implementation allows for efficient batch processing of multi-channel image data.

Methods

CalcInputGradient(float[,,,])

Calculates input gradient.

protected override float[,,,] CalcInputGradient(float[,,,] outputGradient)

Parameters

outputGradient float[,,,]

Returns

float[,,,]

Remarks

Based on outputGradient, calculates changes in input.

CalcOutput(bool)

Computes output.

protected override float[,,,] CalcOutput(bool inference)

Parameters

inference bool

Returns

float[,,,]

ToString()

Returns a string that represents the current operation.

public override string ToString()

Returns

string

A string that represents the current operation.

Remarks

It is used in a layer/model description.