| AIfES 2 2.0.0

Data Fields
ailoss_crossentropy Struct Reference

General Cross-Entropy loss struct. More...

`#include <ailoss_crossentropy.h>`

## Data Fields
ailoss_t | base
| Inherited field members from general ailoss struct.
const aimath_dtype_t * | dtype
| Main data type of the loss.
Math functions
Required data type specific math functions
void(* | tensor_sub )(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
| Required math function: Element wise tensor subtraction. More...
void(* | crossentropy )(const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
| Required math function: Cross-Entropy between two tensors. More...
void(* | scale_by_batch_size )(const aitensor_t *predicted_data, aitensor_t *result)
| Required math function: Scaling of the gradient tensor. More...

## Detailed Description

General Cross-Entropy loss struct.

## Field Documentation

## ◆ crossentropy

void(* crossentropy) (const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)

Required math function: Cross-Entropy between two tensors.

Requires a math function that calculates the Cross-Entropy between two tensors.
For a Sigmoid output layer it should be the binary Cross-Entropy:

\[ result = -\sum (target \cdot \log(predicted) + (1 - target) \log(1 - predicted)) \]

For a Softmax output layer it should be the categorical Cross-Entropy:

\[ result = -\sum target \cdot \log(predicted) \]

Parameters

  result | A Scalar of the defined data type

## ◆ scale_by_batch_size

void(* scale_by_batch_size) (const aitensor_t *predicted_data, aitensor_t *result)

Required math function: Scaling of the gradient tensor.

Requires a math function that scales a tensor by its batch size:

## ◆ tensor_sub

void(* tensor_sub) (const aitensor_t *a, const aitensor_t *b, aitensor_t *result)

Required math function: Element wise tensor subtraction.

Requires a math function that subtracts two tensors element wise:

\[ result = a - b \]

The documentation for this struct was generated from the following file:

- ailoss_crossentropy.h