SquashActivation<T>
Models & Types · AiDotNet.ActivationFunctions
Implements the Squash activation function, which normalizes vectors to have a magnitude between 0 and 1.
Inheritance: ActivationFunctionBase<T> → SquashActivation<T>
For Beginners
The Squash function is different from most activation functions because it works on entire vectors (groups of numbers) rather than individual numbers. Think of a vector as an arrow pointing in some direction with a certain length.
What Squash does:
- It keeps the arrow pointing in the same direction
- It adjusts the length of the arrow to be between 0 and 1
- Short vectors remain almost the same length
- Long vectors get “squashed” to be closer to length 1
This is useful in advanced neural networks like capsule networks, where the direction of a vector represents important features, and the length represents the probability that those features exist.
How It Works
The Squash activation function maps input vectors to have a magnitude (length) between 0 and 1 while preserving their direction. This is particularly useful in capsule networks and other neural network architectures where vector orientation is important.
Example
using AiDotNet.ActivationFunctions;
var activation = new SquashActivation<double>();
double y = activation.Activate(0.5);
Console.WriteLine($"SquashActivation: f(0.5) = {y:F4}");
Constructors
| Constructor | Summary |
|---|---|
SquashActivation() |
Methods
| Method | Summary |
|---|---|
Matrix<T> Derivative(Vector<T> input) |
Calculates the Jacobian matrices for a batch of vectors stored in a tensor. |
T Activate(T input) |
Applies the Squash activation function to a batch of vectors stored in a tensor. |
T Derivative(T input) |
Calculates the Jacobian matrices for a batch of vectors stored in a tensor. |
Tensor<T> Activate(Tensor<T> input) |
Applies the Squash activation function to a batch of vectors stored in a tensor. |
Tensor<T> Derivative(Tensor<T> input) |
Calculates the Jacobian matrices for a batch of vectors stored in a tensor. |
Vector<T> Activate(Vector<T> input) |
Applies the Squash activation function to a batch of vectors stored in a tensor. |