smash.factory.Net.forward_pass#

Net.forward_pass(x)[source]#

Perform a forward pass through the neural network.

Parameters:
xnumpy.ndarray

An array representing the input data for the neural network. The shape of this array must be broadcastable into the input shape of the first layer.

Returns:
ynumpy.ndarray

The output of the neural network after passing through all layers.

Examples

>>> from smash.factory import Net
>>> net = Net()
>>> net.add_dense(12, input_shape=5, activation="tanh")
>>> net.add_dense(3, activation="softmax")
>>> net
+----------------------------------------------------------+
| Layer Type            Input/Output Shape  Num Parameters |
+----------------------------------------------------------+
| Dense                 (5,)/(12,)          72             |
| Activation (TanH)     (12,)/(12,)         0              |
| Dense                 (12,)/(3,)          39             |
| Activation (Softmax)  (3,)/(3,)           0              |
+----------------------------------------------------------+
Total parameters: 111
Trainable parameters: 111

Set random weights

>>> net.set_weight(random_state=1)

Run the forward pass

>>> import numpy as np
>>> x = np.array([0.1, 0.11, 0.12, 0.13, 0.14])
>>> net.forward_pass(x)
array([[0.31315546, 0.37666753, 0.31017701]])