Newer
Older
Martin Beseda
committed
#include <boost/serialization/export.hpp>
Martin Beseda
committed
#include "NeuronSerialization.h"
#include "NeuronLogisticSerialization.h"
Martin Beseda
committed
BOOST_CLASS_EXPORT_IMPLEMENT(lib4neuro::NeuronLogistic);
BOOST_CLASS_EXPORT_IMPLEMENT(lib4neuro::NeuronLogistic_d1);
BOOST_CLASS_EXPORT_IMPLEMENT(lib4neuro::NeuronLogistic_d2);
Martin Beseda
committed
namespace lib4neuro {

Michal Kravcenko
committed
Martin Beseda
committed
NeuronLogistic_d2::NeuronLogistic_d2() {}

Michal Kravcenko
committed
double NeuronLogistic_d2::activate(double x,
double b) {
Martin Beseda
committed
//(e^(b + x) (e^b - e^x))/(e^b + e^x)^3

Michal Kravcenko
committed
double ex = std::pow(lib4neuro::E,
x);
double eb = std::pow(E,
b);
Martin Beseda
committed
double denom = (eb + ex);

Michal Kravcenko
committed
kra568
committed
return (eb * ex * (eb - ex)) / (denom * denom * denom);
Martin Beseda
committed
}

Michal Kravcenko
committed
double NeuronLogistic_d2::activation_function_eval_derivative_bias(double x,
double b) {
Martin Beseda
committed
//-(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);
double ebex = eb * ex;
Martin Beseda
committed
double denom = (eb + ex);

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

Michal Kravcenko
committed
double NeuronLogistic_d2::activation_function_eval_derivative(double x,
double b) {
Martin Beseda
committed
//(e^(b + x) (-4 e^(b + x) + e^(2 b) + e^(2 x)))/(e^b + e^x)^4
return -this->activation_function_eval_derivative_bias(x,
b);
Martin Beseda
committed
}

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

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

Michal Kravcenko
committed

Michal Kravcenko
committed
double NeuronLogistic_d1::activate(double x,
double b) {
Martin Beseda
committed
//e^(b - x)/(e^(b - x) + 1)^2

Michal Kravcenko
committed
double ex = std::pow(E,
x);
double eb = std::pow(E,
b);
double d = (eb / ex);
Martin Beseda
committed
double denom = (d + 1);

Michal Kravcenko
committed
kra568
committed
return d / (denom * denom);
Martin Beseda
committed
}

Michal Kravcenko
committed
double NeuronLogistic_d1::activation_function_eval_derivative_bias(double x,
double b) {
Martin Beseda
committed
//(e^(b + x) (e^x - e^b))/(e^b + e^x)^3

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

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

Michal Kravcenko
committed
double NeuronLogistic_d1::activation_function_eval_derivative(double x,
double b) {
Martin Beseda
committed
//(e^(b + x) (e^b - e^x))/(e^b + e^x)^3
return -this->activation_function_eval_derivative_bias(x,
b);
Martin Beseda
committed
}

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

Michal Kravcenko
committed
Martin Beseda
committed
output = new NeuronLogistic_d2();

Michal Kravcenko
committed
Martin Beseda
committed
return output;
}
Martin Beseda
committed
NeuronLogistic::NeuronLogistic() {}
double NeuronLogistic::activate(double x,
double b) {
Martin Beseda
committed
//(1 + e^(-x + b))^(-1)

Michal Kravcenko
committed
this->activation_val = 1.0 / (1.0 + ex);
return this->activation_val;
Martin Beseda
committed
}
double NeuronLogistic::activation_function_eval_derivative_bias(double x,
double b) {
Martin Beseda
committed
double denom = (ex + 1);
Martin Beseda
committed
return res;
Martin Beseda
committed
}

Michal Kravcenko
committed
double NeuronLogistic::activation_function_eval_derivative(double x,
double b) {
Martin Beseda
committed
//e^(b - x)/(e^(b - x) + 1)^2
return -this->activation_function_eval_derivative_bias(x,
b);

Michal Kravcenko
committed
Martin Beseda
committed
}

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

Michal Kravcenko
committed
Martin Beseda
committed
output = new NeuronLogistic_d1();
return output;
}

Michal Kravcenko
committed