Answered step by step
Verified Expert Solution
Link Copied!

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 f(x):
return x**2+ np.exp(x)-4
def gradient_f(x):
return #FILL IN
############################################
def plot_live(ax, x, y):
ax.plot(x, y, linestyle=':', marker='o', markersize=8, color='blue', alpha=0.3)
print('w ={:.4f} f(w)={:.4f}'.format(x,y))
plt.pause(1)
def gradient_descent(w_init, step_size, n_iter=100, tolerance=1e-04, ax=None):
w = w_init
itr =0
while(itr n_iter):
if ax:
plot_live(ax, w, f(w))
### FILL IN ###############################
gradient = #FILL IN
diff = #FILL IN
w -= #FILL IN
###########################################
stop_criterion = np.abs(diff)
if np.all(stop_criterion = tolerance):
if ax:
plot_live(ax, w, f(w))
print('converged...')
break
itr +=1
if f(w)>1e+8:
print('diverged...')
break
return w
if __name__=="__main__":
fig, ax = plt.subplots()
w_min =-4.1
w_max =4.1
w = np.linspace(w_min, w_max, 1000)
ax.plot(w, f(w), linestyle='-', color='black')
ax.set_ylabel('f(w)', fontsize=15)
ax.set_xlabel('w', fontsize=15)
ax.grid()
ax.set_xlim([np.min(w), np.max(w)])
ax.set_ylim([-10, np.max(f(w))*1.1])
gradient_descent(w_init=-4, step_size=0.1, n_iter=100, tolerance=1e-04, ax=ax)
plt.show()
image text in transcribed

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

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

Explain the need for evaluating test adequacy.

Answered: 1 week ago

Question

6. What are some of the advantages and disadvantages of ESOPs?

Answered: 1 week ago