汽车做网站,电商网站开发 思维导图,莱钢建设有限公司网站,个人网站企业备案区别1. 关于非线性转化方程(non-linear transformation function) sigmoid函数(S 曲线)用来作为activation function:1.1 双曲函数(tanh)tanh是双曲函数中的一个#xff0c;tanh()为双曲正切。在数学中#xff0c;双曲正切“tanh”是由基本双曲函数双曲正弦和双曲余弦推导而来公式…1. 关于非线性转化方程(non-linear transformation function) sigmoid函数(S 曲线)用来作为activation function:1.1 双曲函数(tanh)tanh是双曲函数中的一个tanh()为双曲正切。在数学中双曲正切“tanh”是由基本双曲函数双曲正弦和双曲余弦推导而来公式定义双曲正切函数是双曲函数中的一个函数。定义域和值域函数ytanh x定义域R值域(-1,1)。ytanh x是一个奇函数其函数图像为过原点并且穿越Ⅰ、Ⅲ象限的严格单调递增曲线其图像被限制在两水平渐近线y1和y-1之间。周期性双曲正切函数ytanhx其不是周期函数。导数双曲正切函数的导数公式 求导f(x)1-f(x)*f(x)1.2 逻辑函数(logistic function)Logistic函数或Logistic曲线是一种常见的S形函数它是皮埃尔·弗朗索瓦·韦吕勒在1844或1845年在研究它与人口增长的关系时命名的。广义Logistic曲线可以模仿一些情况人口增长P的S形曲线。起初阶段大致是指数增长然后随着开始变得饱和增加变慢最后达到成熟时增加停止。公式求导 d d x f ( x ) f ( x ) ( 1 − f ( x ) ) {\displaystyle {\frac {d}{dx}}f(x)f(x)(1-f(x))} 2. 实现一个简单的神经网络算法#!/usr/bin/env python
#-*-coding:utf-8-*-
#神经网络的实现方法import numpy as np
#定义双曲函数
def tanh(x):return np.tanh(x)
#双曲线求导
def tanh_deriv(x):return 1.0-np.tanh(x)*np.tanh(x)
#逻辑函数
def logistic(x):return 1/(1np.exp(-x))
#求导
def logistic_derivative(x):return logistic(x)*(1-logistic(x))class NeuralNetwork:def __init__(self,layers,activationtanh):if activation logistic:self.activationlogisticself.activation_derivlogistic_derivativeelif activation tanh:self.activationtanhself.activation_derivtanh_derivself.weights[]#初始化权重for i in range(1,len(layers)-1):self.weights.append((2*np.random.random((layers[i-1]1,layers[i]1))-1)*0.25)self.weights.append((2*np.random.random((layers[i]1,layers[i1]))-1)*0.25)def fit(self,X,y,learning_rate0.2,epochs10000):#每次随机抽取epochs个实例Xnp.atleast_2d(X)tempnp.ones([X.shape[0],X.shape[1]1])temp[:,0:-1]XXtemp#bias初值ynp.array(y)for k in range(epochs):#随机抽取每行inp.random.randint(X.shape[0])a[X[i]]#更新的实例#正向更新for l in range(len(self.weights)):a.append(self.activation(np.dot(a[l],self.weights[l])))errory[i]-a[-1]#反向传送最后一个错误率deltas[error*self.activation_deriv(a[-1])]#输出层ErrjOj(1-Oj)(Tj-Oj)#根据误差反向传送#隐藏层for l in range(len(a)-2,0,-1):deltas.append(deltas[-1].dot(self.weights[l].T)*self.activation_deriv(a[l]))deltas.reverse()#更新权重for i in range(len(self.weights)):layernp.atleast_2d(a[i])deltanp.atleast_2d(deltas[i])self.weights[i]learning_rate*layer.T.dot(delta)def predict(self,x):xnp.array(x)tempnp.ones(x.shape[0]1)temp[0:-1]xatempfor l in range(0,len(self.weights)):aself.activation(np.dot(a,self.weights[l]))return a