日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python實(shí)現(xiàn)之激活函數(shù)

本文轉(zhuǎn)載自微信公眾號(hào)「python與大數(shù)據(jù)分析」,作者一只小小鳥(niǎo)鳥(niǎo)。轉(zhuǎn)載本文請(qǐng)聯(lián)系python與大數(shù)據(jù)分析公眾號(hào)。

目前成都創(chuàng)新互聯(lián)已為成百上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、大柴旦網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。

激活函數(shù)(Activation Function),就是在人工神經(jīng)網(wǎng)絡(luò)的神經(jīng)元上運(yùn)行的函數(shù),負(fù)責(zé)將神經(jīng)元的輸入映射到輸出端。

如果不用激活函數(shù),每一層輸出都是上層輸入的線性函數(shù),無(wú)論神經(jīng)網(wǎng)絡(luò)有多少層,輸出都是輸入的線性組合,這種情況就是最原始的感知機(jī)。

如果使用的話,激活函數(shù)給神經(jīng)元引入了非線性因素,使得神經(jīng)網(wǎng)絡(luò)可以任意逼近任何非線性函數(shù),這樣神經(jīng)網(wǎng)絡(luò)就可以應(yīng)用到眾多的非線性模型中。

 
 
 
 
  1. #!/usr/bin/env python 
  2. # -*- coding: UTF-8 -*- 
  3. #                     _ooOoo_ 
  4. #                   o8888888o 
  5. #                    88" . "88 
  6. #                 ( | -  _  - | ) 
  7. #                     O\ = /O 
  8. #                 ____/`---'\____ 
  9. #                  .' \\| |// `. 
  10. #                 / \\|||:|||// \ 
  11. #               / _|||||-:- |||||- \ 
  12. #                | | \\\ - /// | | 
  13. #              | \_| ''\---/'' | _/ | 
  14. #               \ .-\__ `-` ___/-. / 
  15. #            ___`. .' /--.--\ `. . __ 
  16. #         ."" '< `.___\_<|>_/___.' >'"". 
  17. #       | | : `- \`.;`\  _ /`;.`/ - ` : | | 
  18. #          \ \ `-. \_ __\ /__ _/ .-` / / 
  19. #      ==`-.____`-.___\_____/___.-`____.-'== 
  20. #                     `=---=' 
  21. ''' 
  22. @Project :pythonalgorithms  
  23. @File :Activationfunction.py 
  24. @Author :不勝人生一場(chǎng)醉@Date :2021/8/11 0:14  
  25. ''' 
  26. import numpy as np 
  27. from matplotlib import pyplot as plt 
  28.  
  29.  
  30. def drawpic(x, y, label=' ', title=' '): 
  31.    plt.figure(figsize=(10, 8)) 
  32.    ax = plt.gca()  # 通過(guò)gca:get current axis得到當(dāng)前軸 
  33.    plt.rcParams['font.sans-serif'] = ['SimHei']  # 繪圖中文 
  34.    plt.rcParams['axes.unicode_minus'] = False  # 繪圖負(fù)號(hào) 
  35.    plt.plot(x, y, label=label) 
  36.  
  37.    # 設(shè)置圖片的右邊框和上邊框?yàn)椴伙@示 
  38.    ax.spines['right'].set_color('none') 
  39.    ax.spines['top'].set_color('none') 
  40.  
  41.    # 挪動(dòng)x,y軸的位置,也就是圖片下邊框和左邊框的位置 
  42.    # data表示通過(guò)值來(lái)設(shè)置x軸的位置,將x軸綁定在y=0的位置 
  43.    ax.spines['bottom'].set_position(('data', 0)) 
  44.    # axes表示以百分比的形式設(shè)置軸的位置,即將y軸綁定在x軸50%的位置 
  45.    ax.spines['left'].set_position(('axes', 0.5)) 
  46.    # ax.spines['left'].set_position(('data', 0)) 
  47.    plt.title(title) 
  48.    plt.legend(loc='upper right') 
  49. plt.show() 
  50.  
  51.  
  52. if __name__ == '__main__': 
  53.    std = 0.1  # 標(biāo)準(zhǔn)差為0.1 
  54.    avg = 1  # 平均值為1 
  55.    x = np.linspace(avg - 5 * std, avg + 5 * std, 100) 
  56.    y = normaldistribution(x, avg, std) 
  57.    drawpic(x, y, 'normaldistribution', 'normal distribution function') 
  58.  
  59.    x = np.linspace(-5, 5, 100) 
  60.    y = sigmoid(x) 
  61.    drawpic(x, y, 'sigmoid', 'sigmoid Activation function') 
  62.  
  63.    y = tanh(x) 
  64.    drawpic(x, y, 'tanh', 'tanh Activation function') 
  65.  
  66.    y = stepfunction(x) 
  67.    drawpic(x, y, 'tanh', 'step Activation function') 
  68.  
  69.    y = relu(x) 
  70.    drawpic(x, y, 'relu', 'relu Activation function') 
  71.  
  72.    y = leakyrelu(x) 
  73.    drawpic(x, y, 'leakyrelu', 'leakyrelu Activation function') 
  74.  
  75.    y = softmax(x) 
  76.    drawpic(x, y, 'softmax', 'softmax Activation function') 
 
 
 
 
  1. # 求正態(tài)分布值,avg表示期望值,std表示標(biāo)準(zhǔn)差 
  2. def normaldistribution(x, avg=0, std=1): 
  3.    return np.exp(-(x - avg) ** 2 / (2 * std ** 2)) / (np.sqrt(2 * np.pi) * std) 
  4.    # return np.exp(-(x - avg) ** 2 / (2 * std ** 2)) / (math.sqrt(2 * math.pi) *  

 
 
 
 
  1. # Sigmoid函數(shù) 
  2. # Sigmoid函數(shù)是一個(gè)在生物學(xué)中常見(jiàn)的S型函數(shù),也稱為S型生長(zhǎng)曲線。 
  3. # 在信息科學(xué)中,由于其單增以及反函數(shù)單增等性質(zhì),Sigmoid函數(shù)常被用作神經(jīng)網(wǎng)絡(luò)的閾值函數(shù),將變量映射到0,1之間 
  4. def sigmoid(x): 
  5.    return 1 / (1 + np.power(np.e, -x)) 

 
 
 
 
  1. # Tanh函數(shù) 
  2. # Tanh是雙曲函數(shù)中的一個(gè),Tanh()為雙曲正切。 
  3. # 在數(shù)學(xué)中,雙曲正切“Tanh”是由基本雙曲函數(shù)雙曲正弦和雙曲余弦推導(dǎo)而來(lái)。 
  4. # 函數(shù)tanh(藍(lán)色)和函數(shù)sigmoid(橙色)一樣,在其飽和區(qū)的接近于0,都容易產(chǎn)生后續(xù)梯度消失、計(jì)算量大的問(wèn)題 
  5. def tanh(x): 
  6.    return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x)) 

 
 
 
 
  1. # 階躍函數(shù) 
  2. def stepfunction(x): 
  3.    return np.array(x > 0, dtype=np.int32) 

 
 
 
 
  1. # ReLU函數(shù) 
  2. # Relu激活函數(shù)(The Rectified Linear Unit),用于隱層神經(jīng)元輸出。 
  3. # Relu會(huì)使一部分神經(jīng)元的輸出為0,這樣就造成了網(wǎng)絡(luò)的稀疏性,并且減少了參數(shù)的相互依存關(guān)系,緩解了過(guò)擬合問(wèn)題的發(fā)生。 
  4. def relu(x): 
  5.    return np.maximum(0, x) 

 
 
 
 
  1. # leaky ReLU函數(shù) 
  2. def leakyrelu(x): 
  3.    return np.maximum(0.01 * x, x) 

 
 
 
 
  1. # softmax函數(shù) 
  2. # softmax函數(shù)可以看做是Sigmoid函數(shù)的一般化,用于多分類神經(jīng)網(wǎng)絡(luò)輸出。 
  3. def softmax(x): 
  4.    return np.exp(x) / np.sum(np.exp(x)) 

網(wǎng)頁(yè)標(biāo)題:Python實(shí)現(xiàn)之激活函數(shù)
當(dāng)前網(wǎng)址:http://www.5511xx.com/article/cosgsoc.html