simplenet.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 "CUniformRNG.h"
00007
00008 using namespace std;
00009 using namespace gplib;
00010
00011 int main()
00012 {
00013
00014 const int seglength = 100;
00015 const double maxinit = 0.01;
00016 const double maxbias = 0.01;
00017 const int maxit = 1000;
00018 const int hiddenlayers = 2;
00019 const double mu = 0.1;
00020
00021 ttypeVector typeVector;
00022 ttypeArray typeArray;
00023 ifstream inputfile, reffile;
00024 ofstream outputfile, epsfile;
00025
00026 double currentinput, currentref;
00027
00028 string inputfilename, reffilename;
00029 string outputfilename, epsfilename;
00030
00031 cout << "Inputfile: ";
00032 cin >> inputfilename;
00033 cout << "Referencefile:";
00034 cin >> reffilename;
00035 outputfilename = inputfilename + ".clean";
00036 epsfilename = inputfilename + ".eps";
00037 inputfile.open(inputfilename.c_str());
00038 reffile.open(reffilename.c_str());
00039 epsfile.open(epsfilename.c_str());
00040 outputfile.open(outputfilename.c_str());
00041
00042 typeVector.assign(seglength, bipolar);
00043 for (int i = 0; i < hiddenlayers; ++i)
00044 {
00045 typeArray.push_back(typeVector);
00046 }
00047
00048 typeVector.assign(1, identity);
00049 typeArray.push_back(typeVector);
00050
00051 NeuralNetwork Network;
00052 Network.Input.assign(seglength, 0);
00053 Network.SetLayers(typeArray);
00054 Network.InitWeights(maxinit, maxbias);
00055 Network.mu = mu;
00056 for (int i = 0; i < seglength; ++i)
00057 {
00058 inputfile >> currentinput;
00059 Network.Input.at(i) = currentinput;
00060 }
00061 reffile >> currentref;
00062 Network.Desired.at(0) = currentref;
00063 Network.CalcOutput();
00064 Network.AdaptWeights();
00065
00066
00067 for (int iterations = 0; iterations < maxit; ++iterations)
00068 {
00069
00070 inputfile >> currentinput;
00071 reffile >> currentref;
00072
00073 rotate(Network.Input.begin(), Network.Input.begin() + 1,
00074 Network.Input.end());
00075 Network.Input.back() = currentinput;
00076
00077 Network.Desired.at(0) = currentref;
00078 Network.CalcOutput();
00079 Network.AdaptWeights();
00080
00081 outputfile << Network.Output.at(0) << endl;
00082 epsfile << (Network.Desired.at(0) - Network.Output.at(0)) << endl;
00083 }
00084 inputfile.close();
00085 reffile.close();
00086 outputfile.close();
00087 epsfile.close();
00088
00089 }