Unlock the magic behind neural networks with this **Linear & Non-Linear Activation Functions** Jupyter Notebook! This project offers a vibrant visual exploration of fundamental activation functions like **Linear, ReLU, Sigmoid, and Tanh**. Understand their behavior, impact on neural network capabilities, and why non-linearity is crucial for deep learning. Perfect for students, researchers, and anyone curious about the building blocks of AI! ✨
Table of Contents
This project offers a clear and concise visualization of various **activation functions** commonly used in artificial neural networks. [cite: uploaded:linear_and_Non_Linear_Activation_Function.ipynb] Understanding activation functions is crucial as they introduce non-linearity into the network, enabling it to learn complex patterns and relationships in data. Without non-linear activation functions, a neural network, no matter how many layers it has, would behave like a simple linear regression model. This notebook uses `NumPy` for numerical operations and `Matplotlib` for plotting, making the concepts easy to grasp visually.
The notebook provides detailed visualizations and implementations for the following activation functions:
-
1. Linear Function (
$y = mx + b$ ):A simple function where the output is directly proportional to the input. While not commonly used in hidden layers of deep networks due to its inability to introduce non-linearity, it's fundamental for understanding the basics and sometimes used in the output layer for regression tasks.
-
2. ReLU (Rectified Linear Unit) Function ($y = \text{max}(0, x)$):
One of the most popular activation functions in deep learning. It outputs the input directly if it's positive, otherwise, it outputs zero. Its simplicity and computational efficiency make it widely used in hidden layers.
-
3. Sigmoid Function ($y = 1 / (1 + e^{-x})$):
Also known as the logistic function, it squashes input values into a range between 0 and 1. Historically popular in output layers for binary classification problems, though it suffers from vanishing gradients in deep networks.
-
4. Tanh (Hyperbolic Tangent) Function ($y = (e^x - e^{-x}) / (e^x + e^{-x})$):
Similar to Sigmoid but squashes input values into a range between -1 and 1. It's zero-centered, which often helps with training stability compared to Sigmoid, and was a popular choice before ReLU's widespread adoption.
- 📈 Interactive Visualizations: See how each activation function transforms input values through clear plots. [cite: uploaded:linear_and_Non_Linear_Activation_Function.ipynb]
- ✍️ Simple Implementations: Each function is implemented from scratch using NumPy for better understanding. [cite: uploaded:linear_and_Non_Linear_Activation_Function.ipynb]
- 🔍 Side-by-Side Comparisons: Plots are arranged for easy comparison of different activation functions. [cite: uploaded:linear_and_Non_Linear_Activation_Function.ipynb]
- 📚 Educational Resource: Well-commented code and clear explanations make it an ideal learning tool for deep learning fundamentals.
To run this project, ensure you have the following installed:
- Python 3.x
- Jupyter Notebook (or JupyterLab, Google Colab)
- Required Libraries:
pip install numpy matplotlib
-
Download the Notebook:
Download
linear_and_Non_Linear_Activation_Function.ipynbfrom this repository.Alternatively, open it directly in Google Colab for a zero-setup experience.
-
Install Dependencies:
pip install numpy matplotlib -
Run the Notebook:
Open
linear_and_Non_Linear_Activation_Function.ipynbin Jupyter or Colab.Execute each cell sequentially to visualize the activation functions!
The notebook will generate plots for each activation function, similar to the examples below:
Here are the core implementations of the activation functions:
def linear_function(x, m=1, b=0):
return m * x + bdef relu_function(x):
return np.maximum(0, x)def sigmoid(x):
return 1 / (1 + np.exp(-x))def tanh(x):
return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))Want to expand your understanding of activation functions? Here are some ideas:
- 📈 Explore Derivatives: Add plots for the derivatives of each non-linear activation function. This is crucial for understanding backpropagation.
- 🧪 More Functions: Implement and visualize other activation functions like Leaky ReLU, ELU, Swish, or Softmax.
- 📊 Network Impact: Create a very simple neural network and demonstrate how different activation functions affect its ability to learn a non-linear decision boundary.
- 🎨 Interactive Widgets: Use Jupyter widgets to create sliders for changing parameters (e.g., `m` and `b` for linear function, or `alpha` for Leaky ReLU) in real-time.
Contributions are always welcome! If you have ideas for new activation functions to add, improvements to existing visualizations, or any other enhancements, please feel free to open an issue or submit a pull request. Let's illuminate the concepts of deep learning together! 💡
Star this repo if you find it helpful! ⭐
Created with 💖 by Chirag