什么是激活?
在一个简单的层次上,激活函数有助于决定神经元是否应该被激活。这有助于确定神经元接收的信息是否与输入相关。激活函数是在输入信号上发生的非线性变换,并且变换后的输出被发送到下一个神经元。
用法
使用激活的推荐方法是在你的神经网络中添加激活层,并配置所需的激活:
GraphBuilder graphBuilder = new NeuralNetConfiguration.Builder()
// 添加超参数和其他层
.addLayer("softmax", new ActivationLayer(Activation.SOFTMAX), "previous_input")
// 添加更多的层和输出
.build();
可用的激活
ActivationSoftSign
f_i(x) = x_i / (1+x_i)
ActivationCube
f(x) = x^3
ActivationRectifiedTanh
整流正切
本质上是 max(0, tanh(x))
底层实现是在本地代码中
ActivationThresholdedReLU
门槛的 RELU
f(x) = x for x > theta, f(x) = 0 otherwise. theta defaults to 1.0
ActivationIdentity
f(x) = x
ActivationReLU6
f(x) = min(max(input, cutoff), 6)
ActivationPReLU
参数化整流线性单元 (PReLU)
f(x) = alpha x 对于 x < 0, f(x) = x 对于 x >= 0
Alpha的形状与X相同,是一个学习得来的参数。
ActivationSoftmax
f_i(x) = exp(x_i - shift) / sum_j exp(x_j - shift) where shift = max_i(x_i)
ActivationSwish
f(x) = x sigmoid(x)
ActivationTanH
f(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
ActivationSoftPlus
f(x) = log(1+e^x)
ActivationHardSigmoid
f(x) = min(1, max(0, 0.2x + 0.5))
ActivationRReLU
f(x) = max(0,x) + alpha min(0, x)
alpha在训练期间从uniform(l,u)中提取,在测试L中被设为 l+u/2,I和U默认为1/8和1/3。
ActivationReLU
f(x) = max(0, x)
ActivationHardTanH
⎧ 1, if x > 1 f(x) = ⎨ -1, if x < -1 ⎩ x, otherwise
ActivationRationalTanh
来自 https://arxiv.org/pdf/1508.01292v3 理性正切近似
f(x) = 1.7159 tanh(2x/3) 正切是如下近似 tanh(y) ~ sgn(y) { 1 - 1/(1+|y|+y^2+1.41645y^4)}
底层实现是在本地代码中
ActivationSELU
https://arxiv.org/pdf/1706.02515.pdf
ActivationELU
f(x) = alpha (exp(x) - 1.0); x < 0 = x ; x>= 0
如果没有指定 alpha 默认为 1
ActivationSigmoid
f(x) = 1 / (1 + exp(-x))
ActivationLReLU
Leaky RELU f(x) = max(0, x) + alpha min(0, x) alpha 默认为 0.01