MCPcopy
hub / github.com/ddbourgin/numpy-ml / forward

Method forward

numpy_ml/neural_nets/layers/layers.py:2714–2754  ·  view source on GitHub ↗

Compute the layer output given input volume `X`. Parameters ---------- X : :py:class:`ndarray ` of shape `(n_ex, l_in, in_ch)` The input volume consisting of `n_ex` examples, each of length `l_in` and with `in_ch` input channel

(self, X, retain_derived=True)

Source from the content-addressed store, hash-verified

2712 }
2713
2714 def forward(self, X, retain_derived=True):
2715 """
2716 Compute the layer output given input volume `X`.
2717
2718 Parameters
2719 ----------
2720 X : :py:class:`ndarray <numpy.ndarray>` of shape `(n_ex, l_in, in_ch)`
2721 The input volume consisting of `n_ex` examples, each of length
2722 `l_in` and with `in_ch` input channels
2723 retain_derived : bool
2724 Whether to retain the variables calculated during the forward pass
2725 for use later during backprop. If False, this suggests the layer
2726 will not be expected to backprop through wrt. this input. Default
2727 is True.
2728
2729 Returns
2730 -------
2731 Y : :py:class:`ndarray <numpy.ndarray>` of shape `(n_ex, l_out, out_ch)`
2732 The layer output.
2733 """
2734 if not self.is_initialized:
2735 self.in_ch = X.shape[2]
2736 self._init_params()
2737
2738 W = self.parameters["W"]
2739 b = self.parameters["b"]
2740
2741 n_ex, l_in, in_ch = X.shape
2742 s, p, d = self.stride, self.pad, self.dilation
2743
2744 # pad the input and perform the forward convolution
2745 Z = conv1D(X, W, s, p, d) + b
2746 Y = self.act_fn(Z)
2747
2748 if retain_derived:
2749 self.X.append(X)
2750 self.derived_variables["Z"].append(Z)
2751 self.derived_variables["out_rows"].append(Z.shape[1])
2752 self.derived_variables["out_cols"].append(Z.shape[2])
2753
2754 return Y
2755
2756 def backward(self, dLdy, retain_grads=True):
2757 """

Callers 2

test_Conv1DFunction · 0.95
test_pad1DFunction · 0.95

Calls 3

_init_paramsMethod · 0.95
conv1DFunction · 0.85
act_fnMethod · 0.80

Tested by 2

test_Conv1DFunction · 0.76
test_pad1DFunction · 0.76