神经网络和深度学习-作业(一)
1. 介绍神经网络的发展过程。
神经网络大致发展过程可以分为五个阶段:
第一阶段为1943-1969年,神经网络发展的第一个高潮期。在此期间,科学家们提出了许多神经元模型和学习规则。1943年McCulloch和Pitts发表了神经网络的开山大作《A Logical Calculus if Ideas Immanent in Nervous Activity》,提出了神经元计算模型,这种神经网络模型叫MP模型。1948年,Alan Turing提出了一种“B型图灵机”,可基于Hebbian法则来进行学习。51年诞生第一台神经网络机SNARC,58年Rosenblatt提出感知器,一种模拟人类感知能力的神经网络模型,并提出一种接近于人类学习过程的学习算法。
第二阶段为1969-1983年,Marvin Minsky出版《感知机》,挑出了感知机的两大毛病,无法处理异或回路问题和计算能力不足。往后十多年,神经网络的研究一直没有太大进展。但期间BP算法提出,新知机一种带卷积和子采样操作的多层神经网络也被提出。
第三阶段为1983-1995年,Hinton等人将重新改进的反向传播算法引入多层感知器,BP算法重新激发了人们对神经网络的兴趣,Hopfield网络一种基于联想记忆的网络提出,84年随机化版本的Hopfield网络玻尔兹曼机诞生。分布式并行处理(一种连接主义模型)开始流行,89年,BP算法引入了卷积神经网络,并在手写体数字识别上取得了很大的成功。
第四阶段为1995-2006年,计算机性能仍然无法支持大规模的神经网络训练,SVM和线性分类器等简单的方法反而更流行。
第五阶段为2006-至今,“预训练+精调”的模式,深度学习崛起,大规模并行计算以及GPU设备的普及,计算机的计算能力得以大幅提高,已经可以端到端地训练一个大规模神经网络,不再需要借助预训练的方式。


1.# -*- coding: utf-8 -*- 2.""" 3.Created on Sun Mar 7 17:58:54 2021 4. 5.@author: pjmjty 6.""" 7.import matplotlib.pyplot as plt 8.import numpy as np 9. 10.class activateFunc(): 11. def __init__(self, x, b=None): 12. super(activateFunc, self).__init__() 13. self.x = x 14. self.b = b 15. def Swish(self): 16. y = self.x * (np.exp(self.b*self.x) / (np.exp(self.b*self.x) + 1)) 17. y_grad = np.exp(self.b*self.x)/(1+np.exp(self.b*self.x)) + self.x * (self.b*np.exp(self.b*self.x) / ((1+np.exp(self.b*self.x))*(1+np.exp(self.b*self.x)))) 18. return [y, y_grad] 19. 20.def PlotActiFunc(x, y): 21. plt.plot(x, y) 22. 23.if __name__ == '__main__': 24. x = np.arange(-10, 10, 0.01) 25.activateFunc = activateFunc(x) 26.plt.figure(1) 27.activateFunc.b = 0.1 28.PlotActiFunc(x, activateFunc.Swish()[0]) 29.activateFunc.b = 1 30.PlotActiFunc(x, activateFunc.Swish()[0]) 31.activateFunc.b = 10 32.PlotActiFunc(x, activateFunc.Swish()[0]) 33.plt.legend(['beta=0.1', 'beta=1', 'beta=10']) 34. 35.plt.figure(2) 36.activateFunc.b = 0.1 37.PlotActiFunc(x, activateFunc.Swish()[1]) 38.activateFunc.b = 1 39.PlotActiFunc(x, activateFunc.Swish()[1]) 40.activateFunc.b = 10 41.PlotActiFunc(x, activateFunc.Swish()[1]) 42.plt.legend(['Swish-grad beta=0.1','Swish-grad beta=1','Swish-grad beta=10']) 43.plt.show()
Swish函数图像:

导函数图像:

4. 编写Python代码,统计MNIST数据集中训练集和测试集中每个类别(即0, 1, …, 9)的样本数目,给出MNIST数据集中数字0-9的图片示例。


1.# -*- coding: utf-8 -*- 2.""" 3.Created on Sun Mar 7 23:03:42 2021 4. 5.@author: pjmjty 6.""" 7.import tensorflow as tf 8.import pandas as pd 9.import numpy as np 10.#Matplotlib是Python的2D绘图库 11.import matplotlib.pyplot as plt 12. 13.#mnist是28*28的手写数字的图片和对应标签的数据集 14.mnist = tf.keras.datasets.mnist 15.#mnist.load_data()下载MNIST数据集 16.(x_train, y_train), (x_test, y_test) = mnist.load_data() 17.#print('The shape of the tensor x_train is:', x_train.shape) 18.print('The size of the train data is:', len(y_train)) 19.print('The size of the test data is:', len(y_test)) 20.#value_counts()函数:对series中每一个样本值进行计数 21.pd.Series(y_train).value_counts() 22.c = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 23.print("{}的样本数目分别为:".format("train")) 24.print(pd.Series(y_train).value_counts()[c]) 25.print("{}的样本数目分别为:".format("test")) 26.print(pd.Series(y_test).value_counts()[c]) 27. 28.#统计训练样本中每个数字的样本数 29.#from collections import Counter 30.#print(Counter(y_train)) 31.#print(Counter(y_test)) 32.Z = np.random.rand(28, 28) 33.fig, ax = plt.subplots(nrows=2,ncols=5) 34.ax = ax.flatten() 35. 36.for i in range(10): 37. img = x_train[y_train == i][0].reshape(28, 28) 38. ax[i].imshow(img, cmap='PuBu_r') 39. 40.fig.tight_layout() 41.plt.show()
参考文献:
[1]邱锡鹏,“神经网络与深度学习”,1.5.3节,https://nndl.github.io/
[2]尼克,“人工智能简史”,人民邮电出版社
[3]Swish激活函数 https://blog.csdn.net/bblingbbling/article/details/107105648
[4]小白都能看懂的softmax详解 https://blog.csdn.net/bitcarmanlee/article/details/82320853
[5]Matplotlib库imshow函数 https://www.jianshu.com/p/694afb0db7d5

浙公网安备 33010602011771号