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