diff --git a/src/Neuron/Neuron.h b/src/Neuron/Neuron.h index 6900c36f3d26331b825e7d36f2c56e9a3fc9e555..88747a63ef073600dae1bce06bf9f34b4f4c0c61 100644 --- a/src/Neuron/Neuron.h +++ b/src/Neuron/Neuron.h @@ -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; }; } diff --git a/src/Neuron/NeuronBinary.cpp b/src/Neuron/NeuronBinary.cpp index 652559617ae3025ef3188c6bc89f934dc8d7f94a..9e7bbb80d616a0b56fbfbdecd021e28021ab4b36 100644 --- a/src/Neuron/NeuronBinary.cpp +++ b/src/Neuron/NeuronBinary.cpp @@ -22,4 +22,5 @@ namespace lib4neuro { return this->activation_val; } + } \ No newline at end of file diff --git a/src/Neuron/NeuronBinary.h b/src/Neuron/NeuronBinary.h index 717cbab2a9589ee453191a6340749ef7c0c18aae..1992b03fa3495787b9da990ebe54139d1b59c6f6 100644 --- a/src/Neuron/NeuronBinary.h +++ b/src/Neuron/NeuronBinary.h @@ -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: diff --git a/src/Neuron/NeuronConstant.h b/src/Neuron/NeuronConstant.h index b59f6bf38eab837c3d4dfa732a409155c2f8d941..71e43013630f8d5f6bf1caded440113468719505 100644 --- a/src/Neuron/NeuronConstant.h +++ b/src/Neuron/NeuronConstant.h @@ -12,7 +12,7 @@ namespace lib4neuro { - class NeuronConstant : public NeuronDifferentiable, IGetDerivative { + class NeuronConstant : public NeuronDifferentiable { private: double p = 0.0; diff --git a/src/Neuron/NeuronLinear.h b/src/Neuron/NeuronLinear.h index 2db91345d746435dea2d0fb0dcba44994475f38a..d7043f932180790965b2a55b4ba8285ff949e469 100644 --- a/src/Neuron/NeuronLinear.h +++ b/src/Neuron/NeuronLinear.h @@ -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: diff --git a/src/Neuron/NeuronLogistic.cpp b/src/Neuron/NeuronLogistic.cpp index 9403784db8bb299dabd408efd9850b8ab6759c86..dd1469d794c4a4dbba8e3c847bed287a76f42674 100644 --- a/src/Neuron/NeuronLogistic.cpp +++ b/src/Neuron/NeuronLogistic.cpp @@ -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(); diff --git a/src/Neuron/NeuronLogistic.h b/src/Neuron/NeuronLogistic.h index 45cd4f45b78a2ce7129d00498cc0c0a06f91bc69..9daf384bf05def06eec5038880371d23cf175d39 100644 --- a/src/Neuron/NeuronLogistic.h +++ b/src/Neuron/NeuronLogistic.h @@ -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; }; diff --git a/src/Neuron/NeuronLogisticSerialization.h b/src/Neuron/NeuronLogisticSerialization.h index 4bb0311fdefbba8bf73d17aee5a514c3811f4b50..1d65fcba360ff47d9fcc4baeec740c1746f430de 100644 --- a/src/Neuron/NeuronLogisticSerialization.h +++ b/src/Neuron/NeuronLogisticSerialization.h @@ -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); } }; diff --git a/src/Solvers/DESolver.cpp b/src/Solvers/DESolver.cpp index a963f35aeca5cd2f175a091b6cdf4cd6a361361c..e201c565c3ef2186a3ce87da5741e778c8c2e317 100644 --- a/src/Solvers/DESolver.cpp +++ b/src/Solvers/DESolver.cpp @@ -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;