Modified FeedForward to allow set activation to whole Layer and added XOR test for FF

This commit is contained in:
2016-02-03 21:16:35 +01:00
parent ea4ce22867
commit 567fcd2373
5 changed files with 64 additions and 35 deletions

View File

@@ -9,6 +9,8 @@
#include <iomanip>
#include <limits>
#include <iostream>
namespace NeuralNetwork {
namespace FeedForward {
@@ -29,24 +31,27 @@ namespace FeedForward {
appendLayer(_inputSize);
};
Layer& appendLayer(std::size_t size=1) {
layers.push_back(Layer(size));
if(layers.size() > 1)
layers.back().setInputSize(layers[layers.size()-2].size());
return layers.back();
}
Layer& operator[](const std::size_t &id) {
return layers[id];
}
/**
* @brief Virtual destructor for Network
*/
virtual ~Network() {
};
for(auto &layer:layers) {
delete layer;
}
}
Layer& appendLayer(std::size_t size=1, const ActivationFunction::ActivationFunction &activationFunction=ActivationFunction::Sigmoid(-4.9)) {
layers.push_back(new Layer(size,activationFunction));
if(layers.size() > 1)
layers.back()->setInputSize(layers[layers.size()-2]->size());
return *layers[layers.size()-1];//.back();
}
Layer& operator[](const std::size_t &id) {
return *layers[id];
}
/**
* @brief This is a function to compute one iterations of network
@@ -66,7 +71,7 @@ namespace FeedForward {
if(!first) {
out << ",";
}
out << layer;
out << *layer;
first=false;
}
out << "]";
@@ -74,7 +79,7 @@ namespace FeedForward {
}
protected:
std::vector<Layer> layers;
std::vector<Layer*> layers;
};
}
}