In [10]:
#USN:01FE15BCS237
#Roll:244
#lAB2_Assignment_2

import tensorflow as tf
import matplotlib.pyplot as plt

a = tf.constant([10.0,11.0,12.0,13.0,14.0,15.0,16.0],name ='x')
b = tf.constant([8.0,9.0,10.0,11.0,12.0,13.0,14.0],name='y')
training_epoch = 500
learning_rate = 0.005
t1=0.0
t0=0.0


#h0 calculation
h0=tf.divide(1.0,tf.add(1.0,tf.exp(-tf.add(t0,tf.reduce_sum(tf.multiply(t1,a))))))

model=tf.global_variables_initializer()
sess = tf.Session() 
print("h0 values:",sess.run(h0))
c=tf.cond(h0<0.5,lambda:0.00,lambda:1.00)
print(sess.run(c))


#cost function
v=tf.multiply(b,tf.log(c))
n=tf.subtract(1.0,b)
m=tf.log(tf.subtract(1.0,c))
m1=tf.multiply(n,m)
m2=tf.reduce_sum(tf.subtract(-v,m1))
print("Cost function:",sess.run(m2))

for epoch in range(training_epoch):
    
       #For 500 epoch values
    s1=tf.reduce_sum(tf.multiply(tf.subtract(tf.add(tf.multiply(a,t1),t0),b),a))
    s0=tf.reduce_sum(tf.subtract(tf.add(tf.multiply(a,t1),t0),b))
    tn1 = tf.subtract(t1,tf.multiply(learning_rate,tf.divide(s1,tf.cast(tf.size(a),tf.float32))))
    tn0=  tf.subtract(t0,tf.multiply(learning_rate,tf.divide(s0,tf.cast(tf.size(a),tf.float32))))
    t1=tn1
    t0=tn0
    model=tf.global_variables_initializer()
sess = tf.Session()
print("After 500 epoch values:")
print("theta 1 : ",sess.run(tn1))
print("theta 0 : ",sess.run(tn0))

#Plotting graphs
plt.plot(cost,learning_rate)
plt.show()

plt.plot(cost,training_epoch)
plt.show()


h0 values: 0.5
1.0
Cost function: -inf
After 500 epoch values:
theta 1 :  1.04169
theta 0 :  0.0339648

In [ ]: