Neural Networks Math: A Visual Introduction for Beginners
Neural networks, a core component of machine learning, can seem daunting at first, especially with their mathematical underpinnings. However, with a visual approach and a bit of patience, anyone can grasp the fundamentals. Let's embark on this journey, breaking down the math behind neural networks in an intuitive, beginner-friendly manner.
Table of Contents
Activation Functions
Activation functions are the building blocks of neural networks, introducing non-linearity into the model. They transform the input of a neuron into its output, determining whether a neuron should be activated or not. Let's explore a few common activation functions:
| Function | Formula | Graph |
|---|---|---|
| Sigmoid | σ(x) = 1 / (1 + e-x) | ![]() |
| Tanh | tanh(x) = (ex - e-x) / (ex + e-x) | ![]() |
| ReLU | ReLU(x) = max(0, x) | ![]() |
Loss Functions
Loss functions, also known as cost functions, measure the difference between the predicted output and the actual output. They guide the learning process by quantifying the error. Here are a few common loss functions:

| Function | Formula | Range |
|---|---|---|
| Mean Squared Error (MSE) | MSE = (1/n) * ∑(yi - ŷi)2 | [0, ∞) |
| Binary Cross-Entropy (BCE) | BCE = -(y * log(ŷ) + (1 - y) * log(1 - ŷ)) | [0, ∞) |
| Categorical Cross-Entropy (CCE) | CCE = -(1/n) * ∑yi * log(ŷi) | [0, ∞) |
Backpropagation
Backpropagation is the workhorse algorithm in neural networks, responsible for updating the weights and biases of the network. It calculates the gradient of the loss function with respect to each weight, allowing us to update them in the direction that reduces the loss. Here's a simplified version of the backpropagation algorithm:
- Forward propagate the input through the network to generate an output.
- Calculate the error of the output using the loss function.
- Backpropagate the error through the network, calculating the gradient of the loss with respect to each weight and bias.
- Update the weights and biases using the calculated gradients.
Gradient Descent
Gradient descent is an optimization algorithm used to minimize the loss function in neural networks. It iteratively updates the weights and biases in the direction that reduces the loss. There are several variants of gradient descent, including:
- Batch Gradient Descent (BGD): Updates the weights after processing the entire dataset.
- Stochastic Gradient Descent (SGD): Updates the weights after processing a single example from the dataset.
- Mini-batch Gradient Descent (MBGD): Updates the weights after processing a small subset (mini-batch) of the dataset.
Each variant has its own strengths and weaknesses, and the choice between them depends on the specific problem and dataset at hand.


























