#pragma once #include "../Network.h" #include #include #include #include namespace NeuralNetwork { namespace Recurrent { /** * @author Tomas Cernik (Tom.Cernik@gmail.com) * @brief Reccurent model of Artifical neural network */ class Network: public NeuralNetwork::Network { public: /** * @brief Constructor for Network * @param _inputSize is number of inputs to network * @param _outputSize is size of output from network * @param hiddenUnits is number of hiddenUnits to be created */ inline Network(size_t inputSize, size_t outputSize,size_t hiddenUnits=0):NeuralNetwork::Network(inputSize,outputSize), neurons(0),outputs(0) { neurons.push_back(new NeuralNetwork::BiasNeuron()); for(size_t i=0;iclone()); } } Network& operator=(const Network&r); /** * @brief Virtual destructor for Network */ virtual ~Network() { for(auto& a:neurons) { delete a; } }; /** * @brief This is a function to compute one iterations of network * @param input is input of network * @returns output of network */ inline virtual std::vector computeOutput(const std::vector& input) override { return computeOutput(input,1); } /** * @brief This is a function to compute iterations of network * @param input is input of network * @param iterations is number of iterations * @returns output of network */ std::vector computeOutput(const std::vector& input, unsigned int iterations); std::vector& getNeurons () { return neurons; } virtual SimpleJSON::Type::Object serialize() const override; NeuronInterface& addNeuron() { neurons.push_back(new Neuron(neurons.size())); NeuronInterface *newNeuron=neurons.back(); for(std::size_t i=0;isetInputSize(newNeuron->id+1); } return *newNeuron; } /** * @brief creates new network from joining two * @param r is network that is connected to outputs of this network * @returns network of constructed from two networks */ NeuralNetwork::Recurrent::Network connectWith(const NeuralNetwork::Recurrent::Network &r) const; static std::unique_ptr deserialize(const SimpleJSON::Type::Object&); std::size_t size() const { return neurons.size(); }; NeuronInterface& operator[](std::size_t index) { return *neurons[index]; } typedef SimpleJSON::Factory Factory; protected: std::vector neurons; std::vector outputs; SIMPLEJSON_REGISTER(NeuralNetwork::Recurrent::Network::Factory,NeuralNetwork::Recurrent::Network, deserialize) }; } }