Question
Use gradient descent with a learning rate of 0.01. to find the local minima of the function y=(2x+5) starting from the point x=3. At each
Use gradient descent with a learning rate of 0.01. to find the local minima of the function y=(2x+5) starting from the point x=3.
At each step show the point (x, y), the value of the gradient.
Use the following code snippet to get started.
cur_x = 3 rate = 0.01 # Learning rate precision = 0.0000001 #This tells us when to stop the algorithm max_iters = 10000 # maximum number of iterations iters = 0 #iteration counter
cur_x = 3
while iters < max_iters: prev_x= cur_x
cur_x = cur_x - rate * grad(prev_x) #grad returns the gradient
iters = iters+1 #iteration count
Change the code to introduce a required precision. That is to stop when the difference between two consecutive iterations is less than the given precision parameter.
Now use a different function that has local and global minima and experiment with different starting points.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started