AIfES 2  2.0.0
ailayer_softmax.h File Reference

Base layer implementation of the Softmax activation layer. More...

Go to the source code of this file.

Data Structures

struct  ailayer_softmax
 General Softmax layer struct. More...
 

Typedefs

typedef struct ailayer_softmax ailayer_softmax_t
 

Functions

ailayer_tailayer_softmax (ailayer_softmax_t *layer, ailayer_t *input_layer)
 Initialize and connect the given Softmax layer. More...
 
void ailayer_softmax_forward (ailayer_t *self)
 Calculate the forward pass for given Softmax layer. More...
 
void ailayer_softmax_calc_result_shape (ailayer_t *self)
 Calculate the shape of the result tensor. More...
 
void ailayer_softmax_print_specs (const ailayer_t *self)
 Print the layer specification. More...
 

Variables

const aicore_layertype_tailayer_softmax_type
 Softmax layer type. More...
 

Detailed Description

Base layer implementation of the Softmax activation layer.

Version
2.2.0

This is an "abstract" data-type independent implementation. To use the layer use one of the provided implementations for a specific hardware and data-type (for example from ailayer_softmax_default.h) or set the required math functions on your own.
This layer is designed as an output-layer and has no backward implementation. If you want to train an ANN with this layer, use the Cross-Entropy loss which has a combined Softmax-Cross-Entropy backward function that is faster to compute!

The Softmax layer is used as an activation function layer right after a dense layer. It calculates

\[ y_i = \frac{e^{x_i}}{\sum_{j=1}^{K} e^{x_j}} \]

for every element of the input tensor with \( K \) elements.

The results of the forward pass of this layer are written to the result tensor of the base ailayer_t struct.

Function Documentation

◆ ailayer_softmax()

ailayer_t* ailayer_softmax ( ailayer_softmax_t layer,
ailayer_t input_layer 
)

Initialize and connect the given Softmax layer.

This function represents the "constructor" of the abstract Softmax layer. It initializes the layer structure and connects it to the previous layer.
This function is not intended to call it directly. Instead use one of the data type specific implementations (like for example ailayer_softmax_f32_default()).

Parameters
*layerThe layer to initialize.
*input_layerThe previous layer that provides the inputs to the layer.
Returns
Pointer to the (successfully) initialized general layer structure (ailayer_softmax.base).

◆ ailayer_softmax_calc_result_shape()

void ailayer_softmax_calc_result_shape ( ailayer_t self)

Calculate the shape of the result tensor.

Implementation of ailayer.calc_result_shape.

As the result tensor shape is shared with the result tensor shape of the previous layer (no change in shape is needed), this function returns without doing anything.

Parameters
*selfLayer to calculate the resulting shape for.

◆ ailayer_softmax_forward()

void ailayer_softmax_forward ( ailayer_t self)

Calculate the forward pass for given Softmax layer.

Implementation of ailayer.forward.

It uses the result tensor of the previous layer as input and writes the result of the forward pass to the result tensor (ailayer.result) of the given layer.

Calculation of the forward pass result:

\[ x_{out} \leftarrow Softmax(x_{in}) \]

\( x_{in} \): Result of the forward pass of the previous layer
\( x_{out} \): Result of the forward pass of this layer

Used math functions:

Parameters
*selfLayer to calculate the forward path for.

◆ ailayer_softmax_print_specs()

void ailayer_softmax_print_specs ( const ailayer_t self)

Print the layer specification.

Parameters
*selfThe layer to print the specification for

Variable Documentation

◆ ailayer_softmax_type

const aicore_layertype_t* ailayer_softmax_type
extern

Softmax layer type.

Defines the type of the layer (for example for type checks and debug prints). See aicore_layertype for more information about the layer type.