📄 main.cpp
字号:
//main.cpp
//主程序
#include <iostream.h>
#include "bpnet.h"
#include "backprop.h"
#include "string.h"
//#include "dib.h"
//#include "Afx.h"
#define BPM_ITER 10000//迭代次数
//CDib m_Dib;
//HBITMAP m_hBitmap;
//void LoadBMP(CString strPath)
//{
// if(!m_Dib.LoadFromFile(strPath)) return;
// m_hBitmap = (HBITMAP)::LoadImage(NULL,strPath,
// IMAGE_BITMAP,
// m_Dib.GetDibWidth(),
// m_Dib.GetDibHeight(),
// LR_LOADFROMFILE | LR_CREATEDIBSECTION);//| LR_DEFAULTSIZE
// if(m_hBitmap){
// ::GetBitmapBits(m_hBitmap,m_Dib.GetDibHeight() * m_Dib.GetDibWidth(),m_Dib.pDIBData);
// memcpy(m_Dib.pDIBDeal,m_Dib.pDIBData,sizeof(m_Dib.pDIBData));
// // Invalidate();
// // GetParent()->SetWindowText(strPath);
// }
// else
// MessageBox("装载位图失败!","出错提示",MB_OK | MB_ICONWARNING);
//}
void main() {
CBPNet bp;
for (int i=0;i<BPM_ITER;i++) {
bp.Train(0,0,0);
bp.Train(0,1,1);
bp.Train(1,0,1);
bp.Train(1,1,0);
}
cout << "0,0 = " << bp.Run(0,0) << endl;
cout << "0,1 = " << bp.Run(0,1) << endl;
cout << "1,0 = " << bp.Run(1,0) << endl;
cout << "1,1 = " << bp.Run(1,1) << endl;
//
// //载入位图
// // m_StrPath = strPath;
//// int index;
//// CString strPath;
// double learnSpeed = 0.5; //学习速率
// double mc = 0.95; //动量因子
// double eo, eh; //输出误差
// double sample1[3] = {1.0, 0.0, 0.0}, sample2[3] = {1.0, 0.0, 1.0};
// double a1[3] = {1.0, 1.0, 1.0}, a2[3] = {1.0, 1.0, 0.0};
// double result1[3] = {1.0, 1.0, 0.0}, result2[3] = {1.0, 0.0, 1.0};
// bpnn_initialize(1);
// BPNN *pNet = bpnn_create(2, 10, 2);
// //训练
// for (int i=0; i<BPM_ITER; i++)
// {
// //随机产生0 - 9的随机数
// // index = int(drnd()*10);
// // strPath.Format("\\sample\%d.bmp", index);
// // LoadBMP(strPath);
// memcpy(pNet->input_units, sample1, 3*sizeof(double));
// memcpy(pNet->target, result1, 3*sizeof(double));
// bpnn_train(pNet, learnSpeed, mc, &eo, &eh);
//
// memcpy(pNet->input_units, sample2, 3*sizeof(double));
// memcpy(pNet->target, result2, 3*sizeof(double));
// bpnn_train(pNet, learnSpeed, mc, &eo, &eh);
//
// memcpy(pNet->input_units, a1, 3*sizeof(double));
// memcpy(pNet->target, result1, 3*sizeof(double));
// bpnn_train(pNet, learnSpeed, mc, &eo, &eh);
//
// memcpy(pNet->input_units, a2, 3*sizeof(double));
// memcpy(pNet->target, result2, 3*sizeof(double));
// bpnn_train(pNet, learnSpeed, mc, &eo, &eh);
//
// }
// //识别
//// double a1[3] = {1.0, 1.0, 1.0}, a2[3] = {1.0, 1.0, 0.0};
////
//// pNet->input_units = (1, 1);
// memcpy(pNet->input_units, sample1, 3*sizeof(double));
// bpnn_feedforward(pNet);
// cout << "1,1 = " << pNet->output_units[1] << endl;
// cout << "1,1 = " << pNet->output_units[2] << endl;
// memcpy(pNet->input_units, a2, 3*sizeof(double));
// bpnn_feedforward(pNet);
// cout << "1,0 = " << pNet->output_units[1] << endl;
// cout << "1,0 = " << pNet->output_units[2] << endl;
// bpnn_free(pNet);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -