| AIfES 2 2.0.0

Data Structures | Typedefs | Functions | Variables
ailayer_sigmoid.h File Reference

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

Go to the source code of this file.

## Data Structures
struct | ailayer_sigmoid
| General Sigmoid layer struct. More...

## Typedefs
typedef struct ailayer_sigmoid | ailayer_sigmoid_t

## Functions
ailayer_t * | ailayer_sigmoid (ailayer_sigmoid_t *layer, ailayer_t *input_layer)
| Initialize and connect the given Sigmoid layer. More...
void | ailayer_sigmoid_forward (ailayer_t *self)
| Calculate the forward pass for given Sigmoid layer. More...
void | ailayer_sigmoid_backward (ailayer_t *self)
| Calculate the backward pass for the given Sigmoid layer. More...
void | ailayer_sigmoid_calc_result_shape (ailayer_t *self)
| Calculate the shape of the result tensor. More...
uint32_t | ailayer_sigmoid_sizeof_bwdmem (const ailayer_t *self)
void | ailayer_sigmoid_print_specs (const ailayer_t *self)
| Print the layer specification. More...

## Variables
const aicore_layertype_t * | ailayer_sigmoid_type
| Sigmoid layer type. More...

## Detailed Description

Base layer implementation of the Sigmoid activation layer.

Version
  2.2.0

Copyright
  Copyright (C) 2020-2023 Fraunhofer Institute for Microelectronic Circuits and Systems. All rights reserved.
  AIfES is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
  You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

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_sigmoid_default.h) or set the required math functions on your own.

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

\[ y = \sigma(x) = \frac{1}{1+e^{-x}} \]

for every element of the input tensor.

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

## Function Documentation

## ◆ ailayer_sigmoid()

ailayer_t* ailayer_sigmoid | ( | ailayer_sigmoid_t * | layer,
|  | ailayer_t * | input_layer
| ) |  |

Initialize and connect the given Sigmoid layer.

This function represents the "constructor" of the abstract Sigmoid 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_sigmoid_f32_default()).

Parameters

  *layer | The layer to initialize.
  *input_layer | The previous layer that provides the inputs to the layer.

Returns
  Pointer to the (successfully) initialized general layer structure (ailayer_sigmoid.base).

## ◆ ailayer_sigmoid_backward()

void ailayer_sigmoid_backward | ( | ailayer_t * | self | ) |

Calculate the backward pass for the given Sigmoid layer.

Implementation of ailayer.backward.

It uses the deltas tensor of the next layer as input and writes the result of the backward pass to the deltas tensor (ailayer.deltas) of the given layer.

Calculation of the errors for the previous layer:

\[ \delta_{in} \leftarrow \delta_{out} \circ \sigma'(x_{in}) \]

\( x_{in} \): Result of the forward pass of the previous layer
\( \delta_{in} \): Result of the backward pass of this layer
\( \delta_{out} \): Result of the backward pass of the next layer
Used math functions:

- ailayer_sigmoid.sigmoid
- ailayer_sigmoid.d_sigmoid
- ailayer_sigmoid.multiply

Parameters

  *self | Layer to calculate the backward path for.

## ◆ ailayer_sigmoid_calc_result_shape()

void ailayer_sigmoid_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

  *self | Layer to calculate the resulting shape for.

## ◆ ailayer_sigmoid_forward()

void ailayer_sigmoid_forward | ( | ailayer_t * | self | ) |

Calculate the forward pass for given Sigmoid 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 \sigma(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:

- ailayer_sigmoid.sigmoid

Parameters

  *self | Layer to calculate the forward path for.

## ◆ ailayer_sigmoid_print_specs()

void ailayer_sigmoid_print_specs | ( | const ailayer_t * | self | ) |

Print the layer specification.

Parameters

  *self | The layer to print the specification for

## Variable Documentation

## ◆ ailayer_sigmoid_type

const aicore_layertype_t* ailayer_sigmoid_type
| extern

Sigmoid 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.