nettest.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 "CNeuralConfig.h"
00008 #include "UniformRNG.h"
00009 using namespace std;
00010 
00011 int main()
00012 {
00013         UniformRNG Random;
00014         NeuralNetwork::ttypeVector typeVector;
00015         NeuralNetwork::ttypeArray typeArray;
00016                 
00017         const int seglength = 2;
00018         const double maxinit = 0.1;
00019         const int maxit = 5;
00020         const int hlayers = 3;
00021         const int deslength = 1;
00022         const double mu = 1.0;
00023         vector<double> input(seglength,0), desired(deslength,0), output;
00024         
00025         typeVector.assign(seglength,SigmoidalNeuron::bipolar);
00026         for (int i = 0; i < hlayers; ++i)
00027         {
00028                 typeArray.push_back(typeVector);
00029         }
00030         typeVector.assign(1,SigmoidalNeuron::bipolar);
00031         typeArray.push_back(typeVector);
00032         
00033         NeuralNetwork Network(seglength,deslength);
00034         Network.SetInput(input);
00035         Network.SetLayers(typeArray);
00036         Network.InitWeights(maxinit,maxinit);
00037         Network.SetMu(mu);
00038         
00039         for (int iterations = 0; iterations < maxit; ++iterations)
00040         {
00041                 for (int i = 0; i < seglength; ++i)
00042                         input.at(i) = Random.GetNumber();
00043                 Network.SetInput(input);
00044                 for (int i = 0; i < deslength; ++i)
00045                         desired.at(i) = Random.GetNumber();
00046                 Network.SetDesired(desired);
00047                 output = Network.CalcOutput();
00048                 Network.AdaptWeights();
00049                 std::copy(output.begin(),output.end(),ostream_iterator<double>(cout," "));
00050                 std::cout << std::endl;
00051                 std::cout << "Weights: " << std::endl;
00052                 Network.PrintWeights(std::cout);
00053                 std::cout << std::endl;
00054         }
00055 }

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