自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

8個(gè)深度學(xué)習(xí)中常用的激活函數(shù)

人工智能 深度學(xué)習(xí)
當(dāng)在隱藏層和輸出層中實(shí)現(xiàn)時(shí),激活函數(shù)的選擇非常關(guān)鍵。模型的準(zhǔn)確性和損失很大程度上依賴于激活函數(shù)。此外,必須根據(jù)您對(duì)模型的期望來選擇它們。例如,在二值分類問題中,sigmoid函數(shù)是一種最優(yōu)選擇。

 

激活函數(shù),又稱轉(zhuǎn)換函數(shù),是設(shè)計(jì)神經(jīng)網(wǎng)絡(luò)的關(guān)鍵。激活函數(shù)在某種意義上是重要的,因?yàn)樗挥脕泶_定神經(jīng)網(wǎng)絡(luò)的輸出。它將結(jié)果值映射為0到1或-1到1等(取決于函數(shù))。激活函數(shù)還有另一個(gè)名稱,稱為Squashing函數(shù),當(dāng)限制了激活函數(shù)的范圍時(shí)使用這個(gè)名稱。激活函數(shù)應(yīng)用于神經(jīng)網(wǎng)絡(luò)的每個(gè)節(jié)點(diǎn),并決定該神經(jīng)元是否應(yīng)該被“觸發(fā)”/“激活”。

為什么選擇激活函數(shù)是非常重要的。

當(dāng)在隱藏層和輸出層中實(shí)現(xiàn)時(shí),激活函數(shù)的選擇非常關(guān)鍵。模型的準(zhǔn)確性和損失很大程度上依賴于激活函數(shù)。此外,必須根據(jù)您對(duì)模型的期望來選擇它們。例如,在二值分類問題中,sigmoid函數(shù)是一種最優(yōu)選擇。

激活函數(shù)類型。大致可分為兩類:

線性激活函數(shù)。

非線性激活函數(shù)。

為了方便展示我們導(dǎo)入如下庫(kù):

  1. import math as m  
  2. import matplotlib.pyplot as plt  
  3. import numpy as np  
  4. import tensorflow as tf  
  5. from tensorflow import keras  
  6. from tensorflow.keras import layers  

 

Sigmoid

sigmoid激活函數(shù)也稱為logistic函數(shù)。Sigmoid函數(shù)在回歸分類問題中非常流行。sigmoid函數(shù)給出的值的范圍是0和1。

  1. def sigmoid(x):  
  2. return 1 / (1 + m.exp(-x))values_of_sigmoid = []  
  3. values_of_x = []  
  4. for i in range(-500,500,1):  
  5. i = i*0.01  
  6. values_of_x.append(i)  
  7. values_of_sigmoid.append(sigmoid(i))plt.plot( values_of_x ,values_of_sigmoid)  
  8. plt.xlabel("values of x")  
  9. plt.ylabel("value of sigmoid")  

 

 

8個(gè)深度學(xué)習(xí)中常用的激活函數(shù)

 

tanH

這個(gè)函數(shù)非常類似于sigmoid激活函數(shù)。這個(gè)函數(shù)在-1到1的范圍內(nèi)接受任何實(shí)值作為輸入和輸出值。輸入越大(越正),輸出值越接近1.0,而輸入越小(越負(fù)),輸出越接近-1.0。Tanh激活函數(shù)計(jì)算如下。

  1. def tanh(x):  
  2. return (m.exp(x) - m.exp(-x)) / (m.exp(x) + m.exp(-x))values_of_tanh = []  
  3. values_of_x = []  
  4. for i in range(-500,500,1):  
  5. i = i*0.001  
  6. values_of_x.append(i)  
  7. values_of_tanh.append(tanh(i))plt.plot( values_of_x ,values_of_tanh)  
  8. plt.xlabel("values of x")  
  9. plt.ylabel("value of tanh")  

 

 

8個(gè)深度學(xué)習(xí)中常用的激活函數(shù)

 

Softmax

Softmax激活函數(shù)輸出一個(gè)和為1.0的值向量,可以解釋為類隸屬度的概率。Softmax是argmax函數(shù)的“軟”版本,它允許一個(gè)“贏家通吃”函數(shù)的似然輸出。

  1. def softmax(x):  
  2. e_x = np.exp(x - np.max(x))  
  3. return e_x / e_x.sum()values_of_x = [i*0.01 for i in range(-500,500)]  
  4. plt.plot(scores ,softmax(values_of_x))  
  5. plt.xlabel("values of x")  
  6. plt.ylabel("value of softmax")  

 

 

8個(gè)深度學(xué)習(xí)中常用的激活函數(shù)

 

RELU 線性整流單元

ReLU可能是用于隱藏層的最常見的函數(shù)。它還可以有效地克服其他以前流行的激活函數(shù)(如Sigmoid和Tanh)的限制。具體來說,它不太容易受到阻止深度模型被訓(xùn)練的梯度下降消失問題的影響,盡管它可能會(huì)遇到諸如飽和單元等其他問題。

  1. def ReLU(x):  
  2. return max(0,x)values_of_relu = []  
  3. values_of_x = []  
  4. for i in range(-500,500,1):  
  5. i = i*0.01  
  6. values_of_x.append(i)  
  7. values_of_relu.append(ReLU(i))plt.plot(values_of_x,values_of_relu)  

 

 

8個(gè)深度學(xué)習(xí)中常用的激活函數(shù)

 

Leaky ReLU

ReLU的問題:當(dāng)給ReLU一個(gè)負(fù)值時(shí),它立即變成零,這降低了模型合適地?cái)M合或從數(shù)據(jù)訓(xùn)練的能力。這意味著ReLU激活函數(shù)的任何負(fù)輸入都會(huì)在圖中立即將該值轉(zhuǎn)換為零,這反過來又會(huì)通過不適當(dāng)?shù)赜成湄?fù)值而影響結(jié)果圖。

