Skip to content

Commit

Permalink
wuuu
Browse files Browse the repository at this point in the history
  • Loading branch information
Cachey4467 committed Dec 14, 2018
1 parent 9625a36 commit 3bbc809
Show file tree
Hide file tree
Showing 22 changed files with 346 additions and 60 deletions.
Binary file modified .vs/Nerve/v14/.suo
Binary file not shown.
10 changes: 10 additions & 0 deletions Nerve.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Nerve", "Nerve\Nerve.vcxpro
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Reform_TrainingData", "Reform_TrainingData\Reform_TrainingData.vcxproj", "{EF1B4ECE-FA22-49BD-B4C9-660088459C51}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Train", "Train\Train.vcxproj", "{CC43A4BC-E8D8-425B-954B-3B98D4AE6155}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand All @@ -31,6 +33,14 @@ Global
{EF1B4ECE-FA22-49BD-B4C9-660088459C51}.Release|x64.Build.0 = Release|x64
{EF1B4ECE-FA22-49BD-B4C9-660088459C51}.Release|x86.ActiveCfg = Release|Win32
{EF1B4ECE-FA22-49BD-B4C9-660088459C51}.Release|x86.Build.0 = Release|Win32
{CC43A4BC-E8D8-425B-954B-3B98D4AE6155}.Debug|x64.ActiveCfg = Debug|x64
{CC43A4BC-E8D8-425B-954B-3B98D4AE6155}.Debug|x64.Build.0 = Debug|x64
{CC43A4BC-E8D8-425B-954B-3B98D4AE6155}.Debug|x86.ActiveCfg = Debug|Win32
{CC43A4BC-E8D8-425B-954B-3B98D4AE6155}.Debug|x86.Build.0 = Debug|Win32
{CC43A4BC-E8D8-425B-954B-3B98D4AE6155}.Release|x64.ActiveCfg = Release|x64
{CC43A4BC-E8D8-425B-954B-3B98D4AE6155}.Release|x64.Build.0 = Release|x64
{CC43A4BC-E8D8-425B-954B-3B98D4AE6155}.Release|x86.ActiveCfg = Release|Win32
{CC43A4BC-E8D8-425B-954B-3B98D4AE6155}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
106 changes: 53 additions & 53 deletions Nerve/Nerve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,56 +274,56 @@ namespace Nerve
}
using namespace Nerve;

int main()
{
//Nerve_net net(4, 3, vector<int>{3,4});
Nerve_net net("a.nerve");//从文件读入

int o = 30000;
default_random_engine e(GetTickCount());/*初始化随机引擎*/
uniform_int_distribution<int> u(0,2);
while (o--)
{
if (u(e) == 0)
{
net.Input(vector<double>{1, 1, 0, 0});
net.Set_Desired_output(vector<double>{1, 0, 0});
net.Figue();
net.Train();
}
else if (u(e) == 1)
{
net.Input(vector<double>{0, 1, 1, 0});
net.Set_Desired_output(vector<double>{0, 1, 0});
net.Figue();
net.Train();
}
else
{
net.Input(vector<double>{0, 0, 1, 1});
net.Set_Desired_output(vector<double>{0, 0, 1});
net.Figue();
net.Train();
}

net.Input(vector<double>{1, 1, 1, 1});
net.Set_Desired_output(vector<double>{1, 1, 1});
net.Figue();
net.Train();

}
//教会它识别01
net.Input(vector<double>{1,0.5,0,0.0});
net.Figue();
vector<double> oo = net.Output();
for (int i = 0; i < oo.size(); i++)
std::cout << oo[i] << " ";
std::cout << endl;
net.Input(vector<double>{0,0.60,1.0,0.00});
net.Figue();
vector<double> ooo = net.Output();
for (int i = 0; i < ooo.size(); i++)
std::cout << ooo[i] << " ";

//net.SaveTofile("a.nerve");//保存到文件
}
//int main()
//{
// //Nerve_net net(4, 3, vector<int>{3,4});
// Nerve_net net("a.nerve");//从文件读入
//
// int o = 30000;
// default_random_engine e(GetTickCount());/*初始化随机引擎*/
// uniform_int_distribution<int> u(0,2);
// while (o--)
// {
// if (u(e) == 0)
// {
// net.Input(vector<double>{1, 1, 0, 0});
// net.Set_Desired_output(vector<double>{1, 0, 0});
// net.Figue();
// net.Train();
// }
// else if (u(e) == 1)
// {
// net.Input(vector<double>{0, 1, 1, 0});
// net.Set_Desired_output(vector<double>{0, 1, 0});
// net.Figue();
// net.Train();
// }
// else
// {
// net.Input(vector<double>{0, 0, 1, 1});
// net.Set_Desired_output(vector<double>{0, 0, 1});
// net.Figue();
// net.Train();
// }
//
// net.Input(vector<double>{1, 1, 1, 1});
// net.Set_Desired_output(vector<double>{1, 1, 1});
// net.Figue();
// net.Train();
//
// }
// //教会它识别01
// net.Input(vector<double>{1,0.5,0,0.0});
// net.Figue();
// vector<double> oo = net.Output();
// for (int i = 0; i < oo.size(); i++)
// std::cout << oo[i] << " ";
// std::cout << endl;
// net.Input(vector<double>{0,0.60,1.0,0.00});
// net.Figue();
// vector<double> ooo = net.Output();
// for (int i = 0; i < ooo.size(); i++)
// std::cout << ooo[i] << " ";
//
// //net.SaveTofile("a.nerve");//保存到文件
//}
Binary file added Reform_TrainingData/export.exam
Binary file not shown.
Binary file added Reform_TrainingData/export.train
Binary file not shown.
14 changes: 9 additions & 5 deletions Reform_TrainingData/reform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,20 @@ class Builder

