Below are the solutions to these exercises on Tensorflow Basics.
#################### # # # Exercise 1 # # # #################### input_1 <- tf$placeholder(tf$float32, name='input_1') input_2 <- tf$placeholder(tf$float32, name='input_2') #################### # # # Exercise 2 # # # #################### with(tf$Session() %as% sess, { print(sess$run(c(input_1, input_2), feed_dict=dict(input_1 = 7.0, input_2 = 2.0))) })
## [[1]] ## [1] 7 ## ## [[2]] ## [1] 2
#################### # # # Exercise 3 # # # #################### mult = tf$multiply(input_1, input_2, name='mult') #################### # # # Exercise 4 # # # #################### with(tf$Session() %as% sess, { print(sess$run(mult, feed_dict=dict(input_1 = 2.5, input_2 = 0.1))) })
## [1] 0.25
#################### # # # Exercise 5 # # # #################### input_3 <- tf$placeholder(tf$float32, name='input_3') add = tf$add(mult, input_3, name='add') #################### # # # Exercise 6 # # # #################### with(tf$Session() %as% sess, { print(sess$run(mult, feed_dict=dict(input_1 = 1.2, input_2 = 0.1, input_3 = 2.9))) })
## [1] 0.12
#################### # # # Exercise 7 # # # #################### X <- tf$placeholder(tf$float32, name='X') W <- tf$Variable(tf$random_uniform(shape(1L), -1.0, 1.0)) #################### # # # Exercise 8 # # # #################### alpha <- tf$multiply(X, W, name = "alpha") #################### # # # Exercise 9 # # # #################### b <- tf$Variable(tf$zeros(shape(1L))) y <- tf$add(alpha, b, name = "y") #################### # # # Exercise 10 # # # #################### x_data <- runif(100, min=0, max=1) sess = tf$Session() sess$run(tf$global_variables_initializer()) print(sess$run(y, feed_dict=dict(X = x_data[50])))
## [1] 0.1266156
Leave a Reply