# Gradient descent function question

**URL:** <https://community.deeplearning.ai/t/gradient-descent-function-question/156685>\
**Category:** Supervised ML: Regression and Classification\
**Tags:** week-module-2\
**Created:** [July 7, 2022, 3:31am UTC](https://community.deeplearning.ai/t/gradient-descent-function-question/156685 "2022-07-07T03:31:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pedro\_Gutierrez](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@Pedro\_Gutierrez](https://community.deeplearning.ai/u/Pedro_Gutierrez)\
**Post date:** [July 7, 2022, 3:31am UTC](https://community.deeplearning.ai/t/gradient-descent-function-question/156685/1 "2022-07-07T03:31:48Z")

</div>

Hello,

The following function is generating issues to my understanding. This is where im having the most trouble.

 ![Screen Shot 2022-07-06 at 22.19.06](https://global.discourse-cdn.com/dlai/original/3X/e/3/e3c7d46e0b7970784bdb90343e2df565e19ae1c9.jpeg)  
 ![Screen Shot 2022-07-06 at 22.29.42](https://global.discourse-cdn.com/dlai/original/3X/6/c/6c4b943d7c1acaa80bc64b2e3c9b6867cb8c0abf.jpeg)

As soon as `gradient_descent` function is called, the for loop will iterate over the number of iterations passed to the range function, in this case 1,500. But I don’t understand where the arrows are pointing.

1. What is the `gradient_function` argument doing?

2. What is the `cost_function` argument doing?

Are these two arguments calling another function with global variables such as (x, y) and local variables such as (w, b), and the assigning those to the different variables? or I am missing something else.

Thank you, and I hope you understand.

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [July 7, 2022, 5:03am UTC](https://community.deeplearning.ai/t/gradient-descent-function-question/156685/2 "2022-07-07T05:03:13Z")

</div>

The gradient\_function() computes the gradients using the training set and the current values for the weights and bias. Its return values are the gradients.

The cost\_function() computes the cost for the training set with the updated weights and bias. Its return value is the cost, which is used to create the cost history.

None of x, y, w, or b are global variables.

---

<div class="post-metadata">

**Author:** ![viveksharma](https://avatars.discourse-cdn.com/v4/letter/v/a698b9/32.png) [@viveksharma](https://community.deeplearning.ai/u/viveksharma)\
**Post date:** [July 7, 2022, 6:17am UTC](https://community.deeplearning.ai/t/gradient-descent-function-question/156685/3 "2022-07-07T06:17:36Z")

</div>

As you rightly noted, when the **gradient\_descent** function is _called_, we pass **compute\_cost** and **compute\_gradient** arguments. These are the name of the global function we have already defined earlier in the notebook.

Now in the _definition_ of the function, the arguments **cost\_function** and **gradient\_function** act as a pointer to the function whose name was passed when the function was called. So the argument **cost\_function** basically points to the global function **compute\_cost** , and the argument **gradient\_function** points to the global function **compute\_gradient**. So when inside the function **gradient\_descent** , we call **gradient\_function** or **cost\_function** , we are essentially calling the global **compute\_cost** and **compute\_gradient** functions respectively.

We could have used any other meaningful name as well instead of cost\_function and gradient\_function.

---

<div class="post-metadata">

**Author:** ![Pedro\_Gutierrez](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@Pedro\_Gutierrez](https://community.deeplearning.ai/u/Pedro_Gutierrez)\
**Post date:** [July 7, 2022, 6:33pm UTC](https://community.deeplearning.ai/t/gradient-descent-function-question/156685/4 "2022-07-07T18:33:10Z")

</div>

Thanks for the reply!

---

<div class="post-metadata">

**Author:** ![Pedro\_Gutierrez](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@Pedro\_Gutierrez](https://community.deeplearning.ai/u/Pedro_Gutierrez)\
**Post date:** [July 7, 2022, 6:35pm UTC](https://community.deeplearning.ai/t/gradient-descent-function-question/156685/5 "2022-07-07T18:35:58Z")

</div>

Thanks for the clarification!
