Part of list:

Gradient Descent, an intuitive introduction

- Introduction and Overview
- Equations and formulas
- Pseudocode
- Intuition for Gradient Descent
- Variants of Gradient Descent
- Choosing the learning rate
- Footnote

Gradient Descent, an intuitive introduction[ Edit ]

**Gradient Descent** is one of the most popular and widely used **optimization algorithm**. Given a machine learning model with parameters (weights and biases) and a cost function to evaluate how good a particular model is, our learning problem reduces to that of finding a good set of weights for our model which minimizes the cost function.

Gradient descent is an **iterative method**. We start some value for our model parameters (weights and biases), and improve them slowly. To improve a given set of weights, we try to get a sense of the value of the cost function for weights similar to the current weights (by calculating the gradient) and move in the direction in which the cost function reduces. By repeat this step thousands of times we'll continually minimize our cost function.

Gradient descent is used to minimize a *cost function* *J*(* w*) parameterized by a

Let G be the gradient of the cost function with respect to the parameters at a particular value *w* of the weight vector. That is,

G = \nabla_w J(w)

Then, the gradient descent step is given by

w = w - \eta \cdot G

Here, η is the **learning rate** which determines the size of the steps we take to reach a minimum [1]. We need to be very careful about this parameter since high values of η may overshoot the minimum and very low value will reach minimum very slowly.

**initialize**the weights*w*randomly**calculate the gradients**G of cost function w.r.t parameters**update the weights**by an amount proportional to G, i.e.*w*=*w*- ηG- repeat till
*J*(*w*) stops reducing or other pre-defined**termination criteria**is met

Imagine you're *blind folded *in a rough terrain, and your objective is to reach the *lowest altitude*. One of the simplest strategies you can use, is to *feel the ground in every direction, and take a step in the direction where the ground is descending* the fastest. If you keep repeating this process, you might end up at the lake, or even better, somewhere in the huge valley.

Source: Video clip of Andrej Karpathy's Stanford course lecture 3

The rough terrain is analogous to the cost function. Minimizing the cost function is analogous to trying to reach lower altitudes. You are blind folded, since we don't have the luxury of evaluating (seeing) the value of the function for every possible set of parameters. Feeling the slope of the terrain around you is analogous to calculating the gradient, and taking a step is analogous to one iteration of update to the parameters.

There are multiple variants of gradient descent depending on how much of the data is being used to calculate the gradient. The main reason behind these variations is computational efficiency. A dataset may have millions of data points, and calculating the gradient over the entire dataset can be computational expensive.

**Batch gradient descent**computes the gradient of the cost function w.r.t to parameter w for**entire training data**. Since we need to calculate the gradients for the whole dataset to perform one parameter update, batch gradient descent can be very slow.**Stochastic gradient descent (SGD)**computes the gradient for each training example*x*. i.e. a^{i}**single training data point**is used for each update.- In
**mini-batch gradient descent**, we calculate the gradient for each small mini-batch of training data. That is, we first divide the training data into small batches (say M samples / batch). We perform one update per mini-batch. M is usually in the range 30-500, depending on the problem.

Of these, stochastic GD and mini-batch GD are most popular. Usually mini-batch GD is used because computing infrastructure (compilers, CPUs, GPUs) is often optimized for performing vector additions and vector multiplications.

There are some challenges with aforementioned gradient descent algorithms such as choosing a proper learning rate. It's typical to choose a small value such as 0.1, 0.01 or 0.001 and adapt it based on whether the cost function is reducing very slowly (increase learning rate) or is exploding / being erratic (decrease learning rate).

Although manually choosing a learning rate is still the most common practice, several methods such as adam optimizer, AdaGrad and RMSProp have been proposed to automatically choose a suitable learning rate. Suggested further reading for going deeper into this topic: An overview of gradient descent optimization algorithms.

- The value of the gradient depends on the cost function and the inputs, and you might need to revisit the topic of differentiation if you are calculating them by hand. It is common for machine learning software libraries to calculate the gradients automatically once the cost function is specified. However, if one is implementing a novel machine learning algorithm and applying the gradient descent optimization technique on it, it is important to have at-least a rough idea of what the gradients look like in-order to make sure that the method works as desired and does not get stuck / behave erratically.

Read more…(880 words)

Mark as completed

Part of lists:

Previous

Linear Regression Tutorial with Example

Next

Overfitting, Cross Validation and Regularization

About the contributors:

Keshav DhandhaniaMSc in Deep Learning @ MIT (2014)

70%

Savan VisalparaMachine Learning Practitioner

30%

Loading…

Have a question? Ask here…

Post

Part of list:

Gradient Descent, an intuitive introduction

- Introduction and Overview
- Equations and formulas
- Pseudocode
- Intuition for Gradient Descent
- Variants of Gradient Descent
- Choosing the learning rate
- Footnote

Contributors

Keshav DhandhaniaMSc in Deep Learning @ MIT (2014)

70%

Savan VisalparaMachine Learning Practitioner

30%

Ready to join our community?

Sign up below to automatically get notified of new lists, get **reminders** to finish ones you subscribe to, and **bookmark** articles to read later.

Continue with Facebook

— OR —

Your Full Name

Email address

I have an account. Log in instead

By signing up, you agree to our Terms and our Privacy Policy.