refactoring recurent

This commit is contained in:
2016-01-28 20:49:47 +01:00
parent 3c26c9641c
commit 13b179dd57
9 changed files with 229 additions and 61 deletions

View File

@@ -26,7 +26,13 @@ namespace Recurrent {
* @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++) {
neurons.push_back(new NeuralNetwork::BiasNeuron());
for(size_t i=0;i<_inputSize;i++) {
neurons.push_back(new NeuralNetwork::InputNeuron(neurons.size()));
}
for(size_t i=0;i<_outputSize;i++) {
addNeuron();
}
@@ -35,14 +41,14 @@ namespace Recurrent {
}
};
// todo: implement
inline Network(const std::string &json) {
}
/**
* @brief Virtual destructor for Network
*/
virtual ~Network() {};
virtual ~Network() {
for(auto& a:neurons) {
delete a;
}
};
/**
* @brief This is a function to compute one iterations of network
@@ -61,7 +67,7 @@ namespace Recurrent {
*/
std::vector<float> computeOutput(const std::vector<float>& input, unsigned int iterations);
std::vector<Neuron>& getNeurons () {
std::vector<NeuralNetwork::Neuron*>& getNeurons () {
return neurons;
}
@@ -69,20 +75,27 @@ namespace Recurrent {
void stringify(std::ostream& out) const override;
Neuron& addNeuron() {
neurons.push_back(Recurrent::Neuron(neurons.size()));
Neuron &newNeuron=neurons.back();
NeuralNetwork::Neuron& addNeuron() {
neurons.push_back(new Recurrent::Neuron(neurons.size()));
NeuralNetwork::Neuron *newNeuron=neurons.back();
for(size_t i=0;i<neurons.size();i++) {
neurons[i].setWeight(newNeuron,0.0);
neurons[i]->setWeight(*newNeuron,0.0);
}
return newNeuron;
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;
protected:
size_t inputSize=0;
size_t outputSize=0;
std::vector<Recurrent::Neuron> neurons;
std::vector<NeuralNetwork::Neuron*> neurons;
};
}
}