亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? testdoc.cpp

?? 神經網絡的bp算法。學神經網絡的基礎經典算法
?? CPP
字號:
// testDoc.cpp : implementation of the CTestDoc class
//

#include "stdafx.h"
#include "test.h"

#include "testDoc.h"
#include "DataInput.h"
#include "ValueInput.h"
#include "MyTestDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTestDoc

IMPLEMENT_DYNCREATE(CTestDoc, CDocument)

BEGIN_MESSAGE_MAP(CTestDoc, CDocument)
	//{{AFX_MSG_MAP(CTestDoc)
	ON_COMMAND(ID_MENU_LOAD, OnMenuLoad)
	ON_COMMAND(ID_MENU_LEARN, OnMenuLearn)
	ON_COMMAND(ID_MENU_NEWFILE, OnMenuNewfile)
	ON_COMMAND(ID_MENU_TEST, OnMenuTest)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDoc construction/destruction

CTestDoc::CTestDoc()
{
	// TODO: add one-time construction code here
	max_error_tollerance = 0.09;
	file_loaded = FALSE;
	data_learned = FALSE;
	can_learn = FALSE;
	dispmode = 0;
	ytemp = 0;
	ztemp = 0;
	total = 0;

	input = NULL;
	hidden = NULL;
	output = NULL;
	target = NULL;
	bias = NULL;
	weight_i_h = NULL;
	weight_h_o = NULL;
	errorsignal_hidden = NULL;
	errorsignal_output = NULL;
}

CTestDoc::~CTestDoc()
{
	if (file_loaded)
	{
		clear_memory();
	}
}

BOOL CTestDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CTestDoc serialization

void CTestDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CTestDoc diagnostics

#ifdef _DEBUG
void CTestDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CTestDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTestDoc commands

void CTestDoc::OnMenuLoad() 
{
	// TODO: Add your command handler code here
    CFileDialog dlg_file(TRUE,"txt","*.txt");
	if (dlg_file.DoModal()==IDOK)
	{
		if (file_loaded)
		{
			clear_memory();
		}
		else
		{
			file_loaded = TRUE;
		}
		ifstream in(dlg_file.GetPathName());
	
		TRACE("\nfilename=%s\n",dlg_file.GetPathName());
		data_learned = FALSE;
		can_learn = TRUE;
	
		in >> input_array_size;
		in >> hidden_array_size;
		in >> output_array_size;
		in >> learning_rate;
		in >> number_of_input_patterns;
		TRACE("\n\nparameter=%d,%d,%d,%f,%d\n\n",input_array_size,
										   hidden_array_size,
										   output_array_size,
										   learning_rate,
										   number_of_input_patterns);
		bias_array_size = hidden_array_size + output_array_size;
		initialize_net();
		int x,y;
		for(x=0; x<bias_array_size; x++) 
		{
			in >> bias[x];
			TRACE("BIAS[%d]=%f\n",x,bias[x]);
		}
		for(x=0; x<input_array_size; x++) 
		{ 
			for(y=0; y<hidden_array_size; y++)
			{
				in >> weight_i_h[x][y];
				TRACE("Weight_i_h[%d][%d]=%f\n",x,y,weight_i_h[x][y]);
			}
		}
		for(x=0; x<hidden_array_size; x++) 
		{ 
			for(y=0; y<output_array_size; y++)
			{
				in >> weight_h_o[x][y];
				TRACE("Weight_h_o[%d][%d]=%f\n",x,y,weight_h_o[x][y]);
			}
		}
		for(x=0; x<number_of_input_patterns; x++) 
		{
			for(y=0; y<input_array_size; y++) 
			{
				in >> input[x][y];
				TRACE("input[%d][%d]=%.0f\n",x,y,input[x][y]);
			}
		}
		for(x=0; x<number_of_input_patterns; x++)
		{
			for(y=0; y<output_array_size; y++)
			{
				in >> target[x][y];
				TRACE("target[%d][%d]=%.0f\n",x,y,target[x][y]);
			}
		}
		in.close();
		::AfxMessageBox("Data loaded");
	}
}

