Question: Consider the following Gradient Descent Algorithm that written in Python programming language: x = 2 # The algorithm starts at x = 2 r =

Consider the following Gradient Descent Algorithm that written in Python programming
language:
x =2 # The algorithm starts at x=2
r =0.01 # Learning rate
p =0.000001 # The precision at which the algorithm should be stopped
before_step_size =1 #
i_max =1000 # Maximum number of iterations
i =0 #iteration counter
df = lambda x: 2*(x+3) #Gradient (First derivative) of our function
while before_step_size > p and i i_max:
x_old = x # Stores the current value of x in x_old
x = x - r * df(x_old) # Gradient descent
before_step_size = abs(x - x_old) #Difference between consecutive iterations
i = i+1 #Iteration increasing with every loop
print("Iteration", i,"
X value is", x)
print("The local minimum of the given function occurs at", x)
Apply the matplotlib or seaborn plotting library/module to visualize the output of this
algorithm/program.
Consider the following Gradient Descent Algorithm

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!