diff --git a/tests/activation.cpp b/tests/activation.cpp index 677671c..be77834 100644 --- a/tests/activation.cpp +++ b/tests/activation.cpp @@ -4,8 +4,13 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" + #include +#pragma GCC diagnostic pop + union SSE { __m128 sse; // SSE 4 x float vector float floats[4]; // scalar array of 4 floats diff --git a/tests/backpropagation.cpp b/tests/backpropagation.cpp index f93ecbf..caafcfc 100644 --- a/tests/backpropagation.cpp +++ b/tests/backpropagation.cpp @@ -1,8 +1,13 @@ #include #include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" #include +#pragma GCC diagnostic pop TEST(BackProp,XOR) { NeuralNetwork::FeedForward::Network n(2); NeuralNetwork::ActivationFunction::Sigmoid a(-1); @@ -41,10 +46,47 @@ TEST(BackProp,XOR) { } } +TEST(BackProp,XORHyperbolicTangent) { + NeuralNetwork::FeedForward::Network n(2); + NeuralNetwork::ActivationFunction::HyperbolicTangent a(-1); + n.appendLayer(2,a); + n.appendLayer(1,a); + + n.randomizeWeights(); + + NeuralNetwork::Learning::BackPropagation prop(n); + + for(int i=0;i<10000;i++) { + prop.teach({1,0},{1}); + prop.teach({1,1},{0}); + prop.teach({0,0},{0}); + prop.teach({0,1},{1}); + } + + { + std::vector ret =n.computeOutput({1,1}); + ASSERT_LT(ret[0], 0.1); + } + + { + std::vector ret =n.computeOutput({0,1}); + ASSERT_GT(ret[0], 0.9); + } + + { + std::vector ret =n.computeOutput({1,0}); + ASSERT_GT(ret[0], 0.9); + } + + { + std::vector ret =n.computeOutput({0,0}); + ASSERT_LT(ret[0], 0.1); + } +} + TEST(BackProp,AND) { NeuralNetwork::FeedForward::Network n(2); NeuralNetwork::ActivationFunction::Sigmoid a(-1); - n.appendLayer(2,a); n.appendLayer(1,a); n.randomizeWeights(); diff --git a/tests/feedforward.cpp b/tests/feedforward.cpp index c72a696..d729f41 100644 --- a/tests/feedforward.cpp +++ b/tests/feedforward.cpp @@ -1,7 +1,12 @@ #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" + #include +#pragma GCC diagnostic pop + TEST(FeedForward, XOR) { NeuralNetwork::FeedForward::Network n(2); NeuralNetwork::ActivationFunction::Sigmoid a(-1); diff --git a/tests/optical_backpropagation.cpp b/tests/optical_backpropagation.cpp index f2ff702..037e065 100644 --- a/tests/optical_backpropagation.cpp +++ b/tests/optical_backpropagation.cpp @@ -2,8 +2,12 @@ #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" + #include +#pragma GCC diagnostic pop TEST(OpticalBackPropagation,XOR) { NeuralNetwork::FeedForward::Network n(2); diff --git a/tests/perceptron.cpp b/tests/perceptron.cpp index 5a9a8d6..09bddd0 100644 --- a/tests/perceptron.cpp +++ b/tests/perceptron.cpp @@ -1,7 +1,12 @@ #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" + #include +#pragma GCC diagnostic pop + TEST(Perceptron,Test) { NeuralNetwork::FeedForward::Perceptron p(2,1); diff --git a/tests/perceptron_learning.cpp b/tests/perceptron_learning.cpp index c5d9fc7..4ba2880 100644 --- a/tests/perceptron_learning.cpp +++ b/tests/perceptron_learning.cpp @@ -1,7 +1,11 @@ #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" + #include +#pragma GCC diagnostic pop TEST(PerceptronLearning,XOR) { NeuralNetwork::FeedForward::Perceptron n(2,1); diff --git a/tests/quickpropagation.cpp b/tests/quickpropagation.cpp index f992d70..e54fdd3 100644 --- a/tests/quickpropagation.cpp +++ b/tests/quickpropagation.cpp @@ -1,19 +1,25 @@ #include #include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" #include +#pragma GCC diagnostic pop + TEST(QuickPropagation,XOR) { NeuralNetwork::FeedForward::Network n(2); NeuralNetwork::ActivationFunction::Sigmoid a(-1); - n.appendLayer(2,a); + n.appendLayer(10,a); n.appendLayer(1,a); n.randomizeWeights(); NeuralNetwork::Learning::QuickPropagation prop(n); - for(int i=0;i<10000;i++) { + for(int i=0;i<400;i++) { prop.teach({1,0},{1}); prop.teach({1,1},{0}); prop.teach({0,0},{0}); @@ -43,7 +49,7 @@ TEST(QuickPropagation,XOR) { TEST(QuickPropagation,AND) { NeuralNetwork::FeedForward::Network n(2); - NeuralNetwork::ActivationFunction::Sigmoid a(-1); + NeuralNetwork::ActivationFunction::Sigmoid a(1.0); n.appendLayer(2,a); n.appendLayer(1,a); @@ -51,11 +57,11 @@ TEST(QuickPropagation,AND) { NeuralNetwork::Learning::QuickPropagation prop(n); - for(int i=0;i<10000;i++) { + for(int i=0;i<400;i++) { prop.teach({1,1},{1}); + prop.teach({1,0},{0}); prop.teach({0,0},{0}); prop.teach({0,1},{0}); - prop.teach({1,0},{0}); } { @@ -115,4 +121,41 @@ TEST(QuickPropagation,NOTAND) { std::vector ret =n.computeOutput({0,0}); ASSERT_GT(ret[0], 0.9); } +} +TEST(QuickPropagation,NOTANDHyperbolicTangent) { + NeuralNetwork::FeedForward::Network n(2); + NeuralNetwork::ActivationFunction::HyperbolicTangent a(1); + n.appendLayer(2,a); + n.appendLayer(1,a); + + n.randomizeWeights(); + + NeuralNetwork::Learning::QuickPropagation prop(n); + + for(int i=0;i<10000;i++) { + prop.teach({1,1},{-1}); + prop.teach({-1,0},{1}); + prop.teach({-1,1},{1}); + prop.teach({1,-1},{1}); + } + + { + std::vector ret =n.computeOutput({1,1}); + ASSERT_LT(ret[0], 0.1); + } + + { + std::vector ret =n.computeOutput({-1,1}); + ASSERT_GT(ret[0], 0.9); + } + + { + std::vector ret =n.computeOutput({1,-1}); + ASSERT_GT(ret[0], 0.9); + } + + { + std::vector ret =n.computeOutput({-1,-1}); + ASSERT_GT(ret[0], 0.9); + } } \ No newline at end of file diff --git a/tests/recurrent.cpp b/tests/recurrent.cpp index 8f5bf3a..a6c34c1 100644 --- a/tests/recurrent.cpp +++ b/tests/recurrent.cpp @@ -1,7 +1,12 @@ #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" + #include +#pragma GCC diagnostic pop + TEST(Recurrent, Sample) { NeuralNetwork::Recurrent::Network a(2,1,1); @@ -18,7 +23,6 @@ TEST(Recurrent, Sample) { } std::string str = a.stringify(); - std::cout << str << std::endl;; //deserialize and check it! NeuralNetwork::Recurrent::Network *deserialized = (NeuralNetwork::Recurrent::Network::Factory::deserialize(str).release());