In [9]:
import tensorflow as tf
import numpy as np
In [14]:
#help(tf.nn.softmax)
#help(tf.multiply)
help(tf.log)
In [32]:
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
mTest=2
nTest=3
aTest=np.random.random([mTest,nTest])
bTest=np.random.random([mTest,nTest])
#bTest=aTest
aTestSoftmax=tf.nn.softmax(aTest)
bTestSoftmax=tf.nn.softmax(bTest)
costFunc=-aTestSoftmax*tf.log(bTestSoftmax)
sumCostFunc=tf.reduce_sum(costFunc)
init=tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
aSoft=sess.run(aTestSoftmax)
bSoft=sess.run(bTestSoftmax)
cFunc=sess.run(costFunc)
sCostFunc=sess.run(sumCostFunc)
print('------------- aSoft --------------')
print aSoft
print('------------- bSoft --------------')
print bSoft
print('------------- cFunc --------------')
print cFunc
print('------------- sCostFunc --------------')
print sCostFunc
print np.sum(cFunc)
In [22]:
import numpy as np
import matplotlib.pyplot as plt
p=np.linspace(1e-9,1-1e-9,100)
logP=-p*np.log2(p)
q=1-p
logQ=-q*np.log2(q)
#print p
#print(np.log2(p))
#print logP
plt.figure(1)
plt.hold
plt.plot(p,logP,'b')
plt.plot(p,logQ,'r')
plt.plot(p,logP+logQ,'g')
plt.grid('on')
plt.show()
In [27]:
import numpy as np
import matplotlib.pyplot as plt
p=np.linspace(1e-9,1-1e-9,100)
logP=-p*np.log(p)
q=1-p
logQ=-q*np.log(q)
#print p
#print(np.log2(p))
#print logP
plt.figure(1)
plt.hold
plt.plot(p,logP,'b')
plt.plot(p,logQ,'r')
plt.plot(p,logP+logQ,'g')
plt.grid('on')
plt.show()
In [80]:
print -np.log2(0.1)
In [81]:
print(-(0.1*np.log2(0.1)+0.9*np.log2(0.9)))
In [82]:
print(-(0.5*np.log2(0.5)+0.5*np.log2(0.5)))
In [86]:
tf.log(tf.constant([2.]))
Out[86]:
In [ ]: