00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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