深度学习4:神经网络的架构和类型
2017-11-28 11:04
549 查看
人类是如何学习的?时代在改变,有些观念却是永恒不变的,信息比肉体的存在更长久,虽然信息存储在我们的大脑里,但它却可以代代相传。我们的大脑可以接收五类感知信息(视觉、听觉、触觉、嗅觉、味觉),并由其创造出层层概念,如果我们足够幸运,就能在老师亲自指导下学会一项技能。当我们身处我们某个环境中,我们可以感受到周遭环境,看到眼前的障碍,并试图预测接下来的走向。如果初次的尝试失败了,没有关系,有了试错的过程,我们可以掌握任何技能,但是什么给了大脑这种特殊的能力,使人脑不同于自然界中的其他生命?
所有我们经历或感受到的想法和记忆、自我认知,都产生于大脑,在分子层面,大脑油大约1000亿个神经细胞(也称神经元)组成,每个神经云负责三项工作,第一项工作是从树突上接受一组信号;第二项工作是把这些信号整合在一起,以决定是否需要把信息传递给细胞体中;最后一项工作是如果信号总和超过了一定阈值,就发送动作电位信号,并通过它们的轴突传给下一组神经元。
神经网络支配大脑,给了智能灵感,人脑智能发明了现代语言,航天科技以及变形金刚,它使得人类成为万物之灵,它让我们在地球上生存并繁衍。但由于我们依旧是物种的一员,我们需要面对生存的威胁,迫在眉睫的气候变化带来的威胁、生化武器的可能、小行星的影响,这些重要的问题需要我们的生物神经网络,一代又一代人类去解决。如果可以利用这种生物神经网络创造一种人工的神经网络,并在类似硅这样的非生物基质上运行,一切会如何?
可以给机器超过人类的计算能力和数据,并让它用超过人类一千甚至百万倍的速度解决问题。1943年,两位早起的科学家Warren McCulloch和Walter
Pitts发明了第一个神经元计算模型,他们的模型演示了一个神经元,可以接收二进制,将它们求和并且如果求和后超过一定阈值,就输出1;如果没有就输出0。这是一个简单的模型,但是在AI的早期,这可相当了不起,让计算机科学家们讨论其可能性。
几年后,一个叫Frank Rosenblatt的心理学家,对McCulloch-Pitts的模型任然缺少学习机制而感到失望,所以他在前人的想法之上设想了一个神经模型,称之为感知器(Perception),也称作单层前馈神经网络。我们称之为前馈,是因为数据只沿着一个方向前进,感知器引入了输入的权值概念,因此给定一些输入输出的训练集,它可以通过增大或减少每个连续特征数据的权值,并依据每个训练集的输出值来学习一个函数。这些权重值以数学的形式应用于输入,这样在每次迭代之后,输出的预测变得更准确。
为了更好地理解训练过程,接下来我们将使用python来建立一个单层神经网络并且只依赖于Numpy。
实现定义一个网络模型,网络模型如上图,代码如下图
然后再main函数中初始化网络,并进行训练测试:
测试模型时,输入值矩阵为4*3,输出矩阵为4*1.
参考资料:
网易云课堂,《硅谷大牛带你入门深度学习》第二讲
更多更好文章,欢迎关注微信公众号:深圳程序媛(updatedaybyday)
附源代码:(编译环境Jupyter Notebook,python3)
所有我们经历或感受到的想法和记忆、自我认知,都产生于大脑,在分子层面,大脑油大约1000亿个神经细胞(也称神经元)组成,每个神经云负责三项工作,第一项工作是从树突上接受一组信号;第二项工作是把这些信号整合在一起,以决定是否需要把信息传递给细胞体中;最后一项工作是如果信号总和超过了一定阈值,就发送动作电位信号,并通过它们的轴突传给下一组神经元。
神经网络支配大脑,给了智能灵感,人脑智能发明了现代语言,航天科技以及变形金刚,它使得人类成为万物之灵,它让我们在地球上生存并繁衍。但由于我们依旧是物种的一员,我们需要面对生存的威胁,迫在眉睫的气候变化带来的威胁、生化武器的可能、小行星的影响,这些重要的问题需要我们的生物神经网络,一代又一代人类去解决。如果可以利用这种生物神经网络创造一种人工的神经网络,并在类似硅这样的非生物基质上运行,一切会如何?
可以给机器超过人类的计算能力和数据,并让它用超过人类一千甚至百万倍的速度解决问题。1943年,两位早起的科学家Warren McCulloch和Walter
Pitts发明了第一个神经元计算模型,他们的模型演示了一个神经元,可以接收二进制,将它们求和并且如果求和后超过一定阈值,就输出1;如果没有就输出0。这是一个简单的模型,但是在AI的早期,这可相当了不起,让计算机科学家们讨论其可能性。
几年后,一个叫Frank Rosenblatt的心理学家,对McCulloch-Pitts的模型任然缺少学习机制而感到失望,所以他在前人的想法之上设想了一个神经模型,称之为感知器(Perception),也称作单层前馈神经网络。我们称之为前馈,是因为数据只沿着一个方向前进,感知器引入了输入的权值概念,因此给定一些输入输出的训练集,它可以通过增大或减少每个连续特征数据的权值,并依据每个训练集的输出值来学习一个函数。这些权重值以数学的形式应用于输入,这样在每次迭代之后,输出的预测变得更准确。
为了更好地理解训练过程,接下来我们将使用python来建立一个单层神经网络并且只依赖于Numpy。
实现定义一个网络模型,网络模型如上图,代码如下图
然后再main函数中初始化网络,并进行训练测试:
测试模型时,输入值矩阵为4*3,输出矩阵为4*1.
参考资料:
网易云课堂,《硅谷大牛带你入门深度学习》第二讲
更多更好文章,欢迎关注微信公众号:深圳程序媛(updatedaybyday)
附源代码:(编译环境Jupyter Notebook,python3)
# coding: utf-8 # In[16]: from numpy import exp, array, random, dot class NeuralNetwork(): def __init__(self): #Seed the random number generator,so it generates the same numbers #every time the program runs random.seed(1) #we model a single neuron,with 3 input connections and 1 output connection #we assign random weights to a 3*1 matrix,with values in the range -1 to 1 self.synatic_weights = 2 * random.random((3,1))-1 #the sigmoid function,which describes an s shaped curve #we pass the weighted sum of the iputs through this function #to normalise them between 0 and 1 def __sigmoid(self, x): return 1 / (1 + exp(-x)) #gradient of the sigmoid curve def __sigmoid__derivative(self, x): return x*(1-x) def train(self, training_set_inputs, training_set_outputs, number_of_training_iterations): for iteration in range(number_of_training_iterations): #pass the training set through our neural net output = self.predict(training_set_inputs) # calculate the error error = training_set_outputs.T-output #mutiply the error by the input ad again by the gradient of the sigmoid curve delta = error* self.__sigmoid__derivative(output) adjustment = training_set_inputs.T.dot(delta) #adjust the weights self.synatic_weights +=adjustment def predict(self, inputs): #pass inputs through neural network(our single neuron) return self.__sigmoid(dot(inputs, self.synatic_weights)) #mian if __name__ == '__main__': #initialise a single neuron neural network neural_network = NeuralNetwork() print('Random starting synaptic weights:') print(neural_network.synatic_weights) #The training set. We have 4 examples,each consisting of 3 input values and 1 output value. training_set_inputs = array([[0,0,1],[1,1,1],[1,0,1],[0,1,1]]) traing_set_outputs = array([[0,1,1,0]]) #train the neural network using a training set. #Do it 10,000 times and make small adjustments each time neural_network.train(training_set_inputs, traing_set_outputs, 10000) print('new synaptic weights after training:') print(neural_network.synatic_weights) #Test the neural network print('predicting') print(neural_network.predict(array([1,0,0]))) # In[ ]:
相关文章推荐
- 第五章(1.4)深度学习——神经网络架构和原理
- 神经网络与深度学习 1.3 神经网络的架构 1.4 一个简单的分类手写数字的网络架构
- 【深度学习技术】神经网络整体架构
- 深度学习——图像前背景分离神经网络技术架构
- 【深度学习】详细的神经网络架构图
- 基于深度学习神经网络等机器学习技术实现一个医学辅助诊断的专家系统原型
- 深度学习框架TensorFlow学习与应用(七)——循环神经网络(RNN)应用于MNIST数据集分类
- 深度学习基础(一)神经网络 分类: 深度学习 2015-01-19 21:29 84人阅读 评论(0) 收藏
- Deep Learning(深度学习)之(五)神经网络训练中的高效BP(反向传播算法)
- [计算机视觉][神经网络与深度学习]Faster R-CNN配置及其训练教程
- 卷积神经网络(六):谷歌的深度学习网络架构Inception与Inception-ResNet
- TensorFlow:实战Google深度学习框架(二)实现简单神经网络
- 【神经网络与深度学习】caffe+VS2013+Windows无GPU快速配置教程
- 台大林轩田机器学习技法神经网络深度学习完全解读
- Coursera deep learning 吴恩达 神经网络和深度学习 第四周 编程作业 Building your Deep Neural Network
- 深度学习概论:神经网络
- TensorFlow 深度学习框架 (1)-- 神经网络与前向传播
- 神经网络与深度学习笔记——神经网络与梯度下降
- coursera 吴恩达 -- 第一课 神经网络和深度学习 :第四周课后习题 Deep Neural Network - Application v3
- Spark MLlib Deep Learning Neural Net(深度学习-神经网络)1.1