nettest3.cpp

Go to the documentation of this file.
00001 #include "NeuralNetwork.h"
00002 #include <iostream>
00003 #include <vector>
00004 #include <string>
00005 #include <algorithm>
00006 #include <iterator>
00007 #include <cmath>
00008 #include <fstream>
00009 #include "UniformRNG.h"
00010 #include "NetCDFTools.h"
00011 #include "ApplyFilter.h"
00012 using namespace std;
00013 
00014 int main()
00015 {
00016         UniformRNG Random;
00017         NeuralNetwork::ttypeVector typeVector;
00018         NeuralNetwork::ttypeArray typeArray;
00019                 
00020         const int seglength = 5;
00021         const double maxinit = 0.5;
00022         const int maxit = 50000;
00023         const int hlayers = 2;
00024         const int deslength = 1;
00025         const double mu = 0.1;
00026         const double alpha = 0.0;
00027         const double period = 35.2;
00028         const double PI = acos(-1.0);
00029         const double noiselevel = 0.2;
00030         TimeSeriesComponent input, desired;
00031         
00032         typeVector.assign(seglength,SigmoidalNeuron::bipolar);
00033         for (int i = 0; i < hlayers; ++i)
00034         {
00035                 typeArray.push_back(typeVector);
00036         }
00037         typeVector.assign(1,SigmoidalNeuron::bipolar);
00038         typeArray.push_back(typeVector);
00039         
00040         NeuralNetwork Network(seglength,deslength,mu,typeArray,maxinit);
00041         Network.SetAlpha(alpha);
00042         //Network.SetInput(input);
00043         //Network.SetLayers(typeArray);
00044         //Network.InitWeights(maxinit,maxinit);
00045         //Network.SetMu(mu);
00046         
00047         ApplyFilter Filter(Network,true);
00048         Filter.SetWeightSaveIntervall(100);
00049         for (int i = 0; i < maxit; ++i)
00050         {
00051                         input.GetData().push_back(sin( 2.0 * PI * i/period));
00052                         desired.GetData().push_back(0.5*cos( 2.0 * PI * i/period)+Random.GetNumber(-noiselevel,noiselevel));
00053         }
00054         Filter.AddInputChannel(input);
00055         Filter.AddReferenceChannel(desired);
00056         cout << "Weights: " << endl;
00057         Network.PrintWeights(cout);
00058         cout << endl;
00059         Filter.FilterData();
00060         cout << "Weights: " << endl;
00061         Network.PrintWeights(cout);
00062         cout << endl;
00063         ofstream cleanfile("test.clean");
00064         for (int i = 0; i < maxit; ++i)
00065                 cleanfile << i << " " << Filter.GetOutChannels().front()->GetData().at(i) << " " << desired.GetData().at(i) << " " 
00066                                          << 0.5*cos( 2.0 * PI * i/period) << endl;
00067         ofstream difffile("test.diff");
00068         for (int i = 0; i < maxit; ++i)
00069                 difffile << i << " " << Filter.GetOutChannels().front()->GetData().at(i) -0.5*cos( 2.0 * PI * i/period)  
00070                           << " " << desired.GetData().at(i) - 0.5* cos( 2.0 * PI * i/period) << endl;
00071         ofstream epsfile("test.eps");
00072         copy(Filter.GetEpsValues().front().begin(),Filter.GetEpsValues().front().end(),ostream_iterator<double>(epsfile,"\n")); 
00073         Network.PrintTopology("test.dot");                       
00074         WriteMatrixAsNetCDF("test.weights.nc",Filter.GetWeightHistory());
00075 }

Generated on Mon Sep 15 12:54:34 2008 for GPLIB++ by  doxygen 1.5.5