Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please fill in the question marks and DO NOT ALTER / DELETE EXISTING CODE OR ADD ANY NEW LINES OF CODE!!!!!!!!!: # Define the activation

Please fill in the question marks and DO NOT ALTER/DELETE EXISTING CODE OR ADD ANY NEW LINES OF CODE!!!!!!!!!: # Define the activation function.
sigma = np.tanh
# Let's use a random initial weight and bias.
W = np.array([[-0.94529712,-0.2667356,-0.91219181],
[2.05529992,1.21797092,0.22914497]])
b = np.array([0.61273249,1.6422662])
# define our feed forward function
def a1(a0) :
# Notice the next line is almost the same as previously,
# except we are using matrix multiplication rather than scalar multiplication
z = np.dot(W, a0)+ b
# Everything else is the same though,
return sigma(z)
# Next, if a training example is,
x = np.array([0.7,0.6,0.2])
y = np.array([0.9,0.6])
# Then the cost function is,
d = a1(x)- y # Vector difference between observed and expected activation
C = np.sum(d **2) # Absolute value squared of the difference.
sigma = np.tanh
# Next define the feed-forward equation.
def a1(w1, b1, a0) :
z = np.dot(w, a0)+ b
return sigma(z)
# This function returns the derivative of the cost function with
# respect to the weight.
def dCdw (w1, a, b1, x, y) :
a = al(wl, bl, x)
dCda =(a - y) # Derivative of cost with activation
dadz =1- np.tanh(a)**2 # derivative of activation with weighted sum z
J = dCda * dadz
dzdw = x # derivative of weighted sum z with weight
J = dCda * dadz
return J # Return the chain rule product.
# This function returns the derivative of the cost function with
# respect to the bias.
# It is very similar to the previous function.
# You should complete this function.
def dCdb (w1, b, x, y) :
dCda =(a - y)
dadz =1- np.tanh(a)**2
# Change the next line to give the derivative of
# the weighted sum, z, with respect to the bias, b.
dzdb =1
return dCda * dadz * dzdb
#the code must work with this statement: dCdb (W, b, x, y)
array([[-2.19184549e+00],
[1.42277240e-03]])
dCdw (W, b, x, y)
array([[-1.53429185e+00,-1.31510730e+00,-4.38369099e-01],
[9.95940681e-04,8.53663441e-04,2.84554480e-04]]). PLEASE ENSURE THERE ARE NO ERRORS SUCH AS : NameError: name 'a' is not defined.

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_2

Step: 3

blur-text-image_3

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

a. What department offers the course?

Answered: 1 week ago

Question

Determine miller indices of plane X z 2/3 90% a/3

Answered: 1 week ago