Skip to content

Calculate DZ Linear MSE Method

Functions

calculate_dZ_linear_mean_squared_error(A, Y, Z)

Calculate dZ for linear activation with mean squared error loss.

Parameters:

Name Type Description Default
A ndarray

Activations of the current layer.

required
Y ndarray

True labels.

required
Z ndarray

Linear output of the current layer.

required

Returns:

Type Description

numpy.ndarray: Gradient of Z.

Example
dZ = calculate_dZ_linear_mean_squared_error(A, Y, Z)
print(dZ.shape)
Source code in microkeras/operations/backward/calculate_dZ_linear_mean_squared_error.py
def calculate_dZ_linear_mean_squared_error(A, Y, Z):
    """
    Calculate dZ for linear activation with mean squared error loss.

    Args:
        A (numpy.ndarray): Activations of the current layer.
        Y (numpy.ndarray): True labels.
        Z (numpy.ndarray): Linear output of the current layer.

    Returns:
        numpy.ndarray: Gradient of Z.

    Example:
        ```python
        dZ = calculate_dZ_linear_mean_squared_error(A, Y, Z)
        print(dZ.shape)
        ```
    """
    m = A.shape[1]
    dZ = 2 * (A - Y) / m
    return dZ