本文共 655 字,大约阅读时间需要 2 分钟。
常用激活函数
import theanofrom keras import backend as Kimport keras.activations as A#from pylab import *x = theano.tensor.dmatrix()softmax = theano.function([x], A.softmax(x))softplus = theano.function([x], A.softplus(x))relu = theano.function([x], A.relu(x))tanh = theano.function([x], A.tanh(x))sigmoid = theano.function([x], A.sigmoid(x))hard_sigmoid = theano.function([x], A.hard_sigmoid(x))linear = theano.function([x], A.linear(x))xv = np.array([range(-20, 20)])for i, fn in enumerate(["softmax", "softplus", "relu", "tanh", "sigmoid", "hard_sigmoid", "linear"]): plt.subplot(3, 3, i + 1) plt.title(fn) plt.plot(xv[0], eval(fn)(xv)[0])plt.show()