errRec.append(sse)
    # 判断是否收敛
    iteration = iteration + 1
        
    if sse <= eb:
        print("iteration:",i) 
        break
     
    # 误差信号反向传播
    # DELTA和delta为局部梯度  
    DELTA = multiply(err,BackPropgation.dlogsig(HM,out))
    wDelta = W.transpose()*DELTA
    delta = multiply(wDelta,BackPropgation.dlogsig(hp,tau))
    dWEX = DELTA*tauex.transpose()
    dwex = delta*SampIn.transpose()        
    # 更新权值
    if i == 0:  
        WEX = WEX + eta * dWEX
        wex = wex + eta * dwex
    else :    
        WEX = WEX + (1 - mc)*eta*dWEX + mc * dWEXOld
        wex = wex + (1 - mc)*eta*dwex + mc * dwexOld
 
    dWEXOld = dWEX
    dwexOld = dwex 
    W  = WEX[:,0:nHidden]

# 绘制误差曲线
X = linspace(0,1000,1000)
Untils.TrendLine(X,errRec)
   
示例#2
0
# -*- coding:utf-8 -*-
# Filename : testBoltzmann01.py

import operator
import copy
import Untils
import Boltzmann
from numpy import *
import matplotlib.pyplot as plt

dataSet = Untils.loadDataSet("dataSet25.txt")
cityPosition = mat(dataSet)
m, n = shape(cityPosition)
bestx, di = Boltzmann.boltzmann(cityPosition, MAX_ITER=1000, T0=100)

# 优化前城市图,路径图
Untils.drawScatter(cityPosition, flag=False)
Untils.drawPath(list(range(m)), cityPosition)

# 显示优化后城市图,路径图
Untils.drawScatter(cityPosition, flag=False)
Untils.drawPath(bestx, cityPosition, color='b')

# 绘制误差趋势线
x0 = list(range(len(di)))
Untils.TrendLine(x0, di)
示例#3
0
import operator
import Untils
import BackPropgation
import matplotlib.pyplot as plt 

# 数据集
dataSet,classLabels = BackPropgation.loadDataSet("testSet2.txt") # 初始化时第1列为全1向量, studentTest.txt
dataSet = BackPropgation.normalize(mat(dataSet))

# 绘制数据点
# 重构dataSet数据集
dataMat = mat(ones((shape(dataSet)[0],shape(dataSet)[1])))
dataMat[:,1] = mat(dataSet)[:,0]
dataMat[:,2] = mat(dataSet)[:,1]	

# 绘制数据集散点图
Untils.drawClassScatter(dataMat,transpose(classLabels),False)

# BP神经网络进行数据分类
errRec,WEX,wex = BackPropgation.bpNet(dataSet,classLabels)

# 计算和绘制分类线
x,z = BackPropgation.BPClassfier(-3.0,3.0,WEX,wex)

Untils.classfyContour(x,x,z)

# 绘制误差曲线
X = linspace(0,2000,2000)
Y = log2(errRec)+1.0e-6
Untils.TrendLine(X,Y)