您当前的位置: 首页 >  网络

IT之一小佬

暂无认证

  • 1浏览

    0关注

    1192博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

神经网络中的神经元常见激活函数绘制

IT之一小佬 发布时间:2021-06-20 11:29:19 ,浏览量:1

近年来,神经网络方法在多个领域表现出优于传统算法的特点,其使用神经元的组合来提取数据中的深度特征,在非线性任务中表现出优越的性能。

神经元的非线性,主要是通过其激活函数f(x),将wx+b进行非线性化映射,其过程如下:

y = f(wx+b)

总结并绘制学术论文中可用的激活函数图,绘制的函数图包括: sigmoid函数、ReLU函数、tanh函数和pReLU函数(参数为0.5)。

1. sigmoid函数
import numpy as np
import matplotlib.pyplot as plt

def sigmoid(x):
    return 1. / (1 + np.exp(-x))

def plot_sigmoid():
    x = np.arange(-10, 10, 0.1)
    y = sigmoid(x)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.spines['top'].set_color('none')
    ax.spines['right'].set_color('none')
    ax.spines['left'].set_position(('data', 0))
    ax.plot(x, y)
    plt.xlim([-10.05, 10.05])
    plt.ylim([-0.02, 1.02])
    plt.tight_layout()
    
plot_sigmoid()

2. tanh函数
import numpy as np
import matplotlib.pyplot as plt


def tanh(x):
    return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))

def plot_sigmoid():
    x = np.arange(-10, 10, 0.1)
    y = tanh(x)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.spines['top'].set_color('none')
    ax.spines['right'].set_color('none')
    ax.spines['left'].set_position(('data', 0))
    ax.spines['bottom'].set_position(('data', 0))
    ax.plot(x, y)
    plt.xlim([-10.05, 10.05])
    plt.ylim([-0.02, 1.02])
    ax.set_yticks([-1.0, -0.5, 0.5, 1.0])
    ax.set_xticks([-10, -5, 5, 10])
    plt.tight_layout()
    
plot_sigmoid()

3. ReLU函数
import numpy as np
import matplotlib.pyplot as plt


def relu(x):
    return np.where(x            
关注
打赏
1665675218
查看更多评论
0.1152s