Skip to content

Calculate DB Method

Functions

calculate_db(dZ, m)

Calculate the gradient of the bias.

Parameters:

Name Type Description Default
dZ ndarray

Gradient of the cost with respect to the linear output.

required
m int

Number of training examples.

required

Returns:

Type Description

numpy.ndarray: Gradient of the bias.

Example
db = calculate_db(dZ, 32)
print(db.shape)
Source code in microkeras/operations/backward/calculate_db.py
def calculate_db(dZ, m):
    """
    Calculate the gradient of the bias.

    Args:
        dZ (numpy.ndarray): Gradient of the cost with respect to the linear output.
        m (int): Number of training examples.

    Returns:
        numpy.ndarray: Gradient of the bias.

    Example:
        ```python
        db = calculate_db(dZ, 32)
        print(db.shape)
        ```
    """
    return (1 / m) * np.sum(dZ, axis=1, keepdims=True)