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 @@
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;
* Abstract class representing a general neuron
*/
class Neuron {
private:
friend class boost::serialization::access;
protected:
template<class Archive>
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];
// }
};
void serialize(Archive & ar, const unsigned int version){};
public:
......@@ -47,6 +38,7 @@ public:
* Performs the activation function and returns the result
*/
virtual double activate( double x, double b ) = 0;
}; /* end of Neuron class */
......
......@@ -4,9 +4,7 @@
#include "NeuronBinary.h"
NeuronBinary::NeuronBinary( ) {
}
NeuronBinary::NeuronBinary( ) {}
double NeuronBinary::activate( double x, double b ) {
......
......@@ -16,12 +16,11 @@
* Binary neuron class - uses unit-step as the activation function
*/
class NeuronBinary:public Neuron {
private:
friend class boost::serialization::access;
protected:
template<class Archive>
void serialize(Archive & ar, const unsigned int version){
//TODO separate implementation to NeuronLogistic.cpp!
ar & boost::serialization::base_object<Neuron>(*this);
};
......
......@@ -8,9 +8,7 @@
#include "NeuronConstant.h"
NeuronConstant::NeuronConstant( double c ) {
this->p = c;
}
double NeuronConstant::activate( double x, double b ) {
......
......@@ -12,13 +12,16 @@
#include "Neuron.h"
class NeuronConstant: public Neuron, public IDifferentiable {
private:
friend class boost::serialization::access;
protected:
double p = 0.0;
template<class Archive>
void serialize(Archive & ar, const unsigned int version){
//TODO separate implementation to NeuronLinear.cpp!
ar & boost::serialization::base_object<Neuron>(*this);
ar & this->p;
};
public:
......@@ -54,7 +57,6 @@ public:
* @return
*/
Neuron* get_derivative( ) override;
private:
double p = 0.0;
};
#endif //INC_4NEURO_NEURONCONSTANT_H
......@@ -6,10 +6,7 @@
NeuronLinear::NeuronLinear( ) {
}
NeuronLinear::NeuronLinear( ) {}
double NeuronLinear::activate( double x, double b ) {
......
......@@ -20,12 +20,11 @@
* 'x' being the neuron's potential
*/
class NeuronLinear:public Neuron, public IDifferentiable {
private:
friend class boost::serialization::access;
protected:
template<class Archive>
void serialize(Archive & ar, const unsigned int version){
//TODO separate implementation to NeuronLinear.cpp!
ar & boost::serialization::base_object<Neuron>(*this);
};
......
......@@ -5,9 +5,7 @@
#include "NeuronLogistic.h"
NeuronLogistic_d2::NeuronLogistic_d2( ) {
}
NeuronLogistic_d2::NeuronLogistic_d2( ) {}
double NeuronLogistic_d2::activate( double x, double b ) {
//(e^(b + x) (e^b - e^x))/(e^b + e^x)^3
......@@ -40,9 +38,7 @@ NeuronLogistic* NeuronLogistic_d2::get_derivative() {
return nullptr;
}
NeuronLogistic_d1::NeuronLogistic_d1( ) {
}
NeuronLogistic_d1::NeuronLogistic_d1( ) {}
double NeuronLogistic_d1::activate( double x, double b ) {
......@@ -80,9 +76,7 @@ NeuronLogistic* NeuronLogistic_d1::get_derivative( ) {
return output;
}
NeuronLogistic::NeuronLogistic( ) {
}
NeuronLogistic::NeuronLogistic( ) {}
double NeuronLogistic::activate( double x, double b ) {
//(1 + e^(-x + b))^(-1)
......
......@@ -59,13 +59,15 @@ public:
class NeuronLogistic_d1:public NeuronLogistic {
private:
friend class boost::serialization::access;
protected:
template<class Archive>
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);
};
public:
/**
......@@ -106,13 +108,15 @@ public:
class NeuronLogistic_d2:public NeuronLogistic_d1 {
private:
friend class boost::serialization::access;
protected:
template<class Archive>
void serialize(Archive & ar, const unsigned int version){
//TODO separate implementation to NeuronLogistic_d1.cpp!
ar & boost::serialization::base_object<Neuron>(*this);
};
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