/*
* 测试环境 vs2008, windows7 32位
* 2016-6-1
* liang1057@163.com
*/
#include <Windows.h>
#include "math.h"
#include<cstdlib>
#include<ctime>
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include "nnBPNet1.h"
bool setProgress(int val, void* bp){
cout << val << " %\r\n";
return true;
}
int main()
{
CoreTextStream tWriter;
int InLayerNodesNum = 1; //输入层节点数
int MidLayerNodesNum = 25; //隐层节点数
int OutLayerNodesNum = 1;
int tLoop = 10000; // 训练次数
cout << "训练次数(10000): \r\n";
cin >> tLoop;
/* 造一组数据进行测试 */
nnBPNet1 myBPNet(InLayerNodesNum, MidLayerNodesNum, OutLayerNodesNum);
const int N=50;
const float Pi=3.1415926;
srand(time(0));
float** a = new float*[N];
float** a2 = new float*[N];
float** a3 = new float*[N];
float** b = new float*[N];
float** b2 = new float*[N];
float** b3 = new float*[N]; //实际结果
float** b3_bp = new float*[N]; //识别结果
for(int i=0; i<N; i++)
{
a[i] = new float[InLayerNodesNum];
a2[i] = new float[InLayerNodesNum];
a3[i] = new float[InLayerNodesNum];
b[i] = new float[OutLayerNodesNum];
b2[i] = new float[OutLayerNodesNum];
b3[i] = new float[OutLayerNodesNum];
b3_bp[i] = new float[OutLayerNodesNum];
}
for(int i=0;i<N;++i)
{
a[i][0]=((2.0*(float)rand()/RAND_MAX)-1)*(Pi/2-1)+1;
a2[i][0]=((2.0*(float)rand()/RAND_MAX)-1)*(Pi/2-1)+1;
a3[i][0]=((2.0*(float)rand()/RAND_MAX)-1)*(Pi/2-1)+1;
b[i][0]=2*sin(a[i][0])-0.7;
b2[i][0]=2*sin(a2[i][0])-0.7;
b3[i][0]=2*sin(a3[i][0])-0.7;
}
myBPNet.train(a,b,N);
myBPNet.train(a2,b2,N);
myBPNet.sim(a3,b3_bp,N);
for(int i=0;i<N;++i)
cout<< a[i][0] << " & " << b3[i][0]<<" -> "<<b3_bp[i][0]<<endl;
return 0;
}