In [1]:
import tensorflow as tf
import matplotlib.pyplot as plt

a1 = tf.constant([10.0,12.0,14.0,6.0,8.0,15.0,18.0],name ='x')
b1 = tf.constant([7.0,11.0,11.0,4.0,7.0,13.0,19.0],name='y')
training_epoch = 500
learning_rate = 0.005
stp=50
t1=0.0
t0=0.0

h0=tf.divide(1.0,tf.add(1.0,tf.exp(-tf.add(t0,tf.reduce_sum(tf.multiply(t1,a1))))))
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(b1,tf.log(c))
n=tf.subtract(1.0,b1)
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))

sess = tf.Session()

for epoch in range(training_epoch):
    
                                #if error is greater than threshold value then stop the iteration
    s1=tf.reduce_sum(tf.multiply(tf.subtract(tf.add(tf.multiply(a1,t1),t0),b1),a1))
    s0=tf.reduce_sum(tf.subtract(tf.add(tf.multiply(a1,t1),t0),b1))
    tn1 = tf.subtract(t1,tf.multiply(learning_rate,tf.divide(s1,tf.cast(tf.size(a1),tf.float32))))
    tn0=  tf.subtract(t0,tf.multiply(learning_rate,tf.divide(s0,tf.cast(tf.size(a1),tf.float32))))
    t1=tn1
    t0=tn0
    model=tf.global_variables_initializer()
    if (epoch%stp==0):
        print("W : ",sess.run(tn1),"   b : ",sess.run(tn0))

    

print("After 500 epoch values:")
print("W : ",sess.run(tn1))
print("b : ",sess.run(tn0))


h0 values: 0.5
1.0
Cost function: -inf
W :  0.695    b :  0.0514286
W :  0.894181    b :  -0.0111606
W :  0.899939    b :  -0.0866611
W :  0.905561    b :  -0.160376
W :  0.91105    b :  -0.232347
W :  0.916408    b :  -0.302615
W :  0.921641    b :  -0.371221
W :  0.926749    b :  -0.438205
W :  0.931737    b :  -0.503604
W :  0.936606    b :  -0.567456
After 500 epoch values:
W :  0.941267
b :  -0.628566

In [ ]: