#183Dense layer with ReLU (the production hidden default)EasyNeural NetworksActivation Functions
Dense layer with ReLU (the production hidden default)
Background
The course's worked net uses sigmoid in the hidden layer for uniform math, but in practice hidden layers use ReLU — it's fast, sparse, and doesn't vanish gradients for positive inputs. A ReLU dense layer is:
where W has shape (n_out, n_in).
Problem statement
Implement relu_layer(x, W, b) returning .
Input
x— input vector, lengthn_in.W— weight matrix(n_out, n_in).b— bias vector(n_out,).
Output
Returns an np.ndarray of shape (n_out,), all entries .
Examples
Example 1
Input: x = [1, -1], W = [[1, 1], [2, -1]], b = [0, 0]
Output: [0. 3.]
Explanation: ; ReLU clips nothing here except the 0.
Example 2 — negative pre-activations clip to 0
Input: x = [1], W = [[-2]], b = [0]
Output: [0.]
Explanation: .
Constraints
- Compute
W @ x + b, then applymax(0, ·)elementwise. - Return an
np.ndarrayof shape(n_out,).
Notes
- Swapping this ReLU hidden layer in (and pairing the sigmoid output with BCE) is the standard production upgrade over the all-sigmoid teaching net.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Mixed pre-activations example
- •Negative clips to zero (reference)
- •Bias rescues a negative score (sample)