Table of Contents

Class ActivationHelper

Namespace
AiDotNet.Helpers
Assembly
AiDotNet.dll

Provides centralized helper methods for applying activation functions with optimal performance. Uses Engine methods (GPU/SIMD) for known activation types, falls back to standard activation otherwise.

public static class ActivationHelper
Inheritance
ActivationHelper
Inherited Members

Remarks

This class consolidates activation type-checking logic in one place, following DRY (Don't Repeat Yourself) and SOLID principles. All layers should use these methods instead of duplicating if-else chains.

Methods

ApplyActivation<T>(IVectorActivationFunction<T>?, Tensor<T>, IEngine)

Applies a vector activation function to a tensor using Engine methods when possible.

public static Tensor<T> ApplyActivation<T>(IVectorActivationFunction<T>? activation, Tensor<T> input, IEngine engine)

Parameters

activation IVectorActivationFunction<T>

The vector activation function to apply.

input Tensor<T>

The input tensor to activate.

engine IEngine

The engine to use for optimized operations.

Returns

Tensor<T>

The activated tensor, or input unchanged if activation is null.

Type Parameters

T

The numeric type (float, double, etc.).

ApplyActivation<T>(IVectorActivationFunction<T>?, Vector<T>, IEngine)

Applies a vector activation function to a vector using Engine methods when possible.

public static Vector<T> ApplyActivation<T>(IVectorActivationFunction<T>? activation, Vector<T> input, IEngine engine)

Parameters

activation IVectorActivationFunction<T>

The vector activation function to apply.

input Vector<T>

The input vector to activate.

engine IEngine

The engine to use for optimized operations.

Returns

Vector<T>

The activated vector, or input unchanged if activation is null.

Type Parameters

T

The numeric type (float, double, etc.).