Skip to content
Snippets Groups Projects
NeuronLogistic.h 4.58 KiB
Newer Older
  • Learn to ignore specific revisions
  • /**
     * DESCRIPTION OF THE CLASS
     *
     * @author Martin Beseda
     * @author Martin Mrovec
     * @author Michal Kravčenko
     * @date 2017 - 2018
     */
    
    
    #ifndef INC_4NEURO_NEURONLOGISTIC_H
    #define INC_4NEURO_NEURONLOGISTIC_H
    
    
        class NeuronLogistic : public NeuronDifferentiable {
    
    
        public:
    
            /**
             * Struct used to access private properties from
             * the serialization function
             */
            struct access;
    
            /**
             * Constructs the object of the Logistic neuron with activation function
             * f(x) = (1 + e^(-x + b))^(-1)
             */
            LIB4NEURO_API explicit NeuronLogistic();
    
            /**
             * Evaluates '(1 + e^(-x + b))^(-1)' and stores the result into the 'state' property
             */
            LIB4NEURO_API virtual double activate(double x, double b) override;
    
            /**
             * Calculates the partial derivative of the activation function
             * f(x) = (1 + e^(-x + b))^(-1)
             * @return Partial derivative of the activation function according to the
             * bias, returns: -e^(b - x)/(e^(b - x) + 1)^2
             */
            LIB4NEURO_API virtual double activation_function_eval_derivative_bias(double x, double b) override;
            /**
             * Calculates d/dx of (1 + e^(-x + b))^(-1)
             * @return e^(b - x)/(e^(b - x) + 1)^2
             */
            LIB4NEURO_API virtual double activation_function_eval_derivative(double x, double b) override;
    
            /**
             * Returns a pointer to a Neuron with derivative as its activation function
             * @return
             */
            LIB4NEURO_API virtual NeuronLogistic *get_derivative() override;
        };
    
    
        class NeuronLogistic_d1 : public NeuronLogistic {
    
        public:
    
            /**
             * Struct used to access private properties from
             * the serialization function
             */
            struct access;
    
            /**
             * Constructs the object of the Logistic neuron with activation function
             * f(x) = e^(b - x)/(e^(b - x) + 1)^2
             * @param[in] b Bias
             */
            LIB4NEURO_API explicit NeuronLogistic_d1();
    
            /**
             * Evaluates 'e^(b - x)/(e^(b - x) + 1)^2' and returns the result
             */
            LIB4NEURO_API virtual double activate(double x, double b) override;
    
            /**
             * Calculates the partial derivative of the activation function
             * f(x) = e^(b - x)/(e^(b - x) + 1)^2
             * @return Partial derivative of the activation function according to the
             * bias, returns: (e^(b + x) (e^x - e^b))/(e^b + e^x)^3
             */
            LIB4NEURO_API virtual double activation_function_eval_derivative_bias(double x, double b) override;
    
            /**
             * Calculates d/dx of  e^(b - x)*(1 + e^(b - x))^(-2)
             * @return  (e^(b + x) (e^b - e^x))/(e^b + e^x)^3
             */
            LIB4NEURO_API virtual double activation_function_eval_derivative(double x, double b) override;
    
            /**
             * Returns a pointer to a Neuron with derivative as its activation function
             * @return
             */
            LIB4NEURO_API virtual NeuronLogistic *get_derivative() override;
        };
    
    
        class NeuronLogistic_d2 : public NeuronLogistic_d1 {
    
        public:
    
            /**
             * Struct used to access private properties from
             * the serialization function
             */
            struct access;
    
            /**
             * Constructs the object of the Logistic neuron with activation function
             * f(x) = (e^(b + x) (e^b - e^x))/(e^b + e^x)^3
             */
            LIB4NEURO_API explicit NeuronLogistic_d2();
    
            /**
             * Evaluates '(e^(b + x) (e^b - e^x))/(e^b + e^x)^3' and returns the result
             */
            LIB4NEURO_API virtual double activate(double x, double b) override;
    
            /**
             * Calculates the partial derivative of the activation function
             * f(x) = (e^(b + x) (e^b - e^x))/(e^b + e^x)^3
             * @return Partial derivative of the activation function according to the
             * bias, returns: -(e^(b + x) (-4 e^(b + x) + e^(2 b) + e^(2 x)))/(e^b + e^x)^4
             */
            LIB4NEURO_API virtual double activation_function_eval_derivative_bias(double x, double b) override;
    
            /**
             * Calculates d/dx of  (e^(b + x) (e^b - e^x))/(e^b + e^x)^3
             * @return (e^(b + x) (-4 e^(b + x) + e^(2 b) + e^(2 x)))/(e^b + e^x)^4
             */
            LIB4NEURO_API virtual double activation_function_eval_derivative(double x, double b) override;
    
            /**
             *
             * @return
             */
            LIB4NEURO_API virtual NeuronLogistic *get_derivative() override;
    
        };
    
    }
    
    #endif //INC_4NEURO_NEURONLOGISTIC_H