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         //eyoutput.open(eyoutfilename.c_str());
00054         
00055         typeVector.assign(seglength*2,bipolar);
00056         for (int i = 0; i < hlayers; ++i)
00057         {
00058                 exoutput << 0 << endl;
00059                 //eyoutput << 0 << endl;
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         //Network.Input.assign(seglength,0);
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         /*cout << "Input: ";
00085         for (int i = 0; i < Network.Input.size(); ++i)
00086                 cout << Network.Input.at(i) << " ";
00087         cout << endl;
00088         cout << "Desired: ";
00089         for (int i = 0; i < Network.Desired.size(); ++i)
00090                 cout << Network.Desired.at(i) << " ";
00091         cout << endl;
00092         cout << "Weights: " << endl;
00093         for (int i = 0; i < typeArray.size(); ++i)
00094         {
00095                 cout << "Layer: " << i << endl;
00096                 for (int j = 0; j < typeArray.at(i).size(); ++j)
00097                 {
00098                         cout << "Neuron: " << j << endl;
00099                         cout << "Weights: " << endl;
00100                         for (int k = 0; k < Network.Layers.at(i).at(j)->Combiner->Weights.size(); ++k)
00101                                 cout << Network.Layers.at(i).at(j)->Combiner->Weights.at(k) << " ";
00102                         cout << endl;
00103                         cout << "Bias: " << Network.Layers.at(i).at(j)->Combiner->Bias << endl;
00104                 }
00105                 cout << endl;
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         /*cout << "Output: ";
00134         for (int i = 0; i < Network.Output.size(); ++i)
00135                 cout << Network.Output.at(i) << " ";
00136         cout << endl << endl;*/
00137         
00138         /*cout << "Delta: " << endl;
00139         for (int i = 0; i < typeArray.size(); ++i)
00140         {
00141                 cout << "Layer: " << i << endl;
00142                 for (int j = 0; j < typeArray.at(i).size(); ++j)
00143                 {
00144                         cout << "Neuron: " << j << endl;
00145                         cout << "Delta: " << Network.Layers.at(i).at(j)->Delta << endl;
00146                         cout << "Net: " << Network.Layers.at(i).at(j)->Net << endl;
00147                         cout << "Output: " << Network.Layers.at(i).at(j)->Output << endl;
00148                 }
00149                 cout << endl;
00150         }*/
00151                 exoutput << Network.Output.at(0) <<endl ;
00152                 //eyoutput << Network.Output.at(1) <<endl;
00153                 exepsfile << (Network.Desired.at(0) - Network.Output.at(0)) << endl;
00154                 //eyepsfile << (Network.Desired.at(1) - Network.Output.at(1)) << endl;
00155         }
00156         hxfile.close();
00157         exfile.close();
00158         eyfile.close();
00159         hyfile.close();
00160         exepsfile.close();
00161         eyepsfile.close();
00162         exoutput.close();
00163         //eyoutput.close();
00164 }

Generated on Tue Aug 4 16:04:05 2009 for GPLIB++ by  doxygen 1.5.8