import math
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
def sigmoid(x):
return 1.0/(1+np.exp(-x))
nums = np.arange(-10, 10, step=1) #生成一个numpy数组
fig, ax = plt.subplots(figsize=(12,4)) #绘制子图
ax.plot(nums, sigmoid(nums), 'r') #绘制sigmoid的函数图像
plt.show()
mpl.rcParams['axes.unicode_minus'] = False
fig = plt.figure(figsize=(6,4))
ax = fig.add_subplot(111)
x = np.linspace(-10,10)
y = sigmoid(x)
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.set_xticks([-10,-5,0,5,10])
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))
ax.set_yticks([-1,-0.5,0.5,1])
[<matplotlib.axis.YTick at 0x1f35d04ad30>,
<matplotlib.axis.YTick at 0x1f35d0ada58>,
<matplotlib.axis.YTick at 0x1f35d083b00>,
<matplotlib.axis.YTick at 0x1f35d0c4eb8>]
plt.plot(x,y,label = 'Softmax',linestyle='-',color='blue')
plt.legend(['Softmax'])
plt.savefig('softmax.png')
plt.show()
fig = plt.figure(figsize=(6,4))
ax = fig.add_subplot(111)
x = np.arange(-10,10)
y = np.where(x<0,0,x) # 小于0输出0,大于0输出y
plt.xlim(-11,11)
plt.ylim(-11,11)
(-11, 11)
ax = plt.gca() # 获得当前axis坐标轴对象
ax.spines['right'].set_color('none') # 去除右边界线
ax.spines['top'].set_color('none') # 去除上边界线
ax.xaxis.set_ticks_position('bottom') # 指定下边的边作为x轴
ax.yaxis.set_ticks_position('left') # 指定左边的边为y轴
ax.spines['bottom'].set_position(('data',0)) # 指定data 设置的bottom(也就是指定的x轴)绑定到y轴的0这个点上
ax.spines['left'].set_position(('data',0)) # 指定y轴绑定到x轴的0这个点上
plt.plot(x,y,label = 'ReLU',linestyle='-',color='darkviolet')
plt.legend(['ReLU'])
plt.savefig('relu.png')
plt.show()
x = np.arange(-10,10)
a = np.array(x)
y = (math.e**(x) - math.e**(-x)) / (math.e**(x) + math.e**(-x))
plt.xlim(-11,11)
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.spines['bottom'].set_position(('data',0))
ax.spines['left'].set_position(('data',0))
plt.plot(x,y,label='Tanh',linestyle='-',color='green')
plt.legend(['Tanh'])
plt.savefig('Tanh.png',dpi=500) # 指定分辨率
plt.show()
对深度学习的理解:
是机器学习的分支,海量数据为输入的,规则自学习方法。深度学习可以让计算机通过较简单的概念构建复杂的概念,让计算机模拟人的学习模式,获取新的知识和技能。深度学习的框架有许多种,比如深度神经网络,卷积神经网络。深度学习的思想是堆叠多个层,这一层的输出作为下一层的输入,通过这种方式来实现对输入信息的分级表达。深度学习提出了一种让计算机自动学习出模式特征的方法,并将特征学习融入到了建立模型的过程中,从而减少了人为设计特征造成的不完备性。