Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use Jupyter notebook First define a function gradient_descent(func, func_grad, xe, step_size, step_nun) to inploment the gradient descent method we have learned in lecture. Feel

Please use Jupyter notebook
image text in transcribed
image text in transcribed
First define a function gradient_descent(func, func_grad, xe, step_size, step_nun) to inploment the gradient descent method we have learned in lecture. Feel free to set default values in the function whenver you think is approptiate. Requirements: - the output of the function is a dictionary. The key "mininizer" correspdonds to x value where the algonithm stops, the key 4 - values" is a numpy array of length (step_size+1) corresponds to history of objective function values during the iteration (including the value at initial xo as first element), and the key "X_. history" is a n (dimension of x ) =by (step_size +1 ) matrix, whose columns store all the obtained x during iteration (including the initial x0 ) - write a detalled documentation string to your function, which at least contains the description about input and output. You may consult here for a great example on format (from line 39 to 252, though we don't such a high expectation here), or ask chatgpt for a hint or generate it for you. - your function should work for any dimensions (not only singleverariable) M in define function here Then display its documentation string using help function, and test on the exampie f(x1,x2,x1)=x12+0.5x22+2x32+2 with initial value xen Ap, array ([1,1,1]), hint you may try to choose parameter step_size and step_num approptiately in testing to get correct result. H = your code here In machine learning. momentum method is indeed more widely used than GD to speed up convergence. it ileration step could be whitten as y+1=y+f(x)x+1=x2y+1 here y is generally called "velocity", and is another called momentum coefficient or momentum step size (value usually from 0 to 1 , and the latger it is, the more differeat with GD). Here y could be initiolized as all-zero vector when start doing the interabion. In the code below, dofine the function momentum(func, func _grad, x, step_size, step_size momentum, step_num) bo implement the momentum method. All requirements are the same with the GD function except that here we have an additional input step.size.momentum representing the in equation. Lastly, use momentum method to redo the example above, keeping step_size and xe same as GD. Piot the function values of f(x1. x2, x3) vs iteration step for the two methods in a same figure using matolotib. Specific requirements: - the figure needs to have axis labels with appropraite strings. - display a figure legend to distinguish the two lineplots of momentum and sGD Alt function you need to plot could be found in this futorial. Then, write down your observation using markdown cell. 1: M

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions