The result of gradient descent algorithm is a vector. So how does this algorithm decide the direction for weight change? We Give hyperparameters for step size. But how is the vector direction for weight change, for the purpose of reducing the Loss function in a Linear Regression Model, determined by this algorithm?

  • $\begingroup$ Welcome to AI.se...The question requires an answer of conceptual nature which can be too lengthy, i have provided a few links in my answer, but I suggest you to explore the internet for an even better understanding of why gradient descent actually works. $\endgroup$
    – user9947
    Mar 14, 2018 at 8:12

2 Answers 2


First thing is that what does gradient descent do? Gradient Descent is a tool of calculus which we use to determine the parameters (here weights) used in a Machine Learning algorithm or a Neural Network, by running the Gradient Descent algorithm iteratively.

What does the vector obtained from one iteration of gradient descent tell us? It tells us the direction of weight change (when weights are treated as a vector) for the maximum reduction in the value outputted by a loss function. The intuition behind why Gradient Descent gives such a direction can be found here:

In general cases the cost/loss function is an n-dimensional paraboloid (we design function in such a way such that its convex).

enter image description here

A 2-D paraboloid with x and y as independent variables.

Now why do we reduce the weights in the direction of negative gradient only? Why not some other direction?

Since we want to reduce the cost in Linear Regression for better predictions we choose only the negative Gradient Descent direction, as it is the direction of steepest descent even though we could have chosen some other possible vector direction to reduce cost, but the negative gradient descent direction ensures that:

  • Cost is always decreased (if the step size is correct and in general only in cases of convex functions e.g paraboloid).
  • Cost is decreased by the maximal amount if we move in that direction, so we don't have to worry whether cost will decrease or not if we move in that direction.

Also we use learning rate alpha to scale by how much amount we want to decrease the weights.

EDIT: As pointed by @pasaba the error function may not be a paraboloid but in general a good cost function looks like a paraboloid with skewed axis.

  • $\begingroup$ @pasabaporaqui activation function is not the same as loss function..the equation of mse is equation of a paraboloid $\endgroup$
    – user9947
    Mar 16, 2018 at 9:02
  • $\begingroup$ MSE is a parabola if the output of the net is taken as MSE argument, E(y), something useless in optimization of a NN. When working on optimization, the arguments to be taken into account are the weights and offsets, E( w_0, w_1, ... ), that is not a parabola, even if measured as MSE. By example, when activation function is sigmoid, It is more near to a superposition of continuous approximations of Heaviside functions. $\endgroup$ Mar 16, 2018 at 9:29
  • $\begingroup$ @pasabaporaqui i plotted the log cost function used in sigmoids and for 1 part I got 1 part of parabola on +ve x-axis and the other part gave me 2nd side of parabola on the negative x-axis....well not exactly parabola, but looked close to it....so I thought to say that cost functions are generally parabolid $\endgroup$
    – user9947
    Mar 16, 2018 at 9:39
  • $\begingroup$ Added an answer with graphics below $\endgroup$ Mar 16, 2018 at 10:17

We can analyze a basic common example: approximation of AND logic gate by a NN.

The inputs to the NN will be "x1" and "x2" and its output is "y". The data to be learned by the NN is:

enter image description here

The basic NN has one intermediate cell with activation function sigmoid and one output cell identity function. That means:

enter image description here

(note by symmetry we assume w1=w2)

Then, the error is:

enter image description here

These are some plots of this function:

enter image description here enter image description here enter image description here

And this is the w derivate of e :

enter image description here

Sage Math code (link) for this graph:

plot3d(e(w,b),(w,-5,5),(b,-5,5),adaptive=True, color=rainbow(60, 'rgbtuple'))

plot3d(edw(w,b),(w,-5,5),(b,-5,5),adaptive=True, color=rainbow(60, 'rgbtuple'))

(PS: please, activate latex on this stack exchange).

  • $\begingroup$ Uh huh I never said mse for sigmoid is convex....I said the log error for sigmoid is convex, kind of paraboloid looking $\endgroup$
    – user9947
    Mar 16, 2018 at 10:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .