⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 基于神经网络的乒乓球机器人乒乓球轨迹预测代码
💻 CPP
字号:
#include "BackProp.h"
#include <string>
#include <sstream>
#include <fstream>
using namespace std;
#define filesize 500

int main(int argc, char* argv[])
{
	char infilepath[100]="E:\\work\\SRTP\\chenwei\\pwhole4.txt";
	char outfilepath[100]="E:\\work\\SRTP\\chenwei\\0.txt";
	double nfx=30,nfy=200,nfz=100;
	double losex=1,losey=0.6,losez=0.9,height=190,interval=23,compx=0,compy=0;
	int maxlimit=50;
	int numLayers = 4, lSz[4] = {3,20,20,1};   
	// defining a net with 4 layers having 3,3,3, and 1 neuron respectively,
	// the first layer is input layer i.e. simply holder for the input parameters
	// and has to be the same size as the no of input parameters, in out example 3
	//incount用于读取数据行数记录
	
	double beta = 0.3, alpha = 0.1;
	double Threshx =0.00000000001,Threshy =0.0000000000001,Threshz =0.000000000000001;
	long num_iter = 2000;
	// Learing rate - beta
	// momentum - alpha
	// Threshhold - thresh (value of target mse, training stops once it is achieved)				

	// Creating the net
	exfile *ef=new exfile(interval,nfx,nfy,nfz,losex,losey,losez,height,compx,compy);
	CBackProp *bpx = new CBackProp(numLayers, lSz, beta, alpha);
	CBackProp *bpy = new CBackProp(numLayers, lSz, beta, alpha);
	CBackProp *bpz = new CBackProp(numLayers, lSz, beta, alpha);
	
	if(ef->opendata(infilepath))
	{
		for(int i0=1;i0<=5;i0++)
			ef->readdata(infilepath);
	}
	else
		cout<<"open file error!"<<endl;
	
	//training and prodict
	while(!ef->infile.eof())
	{	
		int temp=ef->incount;
		while(!ef->gotit)
		{
			for (int i=0;i<num_iter;i++)
			{	
				bpx->bpgt(ef->traindatax, &ef->traindatax[3]);
				bpy->bpgt(ef->traindatay, &ef->traindatay[3]);
				bpz->bpgt(ef->traindataz, &ef->traindataz[3]);
				
				if((bpx->mse(&ef->traindatax[3])<Threshx)
					&&(bpy->mse(&ef->traindatay[3])<Threshy)
					&&(bpz->mse(&ef->traindataz[3])<Threshz))
					break;	
			}
			bpx->ffwd(ef->predatax);
			bpy->ffwd(ef->predatay);
			bpz->ffwd(ef->predataz);
			ef->update(bpx->Out(0),bpy->Out(0),bpz->Out(0),temp);
			temp++;
			if(temp>maxlimit)
				break;
		}
		ef->gotit=0;
		ef->readdata(infilepath);
	}
	ef->writedata(outfilepath);
	return 0;	
}


⌨️ 快捷键说明

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