神经网络的常用激活函数
激活函数
Sigmoid
曲线图如下:
实现方法:
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
#定义x的取值范围
x = np.linspace(-10,10,100)
#直接使用tensorflow实现
y = tf.nn.sigmoid(x)
#绘图
plt.plot(x,y)
plt.grid()
plt.show()
Tanh(双曲正切曲线)
实现方法:
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
#定义x的取值范围
x = np.linspace(-10,10,100)
#直接使用tensorflow实现
y = tf.nn.tanh(x)
#绘图
plt.plot(x,y)
plt.grid()
plt.show()
RELU
实现方法:
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
#定义x的取值范围
x = np.linspace(-10,10,100)
#直接使用tensorflow实现
y = tf.nn.relu(x)
#绘图
plt.plot(x,y)
plt.grid()
plt.show()
LeakyRelu
实现方法:
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
#定义x的取值范围
x = np.linspace(-10,10,100)
#直接使用tensorflow实现
y = tf.nn.leaky_relu(x)
#绘图
plt.plot(x,y)
plt.grid()
plt.show()
softmax
实现方法:
import tensorflow as tf
import matplotlib.pyplot as plt
x = tf.constant([0.2,0.02,0.15,1.3,0.5,0.06,1.1,0.05,3.75])
y = tf.nn.softmax(x)
plt.plot(x,y)
plt.grid()
plt.show()
原文地址:https://blog.csdn.net/weixin_51787442/article/details/140471191
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!