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

Revert "FIX: Fixed Neuron class structure"

This reverts commit 21af8ef1.
parent e20a1f32
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ namespace lib4neuro {
protected:
/**
* Holds the last value of the activation function, used by this->activate
* holds the last value of the activation function, used by this->activate
*/
double activation_val;
......@@ -64,24 +64,12 @@ namespace lib4neuro {
}; /* end of Neuron class */
/**
* Abstract clas providing the method get_derivative()
*/
class IGetDerivative {
public:
/**
* Returns a Neuron pointer object with activation function being the partial derivative of
* the activation function of this Neuron object with respect to the argument, i.e. 'potential'
* @return
*/
virtual Neuron* get_derivative() = 0;
};
/**
* Class serving as an interface providing 'activation_function_eval_partial_derivative',
* 'activation_function_eval_derivative', 'get_partial_derivative' and
* 'get_derivative' methods.
*/
/**
* Class serving as an interface providing 'activation_function_eval_partial_derivative',
* 'activation_function_eval_derivative', 'get_partial_derivative' and
* 'get_derivative' methods.
*/
class NeuronDifferentiable : public Neuron {
public:
/**
......@@ -96,6 +84,13 @@ namespace lib4neuro {
* and 'b' is the bias
*/
virtual double activation_function_eval_derivative_bias(double x, double b) = 0;
/**
* Returns a Neuron pointer object with activation function being the partial derivative of
* the activation function of this Neuron object with respect to the argument, i.e. 'potential'
* @return
*/
virtual Neuron *get_derivative() = 0;
};
}
......
......@@ -22,4 +22,5 @@ namespace lib4neuro {
return this->activation_val;
}
}
\ No newline at end of file
......@@ -14,9 +14,9 @@
namespace lib4neuro {
/**
* Binary neuron class - uses unit-step as the activation function
*/
/**
* Binary neuron class - uses unit-step as the activation function
*/
class NeuronBinary : public Neuron {
public:
......
......@@ -12,7 +12,7 @@
namespace lib4neuro {
class NeuronConstant : public NeuronDifferentiable, IGetDerivative {
class NeuronConstant : public NeuronDifferentiable {
private:
double p = 0.0;
......
......@@ -18,7 +18,7 @@ namespace lib4neuro {
* Linear neuron class - uses activation function in the form f(x)=a*x + b,
* 'x' being the neuron's potential
*/
class NeuronLinear:public NeuronDifferentiable, IGetDerivative {
class NeuronLinear:public NeuronDifferentiable {
public:
......
......@@ -43,10 +43,10 @@ namespace lib4neuro {
return -this->activation_function_eval_derivative_bias(x, b);
}
// NeuronLogistic *NeuronLogistic_d2::get_derivative() {
// //TODO maybe not the best way
// return nullptr;
// }
NeuronLogistic *NeuronLogistic_d2::get_derivative() {
//TODO maybe not the best way
return nullptr;
}
NeuronLogistic_d1::NeuronLogistic_d1() {}
......@@ -78,7 +78,7 @@ namespace lib4neuro {
return -this->activation_function_eval_derivative_bias(x, b);
}
NeuronDifferentiable* NeuronLogistic_d1::get_derivative() {
NeuronLogistic *NeuronLogistic_d1::get_derivative() {
//(e^(b + x) (e^b - e^x))/(e^b + e^x)^3
NeuronLogistic_d2 *output = nullptr;
......@@ -113,7 +113,7 @@ namespace lib4neuro {
}
NeuronDifferentiable* NeuronLogistic::get_derivative() {
NeuronLogistic *NeuronLogistic::get_derivative() {
NeuronLogistic_d1 *output = nullptr;
output = new NeuronLogistic_d1();
......
......@@ -16,7 +16,7 @@
#include "Neuron.h"
namespace lib4neuro {
class NeuronLogistic : public NeuronDifferentiable, IGetDerivative {
class NeuronLogistic : public NeuronDifferentiable {
public:
......@@ -54,7 +54,7 @@ namespace lib4neuro {
* Returns a pointer to a Neuron with derivative as its activation function
* @return
*/
LIB4NEURO_API virtual NeuronDifferentiable* get_derivative() override;
LIB4NEURO_API virtual NeuronLogistic *get_derivative() override;
};
......@@ -78,7 +78,7 @@ namespace lib4neuro {
/**
* Evaluates 'e^(b - x)/(e^(b - x) + 1)^2' and returns the result
*/
LIB4NEURO_API double activate(double x, double b) override;
LIB4NEURO_API virtual double activate(double x, double b) override;
/**
* Calculates the partial derivative of the activation function
......@@ -86,23 +86,23 @@ namespace lib4neuro {
* @return Partial derivative of the activation function according to the
* bias, returns: (e^(b + x) (e^x - e^b))/(e^b + e^x)^3
*/
LIB4NEURO_API double activation_function_eval_derivative_bias(double x, double b) override;
LIB4NEURO_API virtual double activation_function_eval_derivative_bias(double x, double b) override;
/**
* Calculates d/dx of e^(b - x)*(1 + e^(b - x))^(-2)
* @return (e^(b + x) (e^b - e^x))/(e^b + e^x)^3
*/
LIB4NEURO_API double activation_function_eval_derivative(double x, double b) override;
LIB4NEURO_API virtual double activation_function_eval_derivative(double x, double b) override;
/**
* Returns a pointer to a Neuron with derivative as its activation function
* @return
*/
LIB4NEURO_API NeuronDifferentiable* get_derivative() override;
LIB4NEURO_API virtual NeuronLogistic *get_derivative() override;
};
class NeuronLogistic_d2 : public NeuronDifferentiable {
class NeuronLogistic_d2 : public NeuronLogistic_d1 {
public:
......@@ -121,7 +121,7 @@ namespace lib4neuro {
/**
* Evaluates '(e^(b + x) (e^b - e^x))/(e^b + e^x)^3' and returns the result
*/
LIB4NEURO_API double activate(double x, double b) override;
LIB4NEURO_API virtual double activate(double x, double b) override;
/**
* Calculates the partial derivative of the activation function
......@@ -129,19 +129,19 @@ namespace lib4neuro {
* @return Partial derivative of the activation function according to the
* bias, returns: -(e^(b + x) (-4 e^(b + x) + e^(2 b) + e^(2 x)))/(e^b + e^x)^4
*/
LIB4NEURO_API double activation_function_eval_derivative_bias(double x, double b) override;
LIB4NEURO_API virtual double activation_function_eval_derivative_bias(double x, double b) override;
/**
* Calculates d/dx of (e^(b + x) (e^b - e^x))/(e^b + e^x)^3
* @return (e^(b + x) (-4 e^(b + x) + e^(2 b) + e^(2 x)))/(e^b + e^x)^4
*/
LIB4NEURO_API double activation_function_eval_derivative(double x, double b) override;
LIB4NEURO_API virtual double activation_function_eval_derivative(double x, double b) override;
/**
*
* @return
*/
// LIB4NEURO_API virtual NeuronLogistic *get_derivative() override;
LIB4NEURO_API virtual NeuronLogistic *get_derivative() override;
};
......
......@@ -29,14 +29,14 @@ namespace lib4neuro {
struct NeuronLogistic_d1::access {
template<class Archive>
static void serialize(Archive &ar, NeuronLogistic_d1 &n, const unsigned int version) {
ar & boost::serialization::base_object<Neuron>(n);
ar & boost::serialization::base_object<NeuronLogistic>(n);
}
};
struct NeuronLogistic_d2::access {
template<class Archive>
static void serialize(Archive &ar, NeuronLogistic_d2 &n, const unsigned int version) {
ar & boost::serialization::base_object<Neuron>(n);
ar & boost::serialization::base_object<NeuronLogistic_d1>(n);
}
};
......
......@@ -261,7 +261,7 @@ namespace lib4neuro {
for (size_t j = 0; j < derivative_degree; ++j) {
n_ptr2 = n_ptr;
n_ptr = dynamic_cast<NeuronLogistic*>(n_ptr->get_derivative());
n_ptr = n_ptr->get_derivative();
if (j > 0) {
delete n_ptr2;
......
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