Optimization Rule in Deep Neural Networks
Last Updated :
23 Jul, 2025
In machine learning, optimizers and loss functions are two fundamental components that help improve a model’s performance.
- A loss function evaluates a model's effectiveness by computing the difference between expected and actual outputs. Common loss functions include log loss, hinge loss and mean square loss.
- An optimizer improves the model by adjusting its parameters (weights and biases) to minimize the loss function value. Examples include RMSProp, ADAM and SGD (Stochastic Gradient Descent).
The optimizer’s role is to find the best combination of weights and biases that leads to the most accurate predictions.
Gradient Descent
Gradient Descent is a popular optimization method for training machine learning models. It works by iteratively adjusting the model parameters in the direction that minimizes the loss function.
Gradient DescentKey Steps in Gradient Descent
- Initialize parameters: Randomly initialize the model parameters.
- Compute the gradient: Calculate the gradient (derivative) of the loss function with respect to the parameters.
- Update parameters: Adjust the parameters by moving in the opposite direction of the gradient, scaled by the learning rate.
Formula :
θ_{(k+1)} = θ_k - α ∇J(θ_k)
where:
- θ_{(k+1)} is the updated parameter vector at the (k+1)^{th} iteration.
- \theta_k is the current parameter vector at the kth iteration.
- \alpha is the learning rate, which is a positive scalar that determines the step size for each iteration.
- ∇J(θ_k) is the gradient of the cost or loss function J with respect to the parameters \theta_{k}
Gradient Descent with Armijo Goldstein Condition
This variant ensures that the step size is large enough to effectively reduce the objective function, using a line search that satisfies the Armijo condition.
Condition:
f(x^{t-1} + α∇f(x^{t-1})) - f(x^{t-1}) \ge c α ||∇f(x^{t-1})||^2
Where:
- \alpha is the step size.
- c is a constant between 0 and 1.
Gradient Descent with Armijo Full Relaxation Condition
Incorporates both first and second derivatives (Hessian matrix) to determine a more optimal step size for the update.
Condition:
f(x^{t-1} + α∇f(x^{t-1})) - f(x^{t-1}) \ge c α ||∇f(x^{t-1})||^2 + \frac{b}{2} α^2∇f(x^{t-1})^T H(x) ∇f(x^{t-1})
Where:
- H(x) is the Hessian matrix.
- c and b are constants between 0 and 1.
Variants of Gradient Descent
1. Stochastic Gradient Descent (SGD)
Stochastic Gradient Descent (SGD) updates the model parameters after each training example, making it more efficient for large datasets compared to traditional Gradient Descent, which uses the entire dataset for each update.
Stochastic Gradient DescentSteps:
- Select a training example.
- Compute the gradient of the loss function.
- Update the model parameters.
Advantages: Requires less memory and may find new minima.
Disadvantages: Noisier, requiring more iterations to converge.
2. Mini Batch Gradient Descent
Mini-batch gradient descent consists of a predetermined number of training examples, smaller than the full dataset. This approach combines the advantages of the previously mentioned variants.
Mini-Batch Gradient DescentIn one epoch, following the creation of fixed-size mini-batches, we execute the following steps:
- Select a mini-batch.
- Compute the mean gradient of the mini-batch.
- Apply the mean gradient obtained in step 2 to update the model's weights.
- Repeat steps 1 to 2 for all the mini-batches that have been created.
Advantages: Requires medium amount of memory and less time required to converge when compared to SGD
Disadvantage: May get stuck at local minima
3. SGD with Momentum
Momentum-Based Gradient DescentMomentum helps accelerate convergence by smoothing out the noisy gradients of SGD, thus reducing fluctuations and improving the speed of convergence.
v_{(t+1)} = β * v_t + (1 - β) * ∇J(θ_t)
Where:
- v_t is the momentum at time t.
- \beta is the momentum coefficient.
- ∇J(θ_t) is the gradient at time t.
Then, the model parameters are updated using:
θ_{(t+1)} = θ_t - α * v_{(t+1)}
Advantages: Mitigates oscillations, reduces variance and faster convergence.
Disadvantages: Requires tuning the momentum coefficient \beta.
Advanced Optimizers
1. AdaGrad
AdaGrad adapts the learning rate for each parameter based on the historical gradient information. The learning rate decreases over time, making AdaGrad effective for sparse features.
θ_{(t+1)} = θ_t - \frac{α}{\sqrt{G_t + ε}} * ∇J(θ_t)
Where:
- G_t is the sum of squared gradients.
- \varepsilon is a small constant to avoid division by zero.
Advantages: Adapts the learning rate, improving training efficiency.
Disadvantages: Learning rate decays too quickly, causing slow convergence.
2. RMSProp
RMSProp improves upon AdaGrad by introducing a decay factor to prevent the learning rate from decreasing too rapidly.
E[g^2]_t = γ * E[g^2]_{(t-1)} + (1 - γ) * (∇J(θ_t))^2
θ_{(t+1)} = θ_t - \frac{α}{\sqrt{E[g^2]_t + ε}} * ∇J(θ_t)
Where:
- \gamma is the decay rate.
- E[g^2]_t is the exponentially moving average of squared gradients.
Advantages: Prevents excessive decay of learning rates.
Disadvantages: Computationally expensive due to the additional parameter.
3. Adam (Adaptive Moment Estimation)
Adam combines the advantages of Momentum and RMSProp. It uses both the first moment (mean) and second moment (variance) of gradients to adapt the learning rate for each parameter.
- Update the first moment: m_t = β_1 * m_{(t-1)} + (1 - β_1) * ∇J(θ_t)
- Update the second moment: v_t = β_2 * v_{(t-1)} + (1 - β_2) * (∇J(θ_t))^2
- Bias correction: \hat{m}_t = \frac{m_t}{1 - β_1^t}, \quad \hat{v}_t = \frac{v_t}{1 - β_2^t}
- Update parameters: θ_{(t+1)} = θ_t - \frac{α}{\sqrt{\hat{v}_t + ε}} * \hat{m}_t
Where:
- \beta_{1} and β_2 are the decay rates for the first and second moments.
- \varepsilon is a small constant to prevent division by zero.
Advantages: Fast convergence.
Disadvantages: Requires significant memory due to the need to store first and second moment estimates.
Comparison of Optimizers
Optimizer | Advantages | Disadvantages |
---|
SGD | Simple, easy to implement | Slow convergence, requires tuning |
---|
Mini-Batch SGD | Faster than SGD | Computationally expensive, stuck in local minima |
---|
SGD with Momentum | Faster convergence, reduces noise | Requires careful tuning of β |
---|
AdaGrad | Adaptive learning rates | Decays too fast, slow convergence |
---|
RMSProp | Prevents fast decay of learning rates | Computationally expensive |
---|
Adam | Fast, combines momentum and RMSProp | Memory-intensive, computationally expensive |
---|
Each optimizer has its own strengths and weaknesses. The choice of optimizer depends on the specific problem, dataset characteristics and the computational resources available. Adam is often the default choice due to its robust performance, but each situation may call for a different optimizer to achieve optimal results.
Similar Reads
Deep Learning Tutorial Deep Learning is a subset of Artificial Intelligence (AI) that helps machines to learn from large datasets using multi-layered neural networks. It automatically finds patterns and makes predictions and eliminates the need for manual feature extraction. Deep Learning tutorial covers the basics to adv
5 min read
Deep Learning Basics
Introduction to Deep LearningDeep Learning is transforming the way machines understand, learn and interact with complex data. Deep learning mimics neural networks of the human brain, it enables computers to autonomously uncover patterns and make informed decisions from vast amounts of unstructured data. How Deep Learning Works?
7 min read
Artificial intelligence vs Machine Learning vs Deep LearningNowadays many misconceptions are there related to the words machine learning, deep learning, and artificial intelligence (AI), most people think all these things are the same whenever they hear the word AI, they directly relate that word to machine learning or vice versa, well yes, these things are
4 min read
Deep Learning Examples: Practical Applications in Real LifeDeep learning is a branch of artificial intelligence (AI) that uses algorithms inspired by how the human brain works. It helps computers learn from large amounts of data and make smart decisions. Deep learning is behind many technologies we use every day like voice assistants and medical tools.This
3 min read
Challenges in Deep LearningDeep learning, a branch of artificial intelligence, uses neural networks to analyze and learn from large datasets. It powers advancements in image recognition, natural language processing, and autonomous systems. Despite its impressive capabilities, deep learning is not without its challenges. It in
7 min read
Why Deep Learning is ImportantDeep learning has emerged as one of the most transformative technologies of our time, revolutionizing numerous fields from computer vision to natural language processing. Its significance extends far beyond just improving predictive accuracy; it has reshaped entire industries and opened up new possi
5 min read
Neural Networks Basics
What is a Neural Network?Neural networks are machine learning models that mimic the complex functions of the human brain. These models consist of interconnected nodes or neurons that process data, learn patterns and enable tasks such as pattern recognition and decision-making.In this article, we will explore the fundamental
11 min read
Types of Neural NetworksNeural networks are computational models that mimic the way biological neural networks in the human brain process information. They consist of layers of neurons that transform the input data into meaningful outputs through a series of mathematical operations. In this article, we are going to explore
7 min read
Layers in Artificial Neural Networks (ANN)In Artificial Neural Networks (ANNs), data flows from the input layer to the output layer through one or more hidden layers. Each layer consists of neurons that receive input, process it, and pass the output to the next layer. The layers work together to extract features, transform data, and make pr
4 min read
Activation functions in Neural NetworksWhile building a neural network, one key decision is selecting the Activation Function for both the hidden layer and the output layer. It is a mathematical function applied to the output of a neuron. It introduces non-linearity into the model, allowing the network to learn and represent complex patt
8 min read
Feedforward Neural NetworkFeedforward Neural Network (FNN) is a type of artificial neural network in which information flows in a single direction i.e from the input layer through hidden layers to the output layer without loops or feedback. It is mainly used for pattern recognition tasks like image and speech classification.
6 min read
Backpropagation in Neural NetworkBack Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
Deep Learning Models
Deep Learning Frameworks
TensorFlow TutorialTensorFlow is an open-source machine-learning framework developed by Google. It is written in Python, making it accessible and easy to understand. It is designed to build and train machine learning (ML) and deep learning models. It is highly scalable for both research and production.It supports CPUs
2 min read
Keras TutorialKeras high-level neural networks APIs that provide easy and efficient design and training of deep learning models. It is built on top of powerful frameworks like TensorFlow, making it both highly flexible and accessible. Keras has a simple and user-friendly interface, making it ideal for both beginn
3 min read
PyTorch TutorialPyTorch is an open-source deep learning framework designed to simplify the process of building neural networks and machine learning models. With its dynamic computation graph, PyTorch allows developers to modify the networkâs behavior in real-time, making it an excellent choice for both beginners an
7 min read
Caffe : Deep Learning FrameworkCaffe (Convolutional Architecture for Fast Feature Embedding) is an open-source deep learning framework developed by the Berkeley Vision and Learning Center (BVLC) to assist developers in creating, training, testing, and deploying deep neural networks. It provides a valuable medium for enhancing com
8 min read
Apache MXNet: The Scalable and Flexible Deep Learning FrameworkIn the ever-evolving landscape of artificial intelligence and deep learning, selecting the right framework for building and deploying models is crucial for performance, scalability, and ease of development. Apache MXNet, an open-source deep learning framework, stands out by offering flexibility, sca
6 min read
Theano in PythonTheano is a Python library that allows us to evaluate mathematical operations including multi-dimensional arrays efficiently. It is mostly used in building Deep Learning Projects. Theano works way faster on the Graphics Processing Unit (GPU) rather than on the CPU. This article will help you to unde
4 min read
Model Evaluation
Deep Learning Projects