Skip to content
Snippets Groups Projects
Commit 2a28e0dd authored by Martin Beseda's avatar Martin Beseda
Browse files

ENH: Implemented serialization for Neuron classes.

parent b4c6705d
No related branches found
No related tags found
No related merge requests found
...@@ -4,8 +4,3 @@ ...@@ -4,8 +4,3 @@
Neuron::~Neuron() { Neuron::~Neuron() {
} }
//template<class Archive>
//void Neuron::serialize(Archive & ar, const unsigned int version) {
// ar << this->potential;
// ar << this->state;
//}
\ No newline at end of file
...@@ -19,20 +19,11 @@ class IDifferentiable; ...@@ -19,20 +19,11 @@ class IDifferentiable;
* Abstract class representing a general neuron * Abstract class representing a general neuron
*/ */
class Neuron { class Neuron {
private:
friend class boost::serialization::access; friend class boost::serialization::access;
protected:
template<class Archive> template<class Archive>
void serialize(Archive & ar, const unsigned int version){ void serialize(Archive & ar, const unsigned int version){};
//TODO separate implementation to Neuron.cpp!
// ar & this->potential;
// ar & this->state;
//
// for(unsigned short int i = 0; i < this->n_activation_function_parameters; i++) {
// ar & this->activation_function_parameters[i];
// }
};
public: public:
...@@ -47,6 +38,7 @@ public: ...@@ -47,6 +38,7 @@ public:
* Performs the activation function and returns the result * Performs the activation function and returns the result
*/ */
virtual double activate( double x, double b ) = 0; virtual double activate( double x, double b ) = 0;
}; /* end of Neuron class */ }; /* end of Neuron class */
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
#include "NeuronBinary.h" #include "NeuronBinary.h"
NeuronBinary::NeuronBinary( ) { NeuronBinary::NeuronBinary( ) {}
}
double NeuronBinary::activate( double x, double b ) { double NeuronBinary::activate( double x, double b ) {
......
...@@ -16,12 +16,11 @@ ...@@ -16,12 +16,11 @@
* Binary neuron class - uses unit-step as the activation function * Binary neuron class - uses unit-step as the activation function
*/ */
class NeuronBinary:public Neuron { class NeuronBinary:public Neuron {
private:
friend class boost::serialization::access; friend class boost::serialization::access;
protected:
template<class Archive> template<class Archive>
void serialize(Archive & ar, const unsigned int version){ void serialize(Archive & ar, const unsigned int version){
//TODO separate implementation to NeuronLogistic.cpp!
ar & boost::serialization::base_object<Neuron>(*this); ar & boost::serialization::base_object<Neuron>(*this);
}; };
......
...@@ -8,9 +8,7 @@ ...@@ -8,9 +8,7 @@
#include "NeuronConstant.h" #include "NeuronConstant.h"
NeuronConstant::NeuronConstant( double c ) { NeuronConstant::NeuronConstant( double c ) {
this->p = c; this->p = c;
} }
double NeuronConstant::activate( double x, double b ) { double NeuronConstant::activate( double x, double b ) {
......
...@@ -12,13 +12,16 @@ ...@@ -12,13 +12,16 @@
#include "Neuron.h" #include "Neuron.h"
class NeuronConstant: public Neuron, public IDifferentiable { class NeuronConstant: public Neuron, public IDifferentiable {
private:
friend class boost::serialization::access; friend class boost::serialization::access;
protected: double p = 0.0;
template<class Archive> template<class Archive>
void serialize(Archive & ar, const unsigned int version){ void serialize(Archive & ar, const unsigned int version){
//TODO separate implementation to NeuronLinear.cpp!
ar & boost::serialization::base_object<Neuron>(*this); ar & boost::serialization::base_object<Neuron>(*this);
ar & this->p;
}; };
public: public:
...@@ -54,7 +57,6 @@ public: ...@@ -54,7 +57,6 @@ public:
* @return * @return
*/ */
Neuron* get_derivative( ) override; Neuron* get_derivative( ) override;
private:
double p = 0.0;
}; };
#endif //INC_4NEURO_NEURONCONSTANT_H #endif //INC_4NEURO_NEURONCONSTANT_H
...@@ -6,10 +6,7 @@ ...@@ -6,10 +6,7 @@
NeuronLinear::NeuronLinear( ) { NeuronLinear::NeuronLinear( ) {}
}
double NeuronLinear::activate( double x, double b ) { double NeuronLinear::activate( double x, double b ) {
......
...@@ -20,12 +20,11 @@ ...@@ -20,12 +20,11 @@
* 'x' being the neuron's potential * 'x' being the neuron's potential
*/ */
class NeuronLinear:public Neuron, public IDifferentiable { class NeuronLinear:public Neuron, public IDifferentiable {
private:
friend class boost::serialization::access; friend class boost::serialization::access;
protected:
template<class Archive> template<class Archive>
void serialize(Archive & ar, const unsigned int version){ void serialize(Archive & ar, const unsigned int version){
//TODO separate implementation to NeuronLinear.cpp!
ar & boost::serialization::base_object<Neuron>(*this); ar & boost::serialization::base_object<Neuron>(*this);
}; };
......
...@@ -5,9 +5,7 @@ ...@@ -5,9 +5,7 @@
#include "NeuronLogistic.h" #include "NeuronLogistic.h"
NeuronLogistic_d2::NeuronLogistic_d2( ) { NeuronLogistic_d2::NeuronLogistic_d2( ) {}
}
double NeuronLogistic_d2::activate( double x, double b ) { double NeuronLogistic_d2::activate( double x, double b ) {
//(e^(b + x) (e^b - e^x))/(e^b + e^x)^3 //(e^(b + x) (e^b - e^x))/(e^b + e^x)^3
...@@ -40,9 +38,7 @@ NeuronLogistic* NeuronLogistic_d2::get_derivative() { ...@@ -40,9 +38,7 @@ NeuronLogistic* NeuronLogistic_d2::get_derivative() {
return nullptr; return nullptr;
} }
NeuronLogistic_d1::NeuronLogistic_d1( ) { NeuronLogistic_d1::NeuronLogistic_d1( ) {}
}
double NeuronLogistic_d1::activate( double x, double b ) { double NeuronLogistic_d1::activate( double x, double b ) {
...@@ -80,9 +76,7 @@ NeuronLogistic* NeuronLogistic_d1::get_derivative( ) { ...@@ -80,9 +76,7 @@ NeuronLogistic* NeuronLogistic_d1::get_derivative( ) {
return output; return output;
} }
NeuronLogistic::NeuronLogistic( ) { NeuronLogistic::NeuronLogistic( ) {}
}
double NeuronLogistic::activate( double x, double b ) { double NeuronLogistic::activate( double x, double b ) {
//(1 + e^(-x + b))^(-1) //(1 + e^(-x + b))^(-1)
......
...@@ -59,13 +59,15 @@ public: ...@@ -59,13 +59,15 @@ public:
class NeuronLogistic_d1:public NeuronLogistic { class NeuronLogistic_d1:public NeuronLogistic {
private:
friend class boost::serialization::access; friend class boost::serialization::access;
protected:
template<class Archive> template<class Archive>
void serialize(Archive & ar, const unsigned int version){ void serialize(Archive & ar, const unsigned int version){
//TODO separate implementation to NeuronLogistic_d1.cpp! //TODO separate implementation to Neuronogistic_d1.cpp!
ar & boost::serialization::base_object<Neuron>(*this); ar & boost::serialization::base_object<Neuron>(*this);
}; };
public: public:
/** /**
...@@ -106,13 +108,15 @@ public: ...@@ -106,13 +108,15 @@ public:
class NeuronLogistic_d2:public NeuronLogistic_d1 { class NeuronLogistic_d2:public NeuronLogistic_d1 {
private:
friend class boost::serialization::access; friend class boost::serialization::access;
protected:
template<class Archive> template<class Archive>
void serialize(Archive & ar, const unsigned int version){ void serialize(Archive & ar, const unsigned int version){
//TODO separate implementation to NeuronLogistic_d1.cpp! //TODO separate implementation to NeuronLogistic_d1.cpp!
ar & boost::serialization::base_object<Neuron>(*this); ar & boost::serialization::base_object<Neuron>(*this);
}; };
public: public:
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment