๐ง ReLU vs PReLU – The Smart Gatekeepers of Neural Networks
In deep learning, activation functions decide what information should pass forward in a neural network. Think of them as intelligent filters.
๐ Table of Contents
- What is ReLU?
- Problem with ReLU
- What is PReLU?
- Math Explained Simply
- Examples
- Code Example
- CLI Output
- Comparison Table
- Key Takeaways
- Related Articles
⚡ What is ReLU?
ReLU (Rectified Linear Unit) is one of the most commonly used activation functions.
\[ f(x) = \max(0, x) \]
⚠️ Problem: Dying ReLU
When neurons receive negative inputs repeatedly:
\[ f(x) = 0 \]
they stop learning entirely.
๐ What is PReLU?
PReLU (Parametric ReLU) solves this problem by allowing a small portion of negative values to pass.
๐ PReLU Mathematics (Simple)
\[ f(x) = \begin{cases} x, & x > 0 \\ \alpha x, & x \leq 0 \end{cases} \]
Explanation:
- \(x\): input
- \(\alpha\): small learnable parameter
๐ Example
Let’s assume:
\[ \alpha = 0.2 \]
| Input | ReLU Output | PReLU Output |
|---|---|---|
| 4 | 4 | 4 |
| -2 | 0 | -0.4 |
๐ป Code Example
import torch
import torch.nn as nn
relu = nn.ReLU()
prelu = nn.PReLU()
x = torch.tensor([-2.0, 4.0])
print("ReLU:", relu(x))
print("PReLU:", prelu(x))
๐ฅ️ CLI Output
Click to Expand
ReLU: tensor([0., 4.]) PReLU: tensor([-0.5, 4.])
๐ Comparison
| Feature | ReLU | PReLU |
|---|---|---|
| Negative values | 0 | Scaled |
| Learnable | No | Yes |
| Dying neuron issue | Yes | Reduced |
๐ก Key Takeaways
- ReLU is simple and efficient
- PReLU adds flexibility
- Math shows how scaling works
- PReLU can improve learning performance
๐ฏ Final Thought
ReLU is like a strict teacher. PReLU is a smarter one—it still corrects mistakes but doesn’t ignore useful signals.
And in deep learning, that flexibility can make all the difference.
No comments:
Post a Comment