Skip to content
Snippets Groups Projects
NeuronLogistic.cpp 2.73 KiB
Newer Older
  • Learn to ignore specific revisions
  • //
    // Created by fluffymoo on 11.6.18.
    //
    
    
    #include "NeuronLogistic.h"
    
    NeuronLogistic_d2::NeuronLogistic_d2( ) {}
    
    double NeuronLogistic_d2::activate( double x, double b ) {
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
        //(e^(b + x) (e^b - e^x))/(e^b + e^x)^3
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
        double ex = std::pow(E, x);
        double eb = std::pow(E, b);
    
        return (eb*ex*(eb - ex))/(denom*denom*denom);
    
    double NeuronLogistic_d2::activation_function_eval_derivative_bias( double x, double b ) {
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
        //-(e^(b + x) (-4 e^(b + x) + e^(2 b) + e^(2 x)))/(e^b + e^x)^4
    
        double ebex = eb * ex;
        double denom = (eb + ex);
    
        return  -(ebex*(-4*ebex + eb*eb +ex*ex))/(denom*denom*denom*denom);
    
    double NeuronLogistic_d2::activation_function_eval_derivative( double x, double b ) {
    
    Michal Kravcenko's avatar
    Michal Kravcenko 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 );
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
    NeuronLogistic* NeuronLogistic_d2::get_derivative() {
        //TODO maybe not the best way
        return nullptr;
    
    NeuronLogistic_d1::NeuronLogistic_d1( ) {}
    
    double NeuronLogistic_d1::activate( double x, double b ) {
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
        //e^(b - x)/(e^(b - x) + 1)^2
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
        double ex = std::pow(E, x);
        double eb = std::pow(E, b);
        double d = (eb/ex);
    
    double NeuronLogistic_d1::activation_function_eval_derivative_bias( double x, double b ) {
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
        //(e^(b + x) (e^x - e^b))/(e^b + e^x)^3
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
        double ex = std::pow(E, x);
        double eb = std::pow(E, b);
    
        return (eb*ex* (ex - eb))/(denom*denom*denom);
    
    double NeuronLogistic_d1::activation_function_eval_derivative( double x, double b ) {
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
        //(e^(b + x) (e^b - e^x))/(e^b + e^x)^3
    
        return -this->activation_function_eval_derivative_bias( x, b );
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
    NeuronLogistic* NeuronLogistic_d1::get_derivative( ) {
        //(e^(b + x) (e^b - e^x))/(e^b + e^x)^3
    
    NeuronLogistic::NeuronLogistic( ) {}
    
    double NeuronLogistic::activate( double x, double b ) {
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
        //(1 + e^(-x + b))^(-1)
    
        double ex = std::pow(E, b - x);
    
    double NeuronLogistic::activation_function_eval_derivative_bias( double x, double b ) {
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
        //-e^(b - x)/(e^(b - x) + 1)^2
        double ex = std::pow(E, b - x);
    
    double NeuronLogistic::activation_function_eval_derivative( double x, double b ) {
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
        //e^(b - x)/(e^(b - x) + 1)^2
    
        return -this->activation_function_eval_derivative_bias( x, b );
    
    Michal Kravcenko's avatar
    Michal Kravcenko committed
    NeuronLogistic* NeuronLogistic::get_derivative( ) {