Skip to content

Forward Method

Functions

forward(nn, X)

Perform forward propagation through the entire neural network.

Parameters:

Name Type Description Default
nn Sequential

The neural network model.

required
X ndarray

The input data.

required

Returns:

Type Description

numpy.ndarray: The output of the last layer (final predictions).

Example
model = Sequential([
    Dense(64, activation='relu', input_shape=(128,)),
    Dense(10, activation='softmax')
])
X = np.random.randn(128, 32)
output = forward(model, X)
print(output.shape)
Note

This function updates the Z and A attributes of each layer in the network.

Source code in microkeras/operations/forward/forward.py
def forward(nn, X):
    """
    Perform forward propagation through the entire neural network.

    Args:
        nn (Sequential): The neural network model.
        X (numpy.ndarray): The input data.

    Returns:
        numpy.ndarray: The output of the last layer (final predictions).

    Example:
        ```python
        model = Sequential([
            Dense(64, activation='relu', input_shape=(128,)),
            Dense(10, activation='softmax')
        ])
        X = np.random.randn(128, 32)
        output = forward(model, X)
        print(output.shape)
        ```

    Note:
        This function updates the Z and A attributes of each layer in the network.
    """
    A = X
    for layer in nn.layers:
        Z, A = forward_layer(layer, A)
        layer.Z = Z
        layer.A = A
    return A