Activation Functions From Scratch
Implement ReLU and Sigmoid from scratch (pure math, exactly as the notes' own conceptual relu() example does) and apply both to a list of numbers.
Why not build this in Keras/PyTorch? those frameworks are large, GPU-oriented libraries very unlikely to be available in a lightweight code-execution sandbox, and even training a tiny network introduces its own floating-point non-determinism across environments — but the activation functions THEMSELVES are just plain math (the notes' own relu() example already shows this), so this tests that underlying concept directly, dependency-free.
Approach: relu(x) is max(0, x); sigmoid(x) is 1 / (1 + e^-x) using math.exp. Apply both to every given number.
Input: One line: space-separated numbers.
Output: Two lines: the ReLU of each number as a list, then the Sigmoid of each number as a list (each value rounded to 4 decimal places).
-3 0 2 5
[0, 0, 2.0, 5.0] [0.0474, 0.5, 0.8808, 0.9933]
- 1 <= count of numbers <= 20
Hint 1
relu(x) is exactly max(0, x) — the notes' own example.
Hint 2
sigmoid(x) is 1 / (1 + math.exp(-x)); import math for exp().
Hint 3
Round each result to 4 decimal places with round(value, 4) before printing.
relu(x) = max(0, x) — the exact conceptual example from the notes. sigmoid(x) = 1 / (1 + e^-x) squeezes any real number into the range (0, 1). Applying both to every input value and rounding to 4 decimal places gives a fully deterministic, dependency-free way to test genuine understanding of what these activation functions actually compute.