85 lines
2.0 KiB
C++
85 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include "../Network.h"
|
|
#include "Layer.h"
|
|
|
|
#include <vector>
|
|
|
|
#include <sstream>
|
|
#include <iomanip>
|
|
#include <limits>
|
|
|
|
#include <iostream>
|
|
|
|
namespace NeuralNetwork {
|
|
namespace FeedForward {
|
|
|
|
/**
|
|
* @author Tomas Cernik (Tom.Cernik@gmail.com)
|
|
* @brief FeedForward 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):NeuralNetwork::Network(),layers() {
|
|
appendLayer(_inputSize);
|
|
};
|
|
|
|
/**
|
|
* @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
|
|
* @param input is input of network
|
|
* @returns output of network
|
|
*/
|
|
virtual std::vector<float> computeOutput(const std::vector<float>& input) override;
|
|
|
|
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;
|
|
}
|
|
out << "]";
|
|
out << "}";
|
|
}
|
|
|
|
protected:
|
|
std::vector<Layer*> layers;
|
|
};
|
|
}
|
|
} |