Skip to content
Snippets Groups Projects
NeuronTanh.cpp 1.19 KiB
Newer Older
  • Learn to ignore specific revisions
  • //
    // Created by fluffymoo on 11.6.18.
    //
    
    #include "NeuronTanh.h"
    
    
    NeuronTanh::NeuronTanh(double a) {
    
        this->activation_function_parameters = new double[1];
        this->activation_function_parameters[0] = a;
    
    
        this->edges_in = new std::vector<Connection*>(0);
        this->edges_out = new std::vector<Connection*>(0);
    
    
    }
    
    void NeuronTanh::activate( ) {
    
        double a = this->activation_function_parameters[0];
        double x = this->potential;
        double ex = std::pow(E, x - a);
        double exi = 1.0 / ex;
    
        this->state = (ex - exi) / (ex + exi);
    
    }
    
    double NeuronTanh::activation_function_get_partial_derivative(int param_idx) {
    
        double a = this->activation_function_parameters[0];
        double x = this->potential;
    
        if(param_idx == 0){
            double ex = -4.0 * std::pow(E, 2.0 * (x + a));
            double exi = std::pow(E, 2.0 * a) + std::pow(E, 2.0 * x);
    
            return ex / (exi * exi);
        }
    
        return 0.0;
    
    }
    
    double NeuronTanh::activation_function_get_derivative( ) {
    
        double a = this->activation_function_parameters[0];
        double x = this->potential;
        double ex = -4.0 * std::pow(E, 2.0 * (x + a));
        double exi = std::pow(E, 2.0 * a) + std::pow(E, 2.0 * x);
    
        return ex / (exi * exi);
    }