為了克服這個(gè)問題,Leaky ReLU被引入。

  1. def leaky_ReLU(x):  
  2. return max(0.1*x,x)values_of_L_relu = []  
  3. values_of_x = []  
  4. for i in range(-500,500,1):  
  5. i = i*0.01  
  6. values_of_x.append(i)  
  7. values_of_L_relu.append(leaky_ReLU(i))plt.plot(values_of_x,values_of_L_relu)  

 

 

8個(gè)深度學(xué)習(xí)中常用的激活函數(shù)

 

下面幾個(gè)函數(shù)都是RELU的變體基本上都是與Leaky 類似優(yōu)化了激活函數(shù)負(fù)值時(shí)的返回

ELU

  1. activation_elu = layers.Activation(‘elu’)x = tf.linspace(-3.0, 3.0, 100)  
  2. y = activation_elu(x) # once created, a layer is callable just like a functionplt.figure(dpi=100)  
  3. plt.plot(x, y)  
  4. plt.xlim(-3, 3)  
  5. plt.xlabel(“Input”)  
  6. plt.ylabel(“Output”)  
  7. plt.show()  

 

 

8個(gè)深度學(xué)習(xí)中常用的激活函數(shù)

 

SELU

  1. activation_selu = layers.Activation('selu')x = tf.linspace(-3.0, 3.0, 100)  
  2. y = activation_selu(x) # once created, a layer is callable just like a functionplt.figure(dpi=100)  
  3. plt.plot(x, y)  
  4. plt.xlim(-3, 3)  
  5. plt.xlabel("Input")  
  6. plt.ylabel("Output")  
  7. plt.show()  

 

 

8個(gè)深度學(xué)習(xí)中常用的激活函數(shù)

 

Swish

  1. activation_swish = layers.Activation(‘swish’)x = tf.linspace(-3.0, 3.0, 100)  
  2. y = activation_swish(x) # once created, a layer is callable just like a functionplt.figure(dpi=100)  
  3. plt.plot(x, y)  
  4. plt.xlim(-3, 3)  
  5. plt.xlabel(“Input”)  
  6. plt.ylabel(“Output”)  
  7. plt.show()  

 

 

8個(gè)深度學(xué)習(xí)中常用的激活函數(shù)

 

總結(jié)

常用于隱藏層激活函數(shù):

一般遞歸神經(jīng)網(wǎng)絡(luò)使用Tanh或sigmoid激活函數(shù),甚至兩者都使用。例如,LSTM通常對(duì)循環(huán)連接使用Sigmoid激活,對(duì)輸出使用Tanh激活。

1.多層感知器(MLP): ReLU激活函數(shù)。

2.卷積神經(jīng)網(wǎng)絡(luò)(CNN): ReLU激活函數(shù)。

3.遞歸神經(jīng)網(wǎng)絡(luò):Tanh和/或Sigmoid激活函數(shù)。

如果你不確定使用哪個(gè)激活函數(shù),你肯定可以嘗試不同的組合,并尋找最適合的,但是可以從RELU開始

輸出層激活功能:

輸出層激活函數(shù)必須根據(jù)你要解決的問題類型來選擇。例如,如果你有一個(gè)線性回歸問題,那么線性激活函數(shù)將是有用的。下面是您可能面臨的一些常見問題和使用的激活函數(shù)。

二進(jìn)制分類:一個(gè)節(jié)點(diǎn),sigmoid激活。

多類分類:每個(gè)類一個(gè)節(jié)點(diǎn),softmax激活。

多標(biāo)簽分類:每個(gè)類一個(gè)節(jié)點(diǎn),sigmoid激活。

以下是一些常用激活函數(shù)的公式和可視化顯示,希望對(duì)你有幫助

 

8個(gè)深度學(xué)習(xí)中常用的激活函數(shù)

 

責(zé)任編輯:華軒 來源: 今日頭條
相關(guān)推薦

2024-07-11 11:07:41

2022-08-05 13:51:32

Python函數(shù)lambda

2022-04-17 23:09:07

深度學(xué)習(xí)人工智能芯片

2019-12-11 13:24:57

深度學(xué)習(xí)數(shù)據(jù)結(jié)構(gòu)軟件

2022-09-26 00:00:00

神經(jīng)網(wǎng)絡(luò)激活函數(shù)sigmoid

2018-09-13 22:56:15

機(jī)器學(xué)習(xí)損失函數(shù)深度學(xué)習(xí)

2023-03-30 08:00:56

MySQL日期函數(shù)

2017-11-20 05:08:16

深度學(xué)習(xí)激活函數(shù)神經(jīng)網(wǎng)絡(luò)

2020-05-13 21:09:10

JavaScript前端技術(shù)

2010-04-01 09:46:04

Oracle日期函數(shù)

2022-10-17 15:43:14

深度學(xué)習(xí)回歸模型函數(shù)

2022-04-14 09:30:22

深度學(xué)習(xí)激活函數(shù)人工神經(jīng)

2022-04-25 14:27:05

Pandas函數(shù)數(shù)據(jù)

2018-09-18 10:55:24

人工智能機(jī)器學(xué)習(xí)深度學(xué)習(xí)

2022-10-28 15:19:28

機(jī)器學(xué)習(xí)距離度量數(shù)據(jù)集

2023-04-11 08:49:42

排序函數(shù)SQL

2022-06-30 08:31:54

排序函數(shù)SQL

2023-12-27 14:17:11

深度學(xué)習(xí)人工智能激活函數(shù)

2010-03-22 10:27:28

Python常用模塊I

2023-03-15 17:37:26

Java8ListMap
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)