Activation functions

November 8, 2022 ยท View on GitHub

This section describes the layers that calculate the value of specified activation functions for each of their inputs.

Creating a layer

CPtr<CBaseLayer> NEOML_API CreateActivationLayer( const CActivationDesc& activation );

Creates a layer that calculates the activation function specified by the activation parameter.

Activation parameters holder

To create a layer, one must specify its type and, optionally, parameters. All configurable activation layers have a CParam structure with all possible settings.

class CActivationDesc {
public:
	// For non-parametrized activations or default parameters
	CActivationDesc( TActivationFunction type );

	// For explicitly setting activation parameters. 'Param' must be a 'CParam' struct from the correspondent layer
	template<class Param>
	CActivationDesc( TActivationFunction type, const Param& param );

	// Changing/setting parameters of the selected activation.
	// 'Param' must be a 'CParam' struct from the correspondent layer.
	template<class Param>
	void SetParam( const Param& param );

	/// etc.
};

Layer types

enum TActivationFunction {
	AF_Linear = 0,
	AF_ELU,
	AF_ReLU,
	AF_LeakyReLU,
	AF_Abs,
	AF_Sigmoid,
	AF_Tanh,
	AF_HardTanh,
	AF_HardSigmoid,
	AF_Power,
	AF_HSwish,
	AF_GELU,
	AF_Exp,
	AF_Log,

	AF_Count
};
TActivationFunction constantClass nameActivation function
AF_LinearCLinearLayera linear activation function: ax + b
AF_ELUCELULayerELU activation function
AF_ReLUCReLULayerReLU activation function
AF_LeakyReLUCLeakyReLULayerLeakyReLU activation function
AF_AbsCAbsLayerabs(x) activation function
AF_SigmoidCSigmoidLayersigmoid activation function
AF_TanhCTanhLayertanh activation function
AF_HardTanhCHardTanhLayerHardTanh activation function
AF_HardSigmoidCHardSigmoidLayerHardSigmoid activation function
AF_PowerCPowerLayerpow(x, exp) activation function
AF_HSwishCHSwishLayerh-swish activation function
AF_GELUCGELULayerx * F( X < x ) activation function, where X ~ N(0, 1)
AF_ExpCExpLayerexp activation function
AF_LogCLogLayerlog activation function
AF_ErfCErfLayererf activation function
AF_CountThis is an auxiliary constant: it contains the number of supported activation functions.