Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)
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_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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

5. If yes, then why?

Answered: 1 week ago

Question

6. How would you design your ideal position?

Answered: 1 week ago