88 lines
2.1 KiB
C++
88 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include "../Network.h"
|
|
#include "Neuron.h"
|
|
|
|
#include <vector>
|
|
|
|
#include <sstream>
|
|
#include <iomanip>
|
|
#include <limits>
|
|
|
|
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(_inputSize),outputSize(_outputSize), neurons(0) {
|
|
for(size_t i=0;i<_inputSize+_outputSize;i++) {
|
|
addNeuron();
|
|
}
|
|
|
|
for(size_t i=0;i<hiddenUnits;i++) {
|
|
addNeuron();
|
|
}
|
|
};
|
|
|
|
// todo: implement
|
|
inline Network(const std::string &json) {
|
|
|
|
}
|
|
/**
|
|
* @brief Virtual destructor for Network
|
|
*/
|
|
virtual ~Network() {};
|
|
|
|
/**
|
|
* @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<float> computeOutput(const std::vector<float>& 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<float> computeOutput(const std::vector<float>& input, unsigned int iterations);
|
|
|
|
std::vector<Neuron>& getNeurons () {
|
|
return neurons;
|
|
}
|
|
|
|
using NeuralNetwork::Network::stringify;
|
|
|
|
void stringify(std::ostream& out) const override;
|
|
|
|
Neuron& addNeuron() {
|
|
neurons.push_back(Recurrent::Neuron(neurons.size()));
|
|
Neuron &newNeuron=neurons.back();
|
|
for(size_t i=0;i<neurons.size();i++) {
|
|
neurons[i].setWeight(newNeuron,0.0);
|
|
}
|
|
return newNeuron;
|
|
}
|
|
|
|
protected:
|
|
size_t inputSize=0;
|
|
size_t outputSize=0;
|
|
|
|
std::vector<Recurrent::Neuron> neurons;
|
|
};
|
|
}
|
|
} |