You already know two kinds of bent graphs: the V of the absolute value function and the pieces of a piecewise function. Both can be built from one simple shape, the ramp: $$\operatorname{ReLU}(x) = \max(0, x) = \begin{cases} 0, & x < 0 \\ x, & x \ge 0. \end{cases}$$ It is flat at $0$ for negative inputs, then rises with slope $1$. (ReLU is short for "rectified linear unit.")
Key idea
Why it works
Worked examples
Worked example: Absolute value from two ramps
- For $x \ge 0$: $\operatorname{ReLU}(x) = x$, and $-x \le 0$ gives $\operatorname{ReLU}(-x) = 0$. The sum is $x$, which is $|x|$.
- For $x < 0$: $\operatorname{ReLU}(x) = 0$, and $-x$ is positive, so $\operatorname{ReLU}(-x) = -x$. The sum is $-x$, which is $|x|$.
- Check $x = -3$: $\operatorname{ReLU}(-3) + \operatorname{ReLU}(3) = 0 + 3 = 3 = |-3|$.
Answer: $|x| = \operatorname{ReLU}(x) + \operatorname{ReLU}(-x)$
Worked example: Reading a sum of ramps
- At $x = 4$ the insides are $4 + 1 = 5$ and $4 - 2 = 2$, both positive. So $f(4) = 2 \cdot 5 - 3 \cdot 2 = 4$.
- The bends are where the insides are $0$: $x = -1$ and $x = 2$.
- Slopes: $0$ to the left of $-1$; $0 + 2 = 2$ between $-1$ and $2$; $2 + (-3) = -1$ to the right of $2$.
Answer: $f(4) = 4$; slopes $0$, $2$, $-1$
Worked example: Writing a graph as ramps
- Start with the line of the left piece: slope $-1$ through $(0, 1)$ is $y = -x + 1$.
- At $x = 0$ the slope changes from $-1$ to $1$, a change of $2$. Add $2\operatorname{ReLU}(x)$.
- At $x = 3$ the slope changes from $1$ to $0$, a change of $-1$. Add $-\operatorname{ReLU}(x - 3)$.
- Check $x = 5$: $-5 + 1 + 2 \cdot 5 - 2 = 4$, the height of the flat piece. ✓
Answer: $f(x) = -x + 1 + 2\operatorname{ReLU}(x) - \operatorname{ReLU}(x - 3)$
Common mistake
Common mistake