bpnet.cpp

来自「该程序通过BP算法实现0-9的数字识别」· C++ 代码 · 共 87 行

CPP
87
字号
// BPNet.cpp: implementation of the CBPNet class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "bp.h"
#include "BPNet.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBPNet::CBPNet()
{
bSuccess=false;
for (int i=0;i<10;i++)
	{
		for (int j=0;j<10;j++)
		{
			if (i==j)
			{
				t[i][j]=1;
			}
			else
				t[i][j]=0;
		}
	}
}

CBPNet::~CBPNet()
{

}


void CBPNet::InitWeight()
{
  int i,j;
//伪随机种子
  srand((unsigned)time( NULL ) );
  	for(i=0;i<M1;i++)
	{
		for(j=0;j<P;j++)
		{
				float rnd;
				rnd=(rand()%1000)/10000.0;
				hide1_w[i][j]=rnd;//权值初始化。
		}
	}
    
/*	for(i=0;i<M2;i++)
	{
		for(j=0;j<M3;j++)
		{
				float rnd;
				rnd=(rand()%100)/10000.0;
				hide2_w[i][j]=rnd;//权值初始化。
		}
	}

	for(i=0;i<M1;i++)
	{
		for(j=0;j<M2;j++)
		{
				float rnd;
				rnd=(rand()%100)/10000.0;
				hide1_w[i][j]=rnd;//权值初始化。
		}
	}*/

	for(i=0;i<N;i++)
	{
		for(j=0;j<M1;j++)
		{
				float rnd;
				rnd=(rand()%1000)/10000.0;
				intoh_w[i][j]= rnd;//权值初始化。
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?