Skip to content
Snippets Groups Projects
NeuronLogistic.cpp 4.38 KiB
Newer Older
#include <boost/serialization/export.hpp>
#include "NeuronLogistic.h"
#include "NeuronSerialization.h"
#include "NeuronLogisticSerialization.h"

BOOST_CLASS_EXPORT_IMPLEMENT(lib4neuro::NeuronLogistic);
BOOST_CLASS_EXPORT_IMPLEMENT(lib4neuro::NeuronLogistic_d1);
BOOST_CLASS_EXPORT_IMPLEMENT(lib4neuro::NeuronLogistic_d2);
    NeuronLogistic_d2::NeuronLogistic_d2() {}
Martin Beseda's avatar
Martin Beseda committed
    double NeuronLogistic_d2::activate(double x,
                                       double b) {
        //(e^(b + x) (e^b - e^x))/(e^b + e^x)^3
        double ex    = std::pow(lib4neuro::E,
                                x);
        double eb    = std::pow(E,
                                b);
        return (eb * ex * (eb - ex)) / (denom * denom * denom);
Martin Beseda's avatar
Martin Beseda committed
    double NeuronLogistic_d2::activation_function_eval_derivative_bias(double x,
                                                                       double b) {
        //-(e^(b + x) (-4 e^(b + x) + e^(2 b) + e^(2 x)))/(e^b + e^x)^4
        double eb    = std::pow(E,
                                b);
        double ex    = std::pow(E,
                                x);
        double ebex  = eb * ex;
        return -(ebex * (-4 * ebex + eb * eb + ex * ex)) / (denom * denom * denom * denom);
    }
Martin Beseda's avatar
Martin Beseda committed
    double NeuronLogistic_d2::activation_function_eval_derivative(double x,
                                                                  double b) {
        //(e^(b + x) (-4 e^(b + x) + e^(2 b) + e^(2 x)))/(e^b + e^x)^4
Martin Beseda's avatar
Martin Beseda committed
        return -this->activation_function_eval_derivative_bias(x,
                                                               b);
Martin Beseda's avatar
Martin Beseda committed
    NeuronLogistic* NeuronLogistic_d2::get_derivative() {
        //TODO maybe not the best way
        return nullptr;
    }
    NeuronLogistic_d1::NeuronLogistic_d1() {}
Martin Beseda's avatar
Martin Beseda committed
    double NeuronLogistic_d1::activate(double x,
                                       double b) {
        double ex    = std::pow(E,
                                x);
        double eb    = std::pow(E,
                                b);
        double d     = (eb / ex);
Martin Beseda's avatar
Martin Beseda committed
    double NeuronLogistic_d1::activation_function_eval_derivative_bias(double x,
                                                                       double b) {
        //(e^(b + x) (e^x - e^b))/(e^b + e^x)^3
        double ex    = std::pow(E,
                                x);
        double eb    = std::pow(E,
                                b);
        return (eb * ex * (ex - eb)) / (denom * denom * denom);
    }
Martin Beseda's avatar
Martin Beseda committed
    double NeuronLogistic_d1::activation_function_eval_derivative(double x,
                                                                  double b) {
        //(e^(b + x) (e^b - e^x))/(e^b + e^x)^3
Martin Beseda's avatar
Martin Beseda committed
        return -this->activation_function_eval_derivative_bias(x,
                                                               b);
Martin Beseda's avatar
Martin Beseda committed
    NeuronLogistic* NeuronLogistic_d1::get_derivative() {
        //(e^(b + x) (e^b - e^x))/(e^b + e^x)^3
Martin Beseda's avatar
Martin Beseda committed
        NeuronLogistic_d2* output = nullptr;
Martin Beseda's avatar
Martin Beseda committed
    double NeuronLogistic::activate(double x,
                                    double b) {
Martin Beseda's avatar
Martin Beseda committed
        double ex = std::pow(E,
                             b - x);

        this->activation_val = 1.0 / (1.0 + ex);
        return this->activation_val;
Martin Beseda's avatar
Martin Beseda committed
    double NeuronLogistic::activation_function_eval_derivative_bias(double x,
                                                                    double b) {
        double ex    = std::pow(E,
                                b - x);
        double res   = -ex / (denom * denom);
Martin Beseda's avatar
Martin Beseda committed
    double NeuronLogistic::activation_function_eval_derivative(double x,
                                                               double b) {
Martin Beseda's avatar
Martin Beseda committed
        return -this->activation_function_eval_derivative_bias(x,
                                                               b);
Martin Beseda's avatar
Martin Beseda committed
    NeuronLogistic* NeuronLogistic::get_derivative() {
Martin Beseda's avatar
Martin Beseda committed
        NeuronLogistic_d1* output = nullptr;