Skip to content

Calculate DZ Softmax CCE Method

Functions

calculate_dZ_softmax_categorical_crossentropy(A, Y)

Calculate dZ for softmax activation with categorical cross-entropy loss.

Parameters:

Name Type Description Default
A ndarray

Activations of the current layer (softmax output).

required
Y ndarray

True labels (one-hot encoded).

required

Returns:

Type Description

numpy.ndarray: Gradient of Z.

Example
dZ = calculate_dZ_softmax_categorical_crossentropy(A, Y)
print(dZ.shape)
Source code in microkeras/operations/backward/calculate_dZ_softmax_categorical_crossentropy.py
def calculate_dZ_softmax_categorical_crossentropy(A, Y):
    """
    Calculate dZ for softmax activation with categorical cross-entropy loss.

    Args:
        A (numpy.ndarray): Activations of the current layer (softmax output).
        Y (numpy.ndarray): True labels (one-hot encoded).

    Returns:
        numpy.ndarray: Gradient of Z.

    Example:
        ```python
        dZ = calculate_dZ_softmax_categorical_crossentropy(A, Y)
        print(dZ.shape)
        ```
    """
    return A - Y