bool end = false;
int count = 0;
int lis[10] = { 0,1,2,3,4,5,6,7,8,9 };
while (!end)
{
for (int i = 0; i<10; i++)//随机1-9的输出顺序
swap(lis[i], lis[rand() % 10]);
end = true;
for (int i = 0; i < 10; i++)
{
end=true;
if(count<data[i].size())
out.write((char*)&data[i][count], sizeof(Data)),end=false;
if (count<data[lis[i]].size())
out.write((char*)&data[lis[i]][count], sizeof(Data)), end = false;
}
count++;
}
out.close();
}
private:
ifstream in;
Expand All @@ -93,8 +97,8 @@ class Builder
};
int main()
{
Builder r("train-images.idx3-ubyte","train-labels.idx1-ubyte");
Builder r("t10k-images.idx3-ubyte","t10k-labels.idx1-ubyte");
r.wan();
r.Export("export.txt");
r.Export("export.exam");
return 0;
}
Binary file added Reform_TrainingData/t10k-images.idx3-ubyte
Binary file not shown.
Binary file added Reform_TrainingData/t10k-labels.idx1-ubyte
Binary file not shown.
Binary file added Reform_TrainingData/train-images.idx3-ubyte
Binary file not shown.
Binary file added Reform_TrainingData/train-labels.idx1-ubyte
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
9 changes: 7 additions & 2 deletions Reform_TrainingData/x64/Release/Reform_TrainingData.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
 reform.cpp
reform.cpp(54): warning C4267: “参数”: 从“size_t”转换到“int”,可能丢失数据
MSVCRT.lib(exe_main.obj) : error LNK2001: 无法解析的外部符号 main
E:\我的 东东\EasyX学习\深度学习\Nerve_Net\x64\Release\Reform_TrainingData.exe : fatal error LNK1120: 1 个无法解析的外部命令
正在生成代码
4 of 236 functions ( 1.7%) were compiled, the rest were copied from previous compilation.
0 functions were new in current compilation
4 functions had inline decision re-evaluated but remain unchanged
已完成代码的生成
Reform_TrainingData.vcxproj -> E:\我的 东东\EasyX学习\深度学习\Nerve_Net\x64\Release\Reform_TrainingData.exe
Reform_TrainingData.vcxproj -> E:\我的 东东\EasyX学习\深度学习\Nerve_Net\x64\Release\Reform_TrainingData.pdb (Full PDB)
Binary file modified Reform_TrainingData/x64/Release/vc140.pdb
Binary file not shown.
91 changes: 91 additions & 0 deletions Train/Train.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include<iostream>
#include<fstream>
#include<vector>
#include"..//Nerve//Nerve.cpp"
#include<windows.h>
using namespace std;
/*
单体数据结构
*/
#define N 28
struct Train
{
int train_times; //训练次数

int exam_times; //测试次数

int exam_A; //正确样本数
int exam_W; //错误样本数

Nerve_net &nerve; //训练神经网络
char Nerve_ID[16]; //神经网络ID
struct Data
{
char point[N * N];
char ans;
};

public:
Train(Nerve_net &i):nerve(i)
{
}
void train(char *file)
{
ifstream in(file,ios::binary);
Data data;
vector<double> vec(N*N,0.0);
vector<double> outp(10,0.0);
while(1)
{
in.read((char*)&data,sizeof(data));
if(in.gcount()!=0)
{
for(int i=0;i<N*N;i++)
vec[i]=data.point[i];
outp[data.ans]=1.0;
nerve.Input(vec);
nerve.Set_Desired_output(outp);
nerve.Figue();
nerve.Train();

train_times++;
}
else break;
}
}
void exam(char *file)
{
ifstream in(file,ios::binary);
Data data;
vector<double> vec(N*N,0.0);
vector<double> ans(10,0.0);
while(1)
{
in.read((char*)&data,sizeof(data));
if(in.gcount()!=0)
{
for(int i=0;i<N*N;i++)
vec[i]=data.point[i];
nerve.Input(vec);
nerve.Figue();
ans=nerve.Output();
double maxx=0;
int k=0;
for(int i=0;i<10;i++)
if(maxx<ans[i])
maxx=ans[i],k=i;
if(k==data.ans)exam_A++;
else exam_W++;
}
else break;
}
}
void output_statistic(ostream &out)
{
}
};
int main()
{

return 0;
}
Loading

0 comments on commit 3bbc809

Please sign in to comment.