BP(back propagation)神经网络是1986年由Rumelhart和McClelland为首的科学家提出的概念,是一种按照误差逆向传播算法训练的多层前馈神经网络,是目前应用最广泛的神经网络。
该代码不使用任何第三方深度学习工具包实现,利用Python3实现。
# -*- coding: utf-8 -*-
import numpy as np
######分别表示两种激活函数,tanh函数和sigmoid函数以及其的导数#####
# tanh函数
def tanh(x):
return np.tanh(x)
def tanh_derivative(x):
return 1 - np.tanh(x) * np.tanh(x)
# sigmod函数
def logistic(x):
return 1 / (1 + np.exp(-x))
# sigmod函数的导数
def logistic_derivative(x):
return logistic(x) * (1 - logistic(x))
class NeuralNetwork:
def __init__ (self, layers, activation = 'tanh'):
# “activation”参数决定了激活函数的种类,是tanh函数还是sigmoid函数。
if activation == 'logistic':
self.activation = logistic
self.activation_deriv = logistic_derivative
elif activation == 'tanh':
self.activation = tanh
self.activation_deriv = tanh_derivative
点击查看完整代码
本文介绍BP神经网络的基本原理及其使用Python进行实现的方法。BP神经网络由Rumelhart等人于1986年提出,是一种常用的多层前馈神经网络。文中详细展示了如何通过Python代码实现BP神经网络,并提供了tanh和sigmoid两种激活函数及其导数的定义。
4万+

被折叠的 条评论
为什么被折叠?



