Hi, I had the same question as tamalmallick. I think based on your response I am starting to understand that the final call of gradient_descent( ) does use the def functions compute_cost and compute_gradient.
Why use the pointers cost_function and gradient_function when defining gradient_descent? Couldn’t the lab have inputed compute_cost and compute_gradient directly?
Yes, they could have just called those functions directly, but they are just showing you a way to write more flexible “general” code in python. In python you can pass references to functions as parameters to your functions. So they have written a general gradient_descent function that can be used with different cost functions.
For example, suppose that you were considering two different cost functions for a given problem. With the code they wrote, you would only have to write the gradient descent logic once and then you could try both cost functions and compare the results.
Of course note that the compute_gradient function will be paired with the compute_cost function. If you use a different cost function, then the gradient values will be driven by that algorithm.
For me it was also rather confusing at the beginning. I know it´s more general, but back then I need something more understandable. Here is some code I simplify for myself for better understanding (and I also remove J, it´s nice to see but I am a beginner here, so the smaller the code is that does something, the more understandable it is)