1、阈值激活函数,最简单的激活函数,神经元的输入大于0则为1(激活状态),小于0则为0(抑制状态),这个激活函数意义不大,例如使用梯度下降法的时候,它不能求导,因此它无法对网络参数进行有限的训练。
#Author:ZhenhuaLiu HIT-atci
#date:2021.6.26 19:24
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
def threshold(x):
cond = tf.less(x,tf.zeros(tf.shape(x), dtype = x.dtype))
out = tf.where(cond, tf.zeros(tf.shape(x)),tf.ones(tf.shape(x)))
return out
#plotting Threshold Activation Function
h = np.linspace(-1,1,50)
out = threshold(h)
#init = tf.global_variables_initializer()
with tf.Session() as sess:
#sess.run(init)
y=sess.run(out)
plt.xlabel('Activity of Neuron')
plt.ylabel('Output of Neuron')
plt.title('Threshold Activation Function')
plt.plot(h,y)
plt.show()