Neuron change
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "../Neuron.h"
|
||||
#include "../Stringifiable.h"
|
||||
|
||||
namespace NeuralNetwork {
|
||||
namespace FeedForward {
|
||||
@@ -12,19 +13,46 @@ namespace FeedForward {
|
||||
* @author Tomas Cernik (Tom.Cernik@gmail.com)
|
||||
* @brief Class for Layer of FeedForward network
|
||||
*/
|
||||
class Layer
|
||||
{
|
||||
public:
|
||||
class Layer : public Stringifiable {
|
||||
|
||||
~Layer() {};
|
||||
public:
|
||||
Layer(std::size_t size = 0):neurons() {
|
||||
neurons.push_back(new BiasNeuron);
|
||||
for(std::size_t i=0;i<size;i++) {
|
||||
neurons.push_back(new Neuron(neurons.size()));
|
||||
}
|
||||
}
|
||||
|
||||
Layer(const Layer&r):neurons() {
|
||||
*this=r;
|
||||
}
|
||||
|
||||
Layer& operator=(const Layer &r) {
|
||||
for(auto &neuron:neurons) {
|
||||
delete neuron;
|
||||
}
|
||||
|
||||
neurons.clear();
|
||||
|
||||
for(auto &neuron:r.neurons) {
|
||||
neurons.push_back(neuron->clone());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~Layer() {
|
||||
for(auto &neuron:neurons) {
|
||||
delete neuron;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This is a virtual function for selecting neuron
|
||||
* @param neuron is position in layer
|
||||
* @returns Specific neuron
|
||||
*/
|
||||
Neuron& operator[](const std::size_t& neuron) {
|
||||
return neurons[neuron];
|
||||
NeuronInterface& operator[](const std::size_t& neuron) {
|
||||
return *neurons[neuron];
|
||||
}
|
||||
|
||||
void solve(const std::vector<float> &input, std::vector<float> &output);
|
||||
@@ -36,8 +64,29 @@ namespace FeedForward {
|
||||
return neurons.size();
|
||||
}
|
||||
|
||||
void setInputSize(std::size_t size) {
|
||||
for(auto& neuron:neurons) {
|
||||
neuron->setInputSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
using Stringifiable::stringify;
|
||||
virtual void stringify(std::ostream& out) const override {
|
||||
out << "{" << std::endl;
|
||||
out << "\t \"class\": \"NeuralNetwork::FeedForward::Layer\"," << std::endl;
|
||||
out << "\t \"neurons\": [" << std::endl;
|
||||
bool first=true;
|
||||
for(auto &neuron: neurons) {
|
||||
if(!first)
|
||||
out << ", ";
|
||||
out << neuron->stringify();
|
||||
first=false;
|
||||
}
|
||||
out << "]";
|
||||
out << "}";
|
||||
}
|
||||
protected:
|
||||
std::vector<Neuron> neurons;
|
||||
std::vector<NeuronInterface*> neurons;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user