Newer
Older
//
// Created by fluffymoo on 11.6.18.
//
Martin Beseda
committed
#include <boost/serialization/export.hpp>
Martin Beseda
committed
#include "NeuronSerialization.h"
#include "NeuronLogisticSerialization.h"
BOOST_CLASS_EXPORT_IMPLEMENT(NeuronLogistic);
BOOST_CLASS_EXPORT_IMPLEMENT(NeuronLogistic_d1);
BOOST_CLASS_EXPORT_IMPLEMENT(NeuronLogistic_d2);
NeuronLogistic_d2::NeuronLogistic_d2( ) {}

Michal Kravcenko
committed

Michal Kravcenko
committed
double NeuronLogistic_d2::activate( double x, double b ) {

Michal Kravcenko
committed
double ex = std::pow(E, x);
double eb = std::pow(E, b);

Michal Kravcenko
committed
double denom = (eb + ex);

Michal Kravcenko
committed

Michal Kravcenko
committed
return (eb*ex*(eb - ex))/(denom*denom*denom);

Michal Kravcenko
committed
}

Michal Kravcenko
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

Michal Kravcenko
committed
double eb = std::pow(E, b);
double ex = std::pow(E, x);

Michal Kravcenko
committed
double ebex = eb * ex;
double denom = (eb + ex);

Michal Kravcenko
committed

Michal Kravcenko
committed
return -(ebex*(-4*ebex + eb*eb +ex*ex))/(denom*denom*denom*denom);

Michal Kravcenko
committed
}

Michal Kravcenko
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

Michal Kravcenko
committed
return -this->activation_function_eval_derivative_bias( x, b );

Michal Kravcenko
committed
}
NeuronLogistic* NeuronLogistic_d2::get_derivative() {
//TODO maybe not the best way
return nullptr;

Michal Kravcenko
committed
}
NeuronLogistic_d1::NeuronLogistic_d1( ) {}

Michal Kravcenko
committed

Michal Kravcenko
committed
double NeuronLogistic_d1::activate( double x, double b ) {

Michal Kravcenko
committed
double ex = std::pow(E, x);
double eb = std::pow(E, b);
double d = (eb/ex);

Michal Kravcenko
committed
double denom = (d + 1);

Michal Kravcenko
committed

Michal Kravcenko
committed
return d/(denom*denom);

Michal Kravcenko
committed
}

Michal Kravcenko
committed
double NeuronLogistic_d1::activation_function_eval_derivative_bias( double x, double b ) {

Michal Kravcenko
committed
double ex = std::pow(E, x);
double eb = std::pow(E, b);

Michal Kravcenko
committed
double denom = (eb + ex);

Michal Kravcenko
committed

Michal Kravcenko
committed
return (eb*ex* (ex - eb))/(denom*denom*denom);

Michal Kravcenko
committed
}

Michal Kravcenko
committed
double NeuronLogistic_d1::activation_function_eval_derivative( double x, double b ) {

Michal Kravcenko
committed
return -this->activation_function_eval_derivative_bias( x, b );

Michal Kravcenko
committed
NeuronLogistic* NeuronLogistic_d1::get_derivative( ) {
//(e^(b + x) (e^b - e^x))/(e^b + e^x)^3

Michal Kravcenko
committed
NeuronLogistic_d2* output = nullptr;

Michal Kravcenko
committed
output = new NeuronLogistic_d2( );

Michal Kravcenko
committed
return output;
}
NeuronLogistic::NeuronLogistic( ) {}

Michal Kravcenko
committed
double NeuronLogistic::activate( double x, double b ) {

Michal Kravcenko
committed
return 1.0 / (1.0 + ex);

Michal Kravcenko
committed
double NeuronLogistic::activation_function_eval_derivative_bias( double x, double b ) {
//-e^(b - x)/(e^(b - x) + 1)^2
double ex = std::pow(E, b - x);

Michal Kravcenko
committed
double denom = (ex + 1);

Michal Kravcenko
committed
return -ex/(denom*denom);

Michal Kravcenko
committed

Michal Kravcenko
committed
double NeuronLogistic::activation_function_eval_derivative( double x, double b ) {

Michal Kravcenko
committed
return -this->activation_function_eval_derivative_bias( x, b );

Michal Kravcenko
committed
}
NeuronLogistic* NeuronLogistic::get_derivative( ) {

Michal Kravcenko
committed

Michal Kravcenko
committed
NeuronLogistic_d1 *output = nullptr;

Michal Kravcenko
committed
output = new NeuronLogistic_d1( );

Michal Kravcenko
committed
return output;

Michal Kravcenko
committed