allnet.cpp
Go to the documentation of this file.00001 #include "NeuralNetwork.h"
00002 #include <iostream>
00003 #include <vector>
00004 #include <fstream>
00005 #include <string>
00006 #include "CNeuralConfig.h"
00007 #include "CUniformRNG.h"
00008 using namespace std;
00009
00010 int main()
00011 {
00012 CNeuralConfig Configuration;
00013 ttypeVector typeVector;
00014 ttypeArray typeArray;
00015 ifstream exfile,eyfile,hxfile,hyfile;
00016 ofstream exoutput,eyoutput,exepsfile,eyepsfile;
00017
00018 double currentex, currentey, currenthx, currenthy;
00019
00020 string exfilename,eyfilename,hxinfilename,hyinfilename,exoutfilename,eyoutfilename,hxoutfilename,hyoutfilename;
00021 string exepsfilename, eyepsfilename;
00022
00023 Configuration.GetData("neural.conf");
00024 const int seglength = Configuration.seglength;
00025 const double maxinit = Configuration.maxinit;
00026 const int maxit = Configuration.maxit;
00027 const int hlayers = Configuration.hiddenlayers;
00028 vector<double> ex(seglength,0),ey(seglength,0), hx(seglength,0), hy(seglength,0);
00029
00030 cout << "Datafile 1: ";
00031 cin >> exfilename;
00032 cout << "Datafile 2: ";
00033 cin >> eyfilename;
00034 cout << "Datafile 3: ";
00035 cin >> hxoutfilename;
00036 cout << "Datafile 4: ";
00037 cin >> hyoutfilename;
00038 cout << "Referencefile 1:";
00039 cin >> hxinfilename;
00040 cout << "Referencefile 2:";
00041 cin >> hyinfilename;
00042 exoutfilename = exfilename+".clean";
00043 eyoutfilename = eyfilename+".clean";
00044 exepsfilename = exfilename+".eps";
00045 eyepsfilename = eyfilename+".eps";
00046 exfile.open(exfilename.c_str());
00047 eyfile.open(eyfilename.c_str());
00048 exepsfile.open(exepsfilename.c_str());
00049 eyepsfile.open(eyepsfilename.c_str());
00050 hxfile.open(hxfilename.c_str());
00051 hyfile.open(hyfilename.c_str());
00052 exoutput.open(exoutfilename.c_str());
00053
00054
00055 typeVector.assign(seglength*2,bipolar);
00056 for (int i = 0; i < hlayers; ++i)
00057 {
00058 exoutput << 0 << endl;
00059
00060 typeArray.push_back(typeVector);
00061 }
00062 typeVector.assign(4,identity);
00063 typeArray.push_back(typeVector);
00064
00065 NeuralNetwork Network;
00066 Network.Input.assign(seglength*2,0);
00067
00068 Network.SetLayers(typeArray);
00069 Network.InitWeights(maxinit,maxinit);
00070 Network.mu = Configuration.mu;
00071 for (int i = 0; i < seglength; ++i)
00072 {
00073 exfile >> currentex;
00074 eyfile >> currentey;
00075 hxfile >> currenthx;
00076 hyfile >> currenthy;
00077 ex.at(i) = currentex;
00078 ey.at(i) = currentey;
00079 hx.at(i) = currenthx;
00080 hy.at(i) = currenthy;
00081 }
00082 for (int iterations = 0; iterations < maxit; ++iterations)
00083 {
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 for (int i = 0; i < seglength; ++i)
00108 {
00109 Network.Input.at(i) = hx.at(i);
00110 Network.Input.at(i+seglength) = hy.at(i);
00111 }
00112 Network.Desired.at(0) = ex.at(0);
00113 Network.Desired.at(1) = ey.at(0);
00114 Network.CalcOutput();
00115 Network.AdaptWeights();
00116
00117 exfile >> currentex;
00118 eyfile >> currentey;
00119 hxfile >> currenthx;
00120 hyfile >> currenthy;
00121
00122 for (int i = 1; i < seglength; ++i)
00123 {
00124 ex.at(i-1) = ex.at(i);
00125 ey.at(i-1) = ey.at(i);
00126 hx.at(i-1) = hx.at(i);
00127 hy.at(i-1) = hy.at(i);
00128 }
00129 ex.back() = currentex;
00130 ey.back() = currentey;
00131 hx.back() = currenthx;
00132 hy.back() = currenthy;
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 exoutput << Network.Output.at(0) <<endl ;
00152
00153 exepsfile << (Network.Desired.at(0) - Network.Output.at(0)) << endl;
00154
00155 }
00156 hxfile.close();
00157 exfile.close();
00158 eyfile.close();
00159 hyfile.close();
00160 exepsfile.close();
00161 eyepsfile.close();
00162 exoutput.close();
00163
00164 }