#pragma once #include "../Neuron.h" #include #include #include namespace NeuralNetwork { namespace FeedForward { /** * @author Tomas Cernik (Tom.Cernik@gmail.com) * @brief Class for Layer of FeedForward network */ class Layer : public SimpleJSON::SerializableObject { public: Layer(std::size_t size, const ActivationFunction::ActivationFunction &activationFunction):neurons() { neurons.push_back(new BiasNeuron); for(std::size_t i=0;iclone()); } return *this; } ~Layer() { for(auto &neuron:neurons) { delete neuron; } }; /** * @brief Function adds new neuron * @returns Newly added neuron */ Neuron& addNeuron(const ActivationFunction::ActivationFunction &activationFunction = ActivationFunction::Sigmoid()) { auto neuron = new Neuron(neurons.size(),activationFunction); neurons.push_back(neuron); return *neuron; } /** * @brief This is a virtual function for selecting neuron * @param neuron is position in layer * @returns Specific neuron */ NeuronInterface& operator[](const std::size_t& neuron) { return *neurons[neuron]; } /** * @brief This is a virtual function for selecting neuron * @param neuron is position in layer * @returns Specific neuron */ const NeuronInterface& operator[](const std::size_t& neuron) const { return *neurons[neuron]; } void solve(const std::vector &input, std::vector &output); /** * @returns Size of layer */ std::size_t size() const { return neurons.size(); } void setInputSize(std::size_t size) { for(auto& neuron:neurons) { neuron->setInputSize(size); } } virtual SimpleJSON::Type::Object serialize() const override; static std::unique_ptr deserialize(const SimpleJSON::Type::Object&); typedef SimpleJSON::Factory Factory; protected: std::vector neurons; private: Layer():neurons() { } SIMPLEJSON_REGISTER(NeuralNetwork::FeedForward::Layer::Factory, NeuralNetwork::FeedForward::Layer,NeuralNetwork::FeedForward::Layer) }; } }