• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

test/TestNeuralNetwork.cpp

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #include <spl/Log.h>
00018 #include <spl/math/NeuralNetwork.h>
00019 
00020 #ifdef DEBUG
00021 
00022 void _TestNetwork(  )
00023 {
00024         DEBUG_CLEAR_MEM_CHECK_POINTS();
00025         DEBUG_DUMP_MEM_LEAKS();
00026         DEBUG_ASSERT_MEM_NOTED();
00027 
00028         Network *net = new Network(2, 2, 1, 1);
00029         DEBUG_NOTE_MEM_ALLOCATION( net );
00030         net->CheckMem();
00031         DEBUG_ASSERT_MEM_NOTED();
00032 
00033         delete net;
00034         DEBUG_CLEAR_MEM_CHECK_POINTS();
00035         DEBUG_DUMP_MEM_LEAKS();
00036         DEBUG_ASSERT_MEM_NOTED();
00037 
00038         net = new Network(2, 2, 2, 1);
00039         double in1[] = {1.0,0.0};
00040         double out1[] = {1.0};
00041         double in2[] = {0.0, 1.0};
00042         double out2[] = {1.0};
00043         double in3[] = {1.0,1.0};
00044         double out3[] = {0.0};
00045         double in4[] = {0.0,0.0};
00046         double out4[] = {0.0};
00047 
00048         {
00049                 Array<double> in1a(in1, 2);
00050                 Array<double> out1a(out1, 1);
00051 
00052                 Array<double> in2a(in2, 2);
00053                 Array<double> out2a(out2, 1);
00054                 Array<double> in3a(in3, 2);
00055                 Array<double> out3a(out3, 1);
00056                 Array<double> in4a(in4, 2);
00057                 Array<double> out4a(out4, 1);
00058 
00059                 double error = 1.0;
00060                 while ( error > .0001 )
00061                 {
00062                         error = net->Train(in1a, out1a, .0000001, 10000);
00063                         error += net->Train(in2a, out2a, .0000001, 10000);
00064                         error += net->Train(in3a, out3a, .0000001, 10000);
00065                         error += net->Train(in4a, out4a, .0000001, 10000);
00066                 }
00067         }
00068 
00069         delete net;
00070 
00071         DEBUG_CLEAR_MEM_CHECK_POINTS();
00072         DEBUG_DUMP_MEM_LEAKS();
00073         DEBUG_ASSERT_MEM_NOTED();
00074         
00075         Log::SWriteOkFail( "Neural network test 1" );
00076 }
00077 
00078 #endif