seismicnet.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 "UniformRNG.h"
00007 using namespace std;
00008
00009 int main()
00010 {
00011
00012 const int seglength = 3;
00013 const double maxinit = 0.01;
00014 const double maxbias = 0.01;
00015 const int hiddenlayers = 2;
00016 const double mu = 0.1;
00017 const int noiseseglength = 70000;
00018 const int plotintervall = 200;
00019 const double noisepower = 10;
00020 int currentindex = 0;
00021 ttypeVector typeVector;
00022 ttypeArray typeArray;
00023 ifstream datafile, noisefile;
00024 ofstream outputfile,epsfile,weightfile;
00025 UniformRNG Random;
00026
00027 double currentinput, currentref;
00028
00029 string datafilename, noisefilename;
00030 string outputfilename, epsfilename, weightfilename;
00031
00032
00033
00034
00035 cout << "Datafile:";
00036 cin >> noisefilename;
00037 outputfilename = noisefilename+".clean";
00038 epsfilename = noisefilename+".eps";
00039 weightfilename = noisefilename+".weight";
00040 noisefile.open(noisefilename.c_str());
00041
00042 epsfile.open(epsfilename.c_str());
00043 weightfile.open(weightfilename.c_str());
00044 outputfile.open(outputfilename.c_str());
00045
00046 typeVector.assign(seglength,bipolar);
00047 for (int i = 0; i < hiddenlayers; ++i)
00048 {
00049 typeArray.push_back(typeVector);
00050 }
00051 typeVector.assign(1,identity);
00052 typeArray.push_back(typeVector);
00053
00054 NeuralNetwork Network;
00055 Network.Input.assign(seglength,0);
00056 Network.SetLayers(typeArray);
00057 Network.InitWeights(maxinit,maxbias);
00058 Network.mu = mu;
00059 for (int i = 0; i < seglength; ++i)
00060 {
00061 noisefile >> currentinput;
00062 epsfile << currentinput;
00063 Network.Input.at(i) = currentinput;
00064 }
00065
00066 Network.Desired.at(0) = (0.5 - Random.GetNumber())*2 * noisepower;
00067 currentindex = seglength;
00068 Network.CalcOutput();
00069 Network.AdaptWeights();
00070
00071
00072 while (noisefile.good() )
00073 {
00074
00075 noisefile >> currentinput;
00076 for (int i = 0; i < typeArray.size(); ++i)
00077 {
00078 cout << "Layer: " << i << endl;
00079 for (int j = 0; j < typeArray.at(i).size(); ++j)
00080 {
00081 cout << "Neuron: " << j << endl;
00082 cout << "Delta: " << Network.Layers.at(i).at(j)->Delta << endl;
00083 cout << "Net: " << Network.Layers.at(i).at(j)->Net << endl;
00084 cout << "Output: " << Network.Layers.at(i).at(j)->Output << endl;
00085 }
00086 cout << endl;
00087 }
00088 if (noisefile.good())
00089 {
00090 if ( !(currentindex % plotintervall))
00091 Network.WriteWeights(weightfile);
00092 rotate(Network.Input.begin(),Network.Input.begin()+1,Network.Input.end());
00093 Network.Input.back() = currentinput;
00094 Network.Desired.back() = (0.5 - Random.GetNumber())*2 * noisepower;
00095 Network.CalcOutput();
00096 if (currentindex < noiseseglength)
00097 Network.AdaptWeights();
00098 outputfile << Network.Output.at(0) <<endl ;
00099
00100 epsfile << (currentinput - Network.Desired.at(0)) << endl;
00101 currentindex++;
00102 }
00103 }
00104
00105 noisefile.close();
00106 datafile.close();
00107 outputfile.close();
00108 epsfile.close();
00109 weightfile.close();
00110 }