Answered step by step
Verified Expert Solution
Question
1 Approved Answer
solve abcd this is for QC QD import numpy as np import matplotlib.pyplot as plt ### Fill in ################################ def f ( x ) :
solve abcd this is for QC QD import numpy as np import matplotlib.pyplot as plt ### Fill in ################################ def fx: return x npexpx def gradientfx: return #FILL IN ############################################ def plotliveax x y: axplotx y linestyle: markero markersize color'blue', alpha printw :f fw:fformatxy pltpause def gradientdescentwinit, stepsize, niter tolerancee axNone: w winit itr whileitr niter: if ax: plotliveax w fw ### FILL IN ############################### gradient #FILL IN diff #FILL IN w #FILL IN ########################################### stopcriterion npabsdiff if npallstopcriterion tolerance: if ax: plotliveax w fw printconverged break itr if fwe: printdiverged break return w if namemain: fig, ax pltsubplots wmin wmax w nplinspacewmin, wmax, axplotw fw linestyle color'black' axsetylabelfw fontsize axsetxlabelw fontsize axgrid axsetxlimnpminw npmaxw axsetylim npmaxfw gradientdescentwinit stepsize niter tolerancee axax pltshow
solve abcd
this is for QC QD
import numpy as np
import matplotlib.pyplot as plt
### Fill in ################################
def fx:
return x npexpx
def gradientfx:
return #FILL IN
############################################
def plotliveax x y:
axplotx y linestyle: markero markersize color'blue', alpha
printw :f fw:fformatxy
pltpause
def gradientdescentwinit, stepsize, niter tolerancee axNone:
w winit
itr
whileitr niter:
if ax:
plotliveax w fw
### FILL IN ###############################
gradient #FILL IN
diff #FILL IN
w #FILL IN
###########################################
stopcriterion npabsdiff
if npallstopcriterion tolerance:
if ax:
plotliveax w fw
printconverged
break
itr
if fwe:
printdiverged
break
return w
if namemain:
fig, ax pltsubplots
wmin
wmax
w nplinspacewmin, wmax,
axplotw fw linestyle color'black'
axsetylabelfw fontsize
axsetxlabelw fontsize
axgrid
axsetxlimnpminw npmaxw
axsetylim npmaxfw
gradientdescentwinit stepsize niter tolerancee axax
pltshow
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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