removing function from neuron
This commit is contained in:
@@ -18,11 +18,13 @@ namespace NeuralNetwork
|
||||
class NeuronInterface
|
||||
{
|
||||
public:
|
||||
NeuronInterface(const unsigned long &_id=0): id(_id) {
|
||||
NeuronInterface(const unsigned long &_id=0): id(_id), weights(1),_output(1),
|
||||
_value(0) {
|
||||
|
||||
}
|
||||
|
||||
NeuronInterface(const NeuronInterface &r): id(r.id), weights(r.weights),_output(r._output) {
|
||||
NeuronInterface(const NeuronInterface &r): id(r.id), weights(r.weights),_output(r._output),
|
||||
_value(r._value) {
|
||||
weights=weights;
|
||||
}
|
||||
|
||||
@@ -37,20 +39,36 @@ namespace NeuralNetwork
|
||||
*/
|
||||
virtual std::string stringify(const std::string &prefix="") const =0;
|
||||
|
||||
inline virtual float weight(const NeuronInterface &n) const final {
|
||||
return weights[n.id];
|
||||
/**
|
||||
* @brief getter for neuron weight
|
||||
* @param &neuron is neuron it's weight is returned
|
||||
*/
|
||||
inline virtual float weight(const NeuronInterface &neuron) const final {
|
||||
return weights[neuron.id];
|
||||
}
|
||||
|
||||
inline virtual float weight(const std::size_t &n) const final {
|
||||
return weights[n];
|
||||
/**
|
||||
* @brief getter for neuron weight
|
||||
* @param &neuronID is id of neuron
|
||||
*/
|
||||
inline virtual float weight(const std::size_t &neuronID) const final {
|
||||
return weights[neuronID];
|
||||
}
|
||||
|
||||
inline virtual float& weight(const NeuronInterface &n) final {
|
||||
return weights[n.id];
|
||||
/**
|
||||
* @brief This is a virtual function for storing network
|
||||
* @returns json describing network and it's state
|
||||
*/
|
||||
inline virtual float& weight(const NeuronInterface &neuron) final {
|
||||
return weights[neuron.id];
|
||||
}
|
||||
|
||||
inline virtual float& weight(const std::size_t &n) final {
|
||||
return weights[n];
|
||||
/**
|
||||
* @brief getter for neuron weight
|
||||
* @param &neuronID is id of neuron
|
||||
*/
|
||||
inline virtual float& weight(const std::size_t &neuronID) final {
|
||||
return weights[neuronID];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,22 +80,15 @@ namespace NeuralNetwork
|
||||
/**
|
||||
* @brief Returns input of neuron
|
||||
*/
|
||||
virtual float value() const=0;
|
||||
|
||||
/**
|
||||
* @brief Function sets bias for neuron
|
||||
* @param bias is new bias (initial value for neuron)
|
||||
*/
|
||||
virtual void setBias(const float &bias)=0;
|
||||
|
||||
/**
|
||||
* @brief Function returns bias for neuron
|
||||
*/
|
||||
virtual float getBias() const=0;
|
||||
inline virtual float value() const final {
|
||||
return _value;
|
||||
};
|
||||
|
||||
virtual float operator()(const std::vector<float>& inputs) =0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief function resizes weighs to desired size
|
||||
*/
|
||||
inline virtual void setInputSize(const std::size_t &size) final {
|
||||
if(weights.size()<size) {
|
||||
weights.resize(size);
|
||||
@@ -89,21 +100,24 @@ namespace NeuralNetwork
|
||||
*/
|
||||
virtual NeuronInterface* clone() const = 0;
|
||||
|
||||
/*
|
||||
/**
|
||||
* @brief getter for basis function of neuron
|
||||
*/
|
||||
virtual BasisFunction::BasisFunction& getBasisFunction() =0;
|
||||
|
||||
/*
|
||||
/**
|
||||
* @brief getter for activation function of neuron
|
||||
*/
|
||||
virtual ActivationFunction::ActivationFunction& getActivationFunction() =0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief id is identificator if neuron
|
||||
*/
|
||||
const unsigned long id;
|
||||
protected:
|
||||
std::vector<float> weights= std::vector<float>(1);
|
||||
float _output=1.0;
|
||||
std::vector<float> weights;
|
||||
float _output;
|
||||
float _value;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -115,13 +129,11 @@ namespace NeuralNetwork
|
||||
public:
|
||||
Neuron(unsigned long _id=0, const ActivationFunction::ActivationFunction &activationFunction=ActivationFunction::Sigmoid(-4.9)):
|
||||
NeuronInterface(_id), basis(new BasisFunction::Linear),
|
||||
activation(activationFunction.clone()),
|
||||
_value(0) {
|
||||
activation(activationFunction.clone()) {
|
||||
_output=0.0;
|
||||
}
|
||||
|
||||
Neuron(const Neuron &r): NeuronInterface(r), basis(r.basis->clone()), activation(r.activation->clone()),
|
||||
_value(r._value) {
|
||||
Neuron(const Neuron &r): NeuronInterface(r), basis(r.basis->clone()), activation(r.activation->clone()) {
|
||||
}
|
||||
|
||||
virtual ~Neuron() {
|
||||
@@ -133,28 +145,6 @@ namespace NeuralNetwork
|
||||
|
||||
virtual std::string stringify(const std::string &prefix="") const override;
|
||||
|
||||
/**
|
||||
* @brief Returns input of neuron
|
||||
*/
|
||||
virtual float value() const override {
|
||||
return _value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function sets bias for neuron
|
||||
* @param _bias is new bias (initial value for neuron)
|
||||
*/
|
||||
virtual void setBias(const float &_bias) override {
|
||||
weights[0]=_bias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function returns bias for neuron
|
||||
*/
|
||||
virtual float getBias() const override {
|
||||
return weights[0];
|
||||
}
|
||||
|
||||
float operator()(const std::vector<float>& inputs) {
|
||||
//compute value
|
||||
_value=basis->operator()(weights,inputs);
|
||||
@@ -181,8 +171,6 @@ namespace NeuralNetwork
|
||||
|
||||
BasisFunction::BasisFunction *basis;
|
||||
ActivationFunction::ActivationFunction *activation;
|
||||
|
||||
float _value;
|
||||
};
|
||||
|
||||
class BiasNeuron: public NeuronInterface {
|
||||
@@ -200,14 +188,8 @@ namespace NeuralNetwork
|
||||
std::string text;
|
||||
};
|
||||
|
||||
virtual float getBias() const override { return 0; };
|
||||
|
||||
virtual void setBias(const float&) override{ }
|
||||
|
||||
virtual std::string stringify(const std::string& prefix = "") const override { return prefix+"{ \"class\" : \"NeuralNetwork::BiasNeuron\" }"; }
|
||||
|
||||
virtual float value() const override { return 1.0; }
|
||||
|
||||
virtual float operator()(const std::vector< float >&) override { return 1.0; }
|
||||
|
||||
virtual BiasNeuron* clone() const { return new BiasNeuron(); }
|
||||
@@ -241,14 +223,8 @@ namespace NeuralNetwork
|
||||
|
||||
}
|
||||
|
||||
virtual float getBias() const override { return 0; };
|
||||
|
||||
virtual void setBias(const float&) override{ }
|
||||
|
||||
virtual std::string stringify(const std::string& prefix = "") const override { return prefix+"{ \"class\" : \"NeuralNetwork::InputNeuron\", \"id\": "+std::to_string(id)+" }"; }
|
||||
|
||||
virtual float value() const override { return 1.0; }
|
||||
|
||||
virtual float operator()(const std::vector< float >&) override { return 1.0; }
|
||||
|
||||
virtual InputNeuron* clone() const { return new InputNeuron(id); }
|
||||
|
||||
@@ -76,4 +76,3 @@ void NeuralNetwork::Learning::BackPropagation::teach(FeedForward::Network &netwo
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ std::string NeuralNetwork::Neuron::stringify(const std::string &prefix) const {
|
||||
out << prefix << "{\n";
|
||||
out << prefix << "\t\"class\": \"NeuralNetwork::Neuron\",\n";
|
||||
out << prefix << "\t\"id\": " << id << ",\n";
|
||||
out << prefix << "\t\"bias\": " << getBias() << ",\n";
|
||||
out << prefix << "\t\"output\": " << output() << ",\n";
|
||||
out << prefix << "\t\"value\": " << value() << ",\n";
|
||||
out << prefix << "\t\"activationFunction\": " << activation->stringify() <<",\n";
|
||||
|
||||
Reference in New Issue
Block a user