serializatioin / deserialization and tests

This commit is contained in:
2016-04-06 15:54:47 +02:00
parent adb6708b39
commit 17cbf5effe
28 changed files with 437 additions and 280 deletions

View File

@@ -4,13 +4,8 @@
#include "Layer.h"
#include <vector>
#include <sstream>
#include <iomanip>
#include <limits>
#include <iostream>
namespace NeuralNetwork {
namespace FeedForward {
@@ -63,24 +58,29 @@ namespace FeedForward {
using NeuralNetwork::Network::stringify;
void stringify(std::ostream& out) const override {
out << "{" << std::endl;
out << "\t \"class\": \"NeuralNetwork::FeedForward::Network\"," << std::endl;
out << "\t \"layers\": [" << std::endl;
bool first=true;
for(auto &layer:layers) {
if(!first) {
out << ",";
}
out << *layer;
first=false;
virtual SimpleJSON::Type::Object serialize() const override {
std::vector<SimpleJSON::Value> layersSerialized;
for(std::size_t i=0;i<layers.size();i++) {
layersSerialized.push_back(layers[i]->serialize());
}
out << "]";
out << "}";
return {
{"class", "NeuralNetwork::FeedForward::Network"},
{"layers", layersSerialized },
};
}
static std::unique_ptr<Network> deserialize(const SimpleJSON::Type::Object&);
typedef SimpleJSON::Factory<Network> Factory;
protected:
std::vector<Layer*> layers;
private:
inline Network():NeuralNetwork::Network(),layers() {
};
SIMPLEJSON_REGISTER(NeuralNetwork::FeedForward::Network::Factory, NeuralNetwork::FeedForward::Network,NeuralNetwork::FeedForward::Network::deserialize)
};
}
}