Question: Q 3 ( 2 0 points ) 5 . 0 . 1 . Calculate the gradient of f with respect to x and y using

Q3(20 points)
5.0.1. Calculate the gradient of f with respect to x and y using the backpropagation
algorithm
5.0.2. Calculate the gradient of f with respect to x and y using the computation graph in
tensorflow
f(x,y)=x3+y4(x+y)2
Declare intermediate variables, q1=x3,q2=y4,q=q1+q2 and so on. Remember to use is needed when x is used in
multiple paths of the computation), similarly dfdy.
##code:
import sys
from packaging import version
import sklearn
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from sklearn.preprocessing import add_dummy_feature
from sklearn.datasets import make_blobs
from sklearn import metrics #Import scikit-learn metrics module for accuracy calculation
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
from sklearn.datasets import make_classification
print("Sklearn package",sys.version_info)
print("Sklearn package",sklearn.__version__)
print("TensorFlow version:", tf.__version__)
assert sys.version_info >=(3,7)
assert version.parse(sklearn.__version__)>= version.parse("1.0.1")
plt.rc('font', size=12)
plt.rc('axes', labelsize=14, titlesize=14)
plt.rc('legend', fontsize=14)
plt.rc('xtick', labelsize=10)
plt.rc('ytick', labelsize=10)
##
x =2
y =5
#Forward pass
#Backward pass
#print(f)
#print(dfdx,dfdy)
#f =12.918367346938776
#dfdx =-3.4460641399416914
#dfdy =6.513119533527696
##
#using computation graph from tensorflow
x = tf.Variable(2.)
y = tf.Variable(5.)
#print(f)
#print(grad_x,grad_y)
 Q3(20 points) 5.0.1. Calculate the gradient of f with respect to

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!