如何选择激活函数

激活函数在设计神经网络上很关键。隐藏层的激活函数影响的是学习,输出层影响的是输出。

概述:
1.激活函数
2.隐藏层的激活函数
3.输出层的激活函数

激活函数

激活函数定义了输入的加权和是如何被转化成输出的。

一个神经网络通常有三个部分:输入层,隐藏层,输出层。
所有隐藏层的激活函数一般相同,输出层一般不同。激活函数一般可微。

隐藏层的激活函数

Rectified Linear Activation (ReLU)
Logistic (Sigmoid)
Hyperbolic Tangent (Tanh)

ReLU:max(0.0, x)

from matplotlib import pyplot
 
# rectified linear function
def rectified(x):
    return max(0.0, x)
 
# define input data
inputs = [x for x in range(-10, 10)]
# calculate outputs
outputs = [rectified(x) for x in inputs]
# plot inputs vs outputs
pyplot.plot(inputs, outputs)
pyplot.show()

Sigmoid:1.0 / (1.0 + e^-x)


# example plot for the sigmoid activation function
from math import exp
from matplotlib import pyplot
 
# sigmoid activation function
def sigmoid(x):
    return 1.0 / (1.0 + exp(-x))
 
# define input data
inputs = [x for x in range(-10, 10)]
# calculate outputs
outputs = [sigmoid(x) for x in inputs]
# plot inputs vs outputs
pyplot.plot(inputs, outputs)
pyplot.show()

tanh:

# example plot for the tanh activation function
from math import exp
from matplotlib import pyplot
 
# tanh activation function
def tanh(x):
    return (exp(x) - exp(-x)) / (exp(x) + exp(-x))
 
# define input data
inputs = [x for x in range(-10, 10)]
# calculate outputs
outputs = [tanh(x) for x in inputs]
# plot inputs vs outputs
pyplot.plot(inputs, outputs)
pyplot.show()

如何选择一个隐藏层激活函数:


image.png

输出层

Linear
Logistic (Sigmoid)
Softmax

线形的并不改变什么,而是直接返回值。


# example plot for the linear activation function
from matplotlib import pyplot
 
# linear activation function
def linear(x):
    return x
 
# define input data
inputs = [x for x in range(-10, 10)]
# calculate outputs
outputs = [linear(x) for x in inputs]
# plot inputs vs outputs
pyplot.plot(inputs, outputs)
pyplot.show()

softmax和概率相关
sigmoid

如何选择:
回归问题用线性,
Binary Classification: One node, sigmoid activation.
Multiclass Classification: One node per class, softmax activation.

Multilabel Classification: One node per class, sigmoid activation.
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文结构: 什么是梯度消失? 梯度消失有什么影响? 是什么原因? 解决方案有哪些? 如何选择激活函数? 1. 什么...
    不会停的蜗牛阅读 11,067评论 1 32
  • 计算机可以在眨眼间计算出复杂的数值计算。从理论上讲,它们甚至具有比人脑更大的处理能力 个晶体管,对 神经元的切换时...
    leon_kbl阅读 6,828评论 0 1
  • 各种activation functions的pro/con。 参考:https://blog.csdn.net/...
    log1302阅读 3,783评论 0 0
  • 在学习神经网络中,我们会常常碰到激活函数这个名词。那么什么是激活函数?激活函数激活的是什么?在神经网络中,有什么用...
    李涛AT北京阅读 8,175评论 0 1
  • 激活函数 神经网络的每一层基本都是在一个线性运算后面来一个非线性激活函数(Activation function)...
    andyjkt阅读 1,241评论 0 0