原文标题 :Elliot Activation Function: What Is It and Is It Effective?
Elliot 激活函数:它是什么并且有效吗?
什么是 Elliot 激活函数?它是否可以替代神经网络中使用的其他激活函数?
Introduction
您是否正在创建一个新的机器学习模型并且不确定您应该使用什么激活函数?
但是等等,什么是激活函数?
激活函数允许机器学习模型理解和解决非线性问题。在神经网络中使用激活函数特别有助于将最重要的信息从每个神经元传递到下一个神经元。如今,ReLU 激活函数通常用于神经网络的体系结构中,但这并不一定意味着它始终是最佳选择。 (查看我下面关于 ReLU 和 LReLU 激活的帖子)。
我最近遇到了 Elliot 激活函数,它被誉为可以替代各种激活函数,包括 Sigmoid 和 Hyperbolic Tagenet。今天我们将运行一个实验来测试 Elliot 激活函数的性能。
实验 1:测试 Elliot 激活函数对 Sigmoid 激活函数和双曲正切激活函数的性能。
实验 2:针对 ReLU 激活函数测试 Elliot 激活函数的性能。
目标是回答这个问题:Elliot 激活函数是否有效?
Elliot Activation Function
Elliot 激活函数将导致相对接近 Sigmoid 和双曲正切激活函数的近似值。有些人发现 Elliot 执行计算的速度比 Sigmoid 激活函数快 2 倍 [3]。就像 Sigmoid 激活函数一样,Elliot 激活函数被限制在 0 和 1 之间。
Experiment
问题:Keras 目前在其存储库中没有 Elliot 激活函数。
解决方案:我们可以使用 Keras 后端并自己创建它!
def elliot(x, K=1.0):
return ((.5*x) / (1 + K.abs(x)))
elliot = Activation(elliot)
对于这个实验,让我们看看 Elliot 激活函数与其类似对应函数以及 ReLU 激活函数(当今神经网络中使用的基本激活函数)的比较。
Dataset and Setup
所有 Python 项目的第一步是导入您的包。
import keras.backend as K
from keras.layers import Layer
from keras.layers import Activation
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from keras import layers
from keras import Sequential
今天使用的数据集是鸢尾花数据集,可以在这里找到。该数据集是公开可用的,并允许公众使用(可以选择通过 sklearn 将其加载到 Python 中)。[0]
iris = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data")
# Preprocess the data
X = iris.iloc[:, :-1].values
y = iris.iloc[:, -1].values
# Encode the categorical output labels
encoder = LabelEncoder()
y = encoder.fit_transform(y)
# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
接下来,让我们创建四个模型。这些将是相当简单的模型。每个都有一层 8 个神经元和一个激活函数。最后一层将有 3 个神经元并使用 Softmax 激活函数。
#Model 1 (Sigmoid)
#Model 1
model = Sequential()
model.add(layers.Dense(8, input_dim=4, activation='sigmoid'))
model.add(layers.Dense(3, activation='softmax'))
#Model 2 (Tanh)
model = Sequential()
model.add(layers.Dense(8, input_dim=4, activation='tanh'))
model.add(layers.Dense(3, activation='softmax'))
#Model 3 (ReLU)
model = Sequential()
model.add(layers.Dense(8, input_dim=4, activation='relu'))
model.add(layers.Dense(3, activation='softmax'))
#Model 4 (Elliot)
model = Sequential()
model.add(layers.Dense(8, input_dim=4, activation=elliot))
model.add(layers.Dense(3, activation='softmax'))
接下来,简单地训练模型并分析结果。
# Compile the model
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
# Train the model (Pick the number of epochs)
model.fit(X_train, y_train, epochs=1, batch_size=10)
Results
结果……实际上令人惊讶。正如预期的那样,Elliot 激活函数生成的模型与采用 S 形和双曲正切激活函数的模型具有相似的性能。
1 Epoch
- Sigmoid @ 1: Accuracy: 0.3109 | Loss: 2.0030
- Elliot @ 1: Accuracy: 0.3361 | Loss: 1.0866
在 1 个 Epoch 时,Elliot 激活函数模型优于 Sigmoid 激活函数模型,精度提高了 2.61%,损失量减少了近 100%。
10 Epochs
- Sigmoid @ 10: Accuracy: 0.3529 | Loss: 1.0932
- Elliot @ 10: Accuracy: 0.6891 | Loss: 0.9434
在 10 个 epoch 时,与使用 Sigmoid 激活函数的模型相比,使用 Elliot 激活函数的模型的准确率提高了近 30%,损失更低。
100 Epochs
- Sigmoid @ 100: Accuracy: 0.9496 | Loss: 0.4596
- Elliot @ 100: Accuracy: 0.9580 | Loss: 0.5485
Sigmoid 模型优于 Elliot 模型,但是,应该注意的是,它们的性能几乎完全相同。
1000 Epochs
- Sigmoid @ 1000: Accuracy: 0.9832 | Loss: 0.0584
- Elliot @ 1000: Accuracy: 0.9832 | loss: 0.0433
在 1000 Epochs 时,两种不同模型的性能几乎完全相同。
总体而言,使用 Elliot 激活函数的模型比使用 Sigmoid 激活函数的模型表现稍好。
艾略特与双曲正切
1 Epoch
- tanh @ 1 : Accuracy: 0.3361 | loss: 1.1578
- Elliot @ 1: Accuracy: 0.3361 | Loss: 1.0866
在第 1 个时期,Elliot 激活函数模型与双曲正切激活函数模型的表现相同。我希望这些函数能够产生类似的性能模型,因为每个函数都类似地限制传递到神经网络下一层的值。
10 Epochs
- tanh @ 10: Accuracy: 0.3277 | Loss: 0.9981
- Elliot @ 10: Accuracy: 0.6891 | Loss: 0.9434
具有 Elliot 激活函数的模型大大优于具有双曲正切激活函数的模型,正如 Elliot 模型在 10 个时期与 S 型模型相比时所做的那样。
100 Epochs
- tanh @ 100: Accuracy: 0.9916 | Loss: 0.2325
- Elliot @ 100: Accuracy: 0.9580 | Loss: 0.5485
在 100 个 epoch 时,双曲正切模型的性能比 Elliot 模型好得多。在更高的时期,Elliot 激活函数与 tanh 激活函数相比似乎表现不佳,但让我们看看它们在 1000 个时期的表现有何不同。
1000 Epochs
- tanh @ 1000: Accuracy: 0.9748 | Loss: 0.0495
- Elliot @ 1000: Accuracy: 0.9832 | Loss: 0.0433
嗯,在 1000 个时期,Elliot 激活函数模型略优于双曲正切激活函数模型。
总的来说,我会说双曲正切模型和 Elliot 激活函数模型在神经网络的各个层中的工作原理几乎相同。训练模型的时间可能会有所不同,但是,这些模型非常简单,随着拥有的数据越多以及它们创建的网络规模越大,时间可能成为一个更大的因素。
Elliot versus ReLU
1 Epoch
- ReLU @ 1: Accuracy: 0.6639 | Loss: 1.0221
- Elliot @ 1: Accuracy: 0.3361 | Loss: 1.0866
在第 1 个时期,具有 ReLU 激活函数的模型表现得更好,这概括了一项观察结果,即 Elliot 激活函数导致模型训练速度变慢。
10 Epochs
- ReLU @ 10: Accuracy: 0.6471 | Loss: 0.9413
- Elliot @ 10: Accuracy: 0.6891 | Loss: 0.9434
哇!包含 Elliot 激活函数的模型实际上比具有 ReLU 激活函数的模型表现更好,精度高 4.2%,损失低 0.21%。
100 Epochs
- ReLU @ 100 : Accuracy: 0.9160 | Loss: 0.4749
- Elliot @ 100: Accuracy: 0.9580 | Loss: 0.5485
即使采用 Elliot 激活函数的模型有更高的损失,它也能达到 4.2% 的更高准确率。同样,这显示了将 Elliot 激活函数置于神经网络中时的强度。
1000 Epochs
- ReLU @ 1000: Accuracy: 0.9916 | Loss: 0.0494
- Elliot @ 1000: Accuracy: 0.9832 | Loss: 0.0433
虽然使用 Elliot 激活函数的模型在准确性方面并没有做得更好,但损失更低,我仍然对结果感到满意。如 1000 个 epoch 所示,Elliot 激活函数几乎与 ReLU 激活函数一样好,并且通过正确的问题和超参数调整,Elliot 激活函数可能是更优的选择。
Conclusion
今天,我们研究了一个鲜为人知的激活函数:艾略特激活函数。为了测试其性能,将其与形状相似的两个激活函数进行了比较:Sigmoid 激活函数和双曲正切激活函数。该试验导致 Elliot 函数的执行效果与在神经网络主体中使用这两个函数中的任何一个相同,甚至更好。接下来,我们将 Elliot 激活函数的性能与当今神经网络中使用的标准 ReLU 激活函数进行了比较。在 4 次试验中,采用 Elliot 激活函数的模型在 50% 的时间内表现更好。对于它表现不佳的其他试验,它的性能仍然与使用 ReLU 激活函数部署的模型几乎完全相同。我建议在你的下一个神经网络中尝试 Elliot 激活函数,因为它有可能表现得更好!
如果您喜欢今天的阅读,请关注我,如果您希望我探讨其他主题,请告诉我!如果您没有 Medium 帐户,请在此处通过我的链接注册!此外,请在 LinkedIn 上加我,或随时联系我们!谢谢阅读![0][1]
- Dubey、Shiv Ram、Satish Kumar Singh 和 Bidyut Baran Chaudhuri。 “深度学习中激活函数的综合调查和性能分析。” arXiv 预印本 arXiv:2109.14545 (2021)。
- Sharma、Sagar、Simone Sharma 和 Anidhya Athaiya。 “神经网络中的激活函数。”迈向数据科学 6.12 (2017):310–316。
- https://www.gallamine.com/2013/01/a-sigmoid-function-without-exponential_31.html[0]
文章出处登录后可见!