void CTestDoc::initialize_net()
{
	int x;
	input = new double * [number_of_input_patterns];
	if(!input) { ::AfxMessageBox("memory problem!"); exit(1); }
	for(x=0; x<number_of_input_patterns; x++)
	{
		input[x] = new double [input_array_size];
		if(!input[x]) { ::AfxMessageBox("memory problem!"); exit(1); }
	}

	//hidden = new double [hidden_array_size];
	hidden = new double * [number_of_input_patterns];
	if(!hidden) { ::AfxMessageBox("memory problem!"); exit(1); }
	for (x=0; x<number_of_input_patterns; x++)
	{
		hidden[x] = new double [hidden_array_size];
		if(!hidden[x]) {::AfxMessageBox("memory problem!"); exit(1); }
	}

	output = new double * [number_of_input_patterns];
	if(!output) { ::AfxMessageBox("memory problem!"); exit(1); }
	for(x=0; x<number_of_input_patterns; x++)
	{
		output[x] = new double [output_array_size];
		if(!output[x]) { ::AfxMessageBox("memory problem!"); exit(1); }
	}

	target = new double * [number_of_input_patterns];
	if(!target) { ::AfxMessageBox("memory problem!"); exit(1); }
	for(x=0; x<number_of_input_patterns; x++)
	{
		target[x] = new double [output_array_size];
		if(!target[x]) { ::AfxMessageBox("memory problem!"); exit(1); }
	}

	bias = new double [bias_array_size];
	if(!bias) { ::AfxMessageBox("memory problem!"); exit(1); }

	weight_i_h = new double * [input_array_size];
	if(!weight_i_h) { ::AfxMessageBox("memory problem!"); exit(1); }
	for(x=0; x<input_array_size; x++)
	{
		weight_i_h[x] = new double [hidden_array_size];
		if(!weight_i_h[x]) { ::AfxMessageBox("memory problem!"); exit(1); }
	}
	weight_h_o = new double * [hidden_array_size];
	if(!weight_h_o) { ::AfxMessageBox("memory problem!"); exit(1); }
	for(x=0; x<hidden_array_size; x++)
	{
		weight_h_o[x] = new double [output_array_size];
		if(!weight_h_o[x]) { ::AfxMessageBox("memory problem!"); exit(1); }
	}

	errorsignal_hidden = new double [hidden_array_size];
	if(!errorsignal_hidden) { ::AfxMessageBox("memory problem!"); exit(1); }
	errorsignal_output = new double [output_array_size];
	if(!errorsignal_output) { ::AfxMessageBox("memory problem!"); exit(1); }
	return;
}

void CTestDoc::clear_memory()
{	
	int x;
	for(x=0; x<number_of_input_patterns; x++)
	{
		delete [] input[x];
	}
	delete [] input;

	for (x=0; x<number_of_input_patterns; x++)
	{
		delete [] hidden[x];
	}
	delete [] hidden;

	for(x=0; x<number_of_input_patterns; x++)
	{
		delete [] output[x];
	}
	delete [] output;

	for(x=0; x<number_of_input_patterns; x++)
	{
		delete [] target[x];
	}
	delete [] target;

	delete [] bias;

	for(x=0; x<input_array_size; x++)
	{
		delete [] weight_i_h[x];
	}
	delete [] weight_i_h;

	for(x=0; x<hidden_array_size; x++)
	{
		delete [] weight_h_o[x];
	}
	delete [] weight_h_o;

	delete [] errorsignal_hidden;
	
	delete [] errorsignal_output;
	file_loaded = FALSE;
	return;
}


void CTestDoc::OnMenuLearn() 
{
	// TODO: Add your command handler code here
	ofstream out(BIAS_FILE);
	BOOL success = FALSE;
	total = 0;

	dispmode = 2;
	UpdateAllViews(NULL);
	register int y;
	notkeyhit = TRUE;
	while(notkeyhit) 
	{
		for(y=0; y<number_of_input_patterns; y++) 
		{
			forward_pass(y);
		}
	
		if(compare_output_to_target())
		{
			success = TRUE;
			break;
		}
		else
		{
			backward_pass(out);
			total++;
		}

		MSG message;
		if (::PeekMessage(&message,NULL,0,0,PM_REMOVE))
		{
			::TranslateMessage(&message);
			::DispatchMessage(&message);
		}
	}
	dispmode = 0;
	UpdateAllViews(NULL);

	out.close();
	ofstream out_e(BIASNUM_FILE);
	out_e << total;
	out_e.close();
	if (success)
	{
		::AfxMessageBox("Learning successful");
		data_learned = TRUE;
	}
	else
	{
		::AfxMessageBox("Learning not successful yet");
	}
	return;
}

void CTestDoc::forward_pass(int pattern)
{
	_control87 (MCW_EM, MCW_EM);
	register double temp=0;
	register int x,y;

// INPUT -> HIDDEN
	for(y=0; y<hidden_array_size; y++) 
	{
		for(x=0; x<input_array_size; x++) {
			temp += (input[pattern][x] * weight_i_h[x][y]); //∑Wi*Xi
		}
		hidden[pattern][y] = (1.0 / (1.0 + exp(-1.0 * (temp + bias[y]))));//1/(1+e^(-uj)); uj=∑Wi*Xi - θj
		temp = 0;                                                //各隱層結點的輸出
	}

// HIDDEN -> OUTPUT
	for(y=0; y<output_array_size; y++) {	//有output_array_size個輸出結點
		for(x=0; x<hidden_array_size; x++) {
			temp += (hidden[pattern][x] * weight_h_o[x][y]);
		}
		output[pattern][y] = (1.0 / (1.0 + exp(-1.0 * (temp + bias[y + hidden_array_size]))));
		temp = 0;
	}
	return;
}

void CTestDoc::backward_pass(ofstream& f_out)
{
	register int x, y, p;
	register double temp = 0;
	double e = 0;
	for (p=0; p<number_of_input_patterns; p++)
	{
	// COMPUTE ERRORSIGNAL FOR OUTPUT UNITS
		for(x=0; x<output_array_size; x++) {
			errorsignal_output[x] = (target[p][x]-output[p][x]);//(t-y)
			e += errorsignal_output[x] * errorsignal_output[x];	//e = (∑(t-y)^2)
			errorsignal_output[x] *= output[p][x] * (1-output[p][x]);//δ= y*(1-y)*(t-y)	
		}
	
	// COMPUTE ERRORSIGNAL FOR HIDDEN UNITS
		for(x=0; x<hidden_array_size; x++) {
			for(y=0; y<output_array_size; y++) { 
				temp += (errorsignal_output[y] * weight_h_o[x][y]);
			}
			errorsignal_hidden[x] = hidden[p][x] * (1-hidden[p][x]) * temp;//Xk*(1-Xk)∑δ*W
			temp = 0.0;
		}

	// ADJUST WEIGHTS OF CONNECTIONS FROM HIDDEN TO OUTPUT UNITS
		double length = 0.0;
		for (x=0; x<hidden_array_size; x++) {
			length += hidden[p][x]*hidden[p][x];
		}
		if (length<=0.1) length = 0.1;
		for(x=0; x<hidden_array_size; x++) {
			for(y=0; y<output_array_size; y++) {
				weight_h_o[x][y] += (learning_rate * errorsignal_output[y] * hidden[p][x]/length);
			}
		}

	// ADJUST BIASES OF HIDDEN UNITS
		for(x=hidden_array_size; x<bias_array_size; x++) {
			bias[x] += (learning_rate * errorsignal_output[x] / length);
		}

	// ADJUST WEIGHTS OF CONNECTIONS FROM INPUT TO HIDDEN UNITS
		length = 0.0;
		for (x=0; x<input_array_size; x++) 
		{
			length += input[p][x]*input[p][x];
		}
		if (length<=0.1) length = 0.1;
		for(x=0; x<input_array_size; x++)
		{                     
			for(y=0; y<hidden_array_size; y++) 
			{
				weight_i_h[x][y] += (learning_rate * errorsignal_hidden[y] * input[p][x]/length);
			}
		}

	// ADJUST BIASES FOR OUTPUT UNITS
		for(x=0; x<hidden_array_size; x++) {
			bias[x] += (learning_rate * errorsignal_hidden[x] / length);
		}
	}
	e /= 2.0;
	f_out << e << endl;
	return;
}

int CTestDoc::compare_output_to_target()
{
	register int y,z;
	register double temp, error = 0.0;
	temp = target[ytemp][ztemp] - output[ytemp][ztemp];//(t-y)<ε
	if (temp < 0) error -= temp;
	else error += temp;
	if(error > max_error_tollerance) return 0;
	error = 0.0;
	for(y=0; y < number_of_input_patterns; y++) {
		for(z=0; z < output_array_size; z++) {
			temp = target[y][z] - output[y][z];
			if (temp < 0) error -= temp;
			else error += temp;
			if(error > max_error_tollerance) {
				ytemp = y;
				ztemp = z;
				return 0;
			}
			error = 0.0;
		}
	}
	return 1;
}

void CTestDoc::OnMenuNewfile() 
{
	// TODO: Add your command handler code here
	CFileDialog dlg_save(FALSE,"txt","*.txt");
	if (dlg_save.DoModal()==IDOK)
	{
		CDataInput dlg_d_input;
		CValueInput dlg_v_input;
		if (dlg_d_input.DoModal() == IDOK)
		{
			int x, y, mode;
			int bias_array_size, input_array_size, hidden_array_size, output_array_size;
			double inpx, val;
			CString str_in,str_tar;
	
			can_learn = FALSE;
			data_learned = FALSE;
		
			ofstream out(dlg_save.GetPathName());
			if (!out)
			{
				::AfxMessageBox("Can not open the file");
				return;
			}

			input_array_size = dlg_d_input.m_nInput;
			hidden_array_size = dlg_d_input.m_nHidden;
			output_array_size = dlg_d_input.m_nOut;
			inpx = dlg_d_input.m_dLearn;
			mode = dlg_d_input.m_nMode;
			bias_array_size = hidden_array_size + output_array_size;
	
			out << input_array_size << endl;
			out << hidden_array_size << endl;
			out << output_array_size << endl;
			out << inpx << endl;
			out << mode << endl << endl;

			srand((unsigned)time(NULL));
			for(x=0; x<bias_array_size; x++) 
			{	
				out << (double)(rand()-10000)/RAND_MAX << ' ';
			}
			out << endl << endl;
			for(x=0; x<input_array_size; x++) {//Weight Input->Hidden
				for(y=0; y<hidden_array_size; y++) 
				{
					out << (double)(rand()-10000)/RAND_MAX << ' ';
				}
			}
			out << endl << endl;
			for(x=0; x<hidden_array_size; x++) {//Weight Hidden->Output
				for(y=0; y<output_array_size; y++) 
				{
					out << (double)(rand()-10000)/RAND_MAX << ' ';
				}
			}
			out << endl << endl;
		
			ofstream output("tmp_1011.txt");
			if (!output)
			{
				::AfxMessageBox("Can not open the tmeporary file");
				return;
			}
	
			for (count = 1; count <=mode; count+=dlg_v_input.delta)
			{
				 if(dlg_v_input.DoModal()==IDOK)
				{
					str_in = dlg_v_input.m_strInput;
					str_tar = dlg_v_input.m_strTarget;
					out << str_in << endl;
					output << str_tar << endl;

				}
			}
			output.close();
			out << endl;
			ifstream f_input("tmp_1011.txt");
			for (count=1; count<=mode; count++)
			{
				for (x=0; x<output_array_size; x++)
				{
					f_input >> val;
					out << val << ' ';;
				}
				out << endl;
			}
			f_input.close();
			out.close();
			CFile::Remove("tmp_1011.txt");
		}
	}
}


void CTestDoc::OnMenuTest() 
{
	// TODO: Add your command handler code here
	CMyTestDlg dlg_test;
	if (dlg_test.DoModal()==IDOK)
	{
		selpattern = dlg_test.m_nModeNum-1;
		TRACE("\nselPATTERN=%d\n",selpattern);
		forward_pass(selpattern);
		dispmode = 1;
	    UpdateAllViews(NULL);
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
老司机午夜精品99久久| 在线中文字幕不卡| 91女人视频在线观看| 欧美日韩国产三级| 中文字幕国产一区二区| 日日夜夜精品视频免费| 91看片淫黄大片一级| 久久色在线观看| 伦理电影国产精品| 欧美日韩日日夜夜| 亚洲精品日韩专区silk | 2021久久国产精品不只是精品| **网站欧美大片在线观看| 麻豆一区二区三| 欧美日韩国产片| 亚洲国产精品综合小说图片区| 成人精品gif动图一区| 精品美女在线观看| 日韩av在线免费观看不卡| 欧美自拍偷拍午夜视频| 玉米视频成人免费看| 波多野结衣91| 国产精品家庭影院| 懂色av一区二区三区免费看| 精品国产免费一区二区三区四区| 丝袜美腿高跟呻吟高潮一区| 欧美日韩国产高清一区| 一区二区成人在线| 色国产精品一区在线观看| 亚洲欧洲无码一区二区三区| 不卡免费追剧大全电视剧网站| 国产精品久久久久久久第一福利| 大白屁股一区二区视频| 欧美国产精品中文字幕| 成人午夜av在线| 亚洲精品一区二区三区福利| 久久99精品国产91久久来源| 久久五月婷婷丁香社区| 成人sese在线| 亚洲欧美一区二区三区久本道91| 色哟哟在线观看一区二区三区| 亚洲欧美激情在线| 欧美午夜精品免费| 欧美96一区二区免费视频| 日韩精品一区二区三区三区免费 | 7878成人国产在线观看| 污片在线观看一区二区| 7777精品伊人久久久大香线蕉 | 国产成人免费9x9x人网站视频| 久久久午夜精品理论片中文字幕| 国产99久久久久| 亚洲欧美视频在线观看| 欧美影院一区二区三区| 裸体一区二区三区| 中文字幕乱码一区二区免费| 一本大道av伊人久久综合| 婷婷综合另类小说色区| 精品福利在线导航| 99re热这里只有精品视频| 午夜精品久久久久久久久久| 久久女同精品一区二区| 91麻豆国产自产在线观看| 五月天婷婷综合| 国产精品嫩草99a| 欧美网站一区二区| 国产真实乱偷精品视频免| 国产精品成人免费精品自在线观看| 欧美无乱码久久久免费午夜一区| 精品一区二区三区的国产在线播放 | 成人成人成人在线视频| 亚洲电影第三页| 欧美国产一区视频在线观看| 欧美日韩免费一区二区三区| 国内精品第一页| 亚洲国产日韩一级| 中文字幕亚洲精品在线观看| 91精品国产乱| 欧美性猛交xxxx黑人交| 国产福利一区在线观看| 亚洲1区2区3区视频| 亚洲国产成人在线| 日韩精品综合一本久道在线视频| av成人动漫在线观看| 国产综合久久久久久久久久久久| 亚洲小少妇裸体bbw| 中文一区二区在线观看| 日韩精品自拍偷拍| 欧美巨大另类极品videosbest | 成人黄色免费短视频| 视频一区视频二区中文字幕| 国产精品麻豆久久久| 欧美r级电影在线观看| 欧美日免费三级在线| 波多野结衣中文字幕一区二区三区| 日本成人在线不卡视频| 一区二区免费在线| 综合色中文字幕| 国产欧美综合在线观看第十页| 欧美电影免费提供在线观看| 欧美军同video69gay| 欧美日韩在线综合| 在线观看日韩精品| av欧美精品.com| 成人美女视频在线观看18| 国内外成人在线| 美女视频黄免费的久久| 男人操女人的视频在线观看欧美 | 日韩小视频在线观看专区| 欧美专区日韩专区| 色综合久久久网| 91在线视频网址| 91老师国产黑色丝袜在线| 99久久综合精品| 99视频超级精品| 91福利精品第一导航| 色偷偷88欧美精品久久久 | 波多野结衣欧美| 99久久精品一区二区| 成人免费av在线| 91丨国产丨九色丨pron| 91豆麻精品91久久久久久| 色哟哟一区二区三区| 在线观看中文字幕不卡| 欧美色图12p| 欧美精品777| 精品处破学生在线二十三| 日韩精品综合一本久道在线视频| 久久久久久夜精品精品免费| 国产日本欧洲亚洲| 亚洲欧洲av另类| 亚洲自拍与偷拍| 麻豆高清免费国产一区| 国产福利一区二区三区在线视频| caoporm超碰国产精品| 在线国产电影不卡| 精品久久人人做人人爱| 国产欧美视频一区二区| 亚洲免费色视频| 青娱乐精品视频| 成人一区二区三区视频在线观看| 色综合视频一区二区三区高清| 欧美精品乱码久久久久久| 久久午夜免费电影| 亚洲黄一区二区三区| 另类的小说在线视频另类成人小视频在线| 国产精品1区二区.| 欧美色欧美亚洲另类二区| 久久免费美女视频| 亚洲免费观看高清在线观看| 日本午夜精品一区二区三区电影| 国产丶欧美丶日本不卡视频| 欧美性猛交xxxxxxxx| 国产色爱av资源综合区| 亚洲线精品一区二区三区八戒| 久久国内精品自在自线400部| 成人不卡免费av| 欧美成人伊人久久综合网| 亚洲裸体xxx| 九色|91porny| 欧美图区在线视频| 国产精品久久久久久久蜜臀| 日本三级韩国三级欧美三级| 99r精品视频| 久久伊99综合婷婷久久伊| 一区二区三区资源| 国产91丝袜在线播放0| 欧美久久久久免费| 亚洲色图在线播放| 国内精品第一页| 欧美一区二区三区视频免费| 亚洲九九爱视频| 国产盗摄精品一区二区三区在线| 4438x成人网最大色成网站| 一区二区三区在线免费播放| 国产成人午夜高潮毛片| 5566中文字幕一区二区电影| 亚洲三级久久久| 成人免费视频免费观看| 欧美v国产在线一区二区三区| 亚洲成人免费在线观看| 一本一道波多野结衣一区二区| 国产亚洲一区字幕| 国内精品久久久久影院一蜜桃| 正在播放一区二区| 午夜欧美视频在线观看| 欧美系列一区二区| 一区二区三区在线免费视频| 91香蕉视频mp4| 国产精品女人毛片| 成人午夜精品在线| 久久精品夜色噜噜亚洲aⅴ| 久久9热精品视频| 日韩一级片网站| 日本不卡123| 日韩一区二区三| 久久狠狠亚洲综合| 久久一夜天堂av一区二区三区| 国产自产视频一区二区三区| 精品处破学生在线二十三| 国产麻豆日韩欧美久久|