-
Notifications
You must be signed in to change notification settings - Fork 0
/
activation_functions.h
executable file
·55 lines (42 loc) · 1.8 KB
/
activation_functions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/******************************************************
*
* ACTIVATION FUNCTIONS FOR FEEDFORWARD LAYERS
*
******************************************************/
/*!
* \brief Activation functions for feedforward layers.
* \details This class implements the sigmoid, softplus and silu activation functions, along with their derivatives.
*/
#ifndef ACTIVATION_FUNCTIONS_H
#define ACTIVATION_FUNCTION_H
#include<math.h>
#include<vector>
#include<iostream>
#include<omp.h>
#include"Eigen/Dense"
//Simgoid activation function
double sigmoid(double x,double max_exp,double exp_zero_approx);
//First derivative of sigmoid
double sigmoid_derivative(double x,double max_exp,double exp_zero_approx);
//Vectorized sigmoid
Eigen::VectorXd sigmoid(Eigen::VectorXd & x, double & max_exp,double & exp_zero_approx);
std::vector<Eigen::VectorXd> sigmoid(std::vector<Eigen::VectorXd> & x, double & max_exp,double & exp_zero_approx);
//Softplus activation function
double softplus(double x,double max_exp);
//First derivative of softplus
double softplus_derivative(double x,double max_exp);
//SiLu
double silu(double x,double max_exp,double exp_zero_approx);
//SiLu derivative
double silu_derivative(double x,double max_exp,double exp_zero_approx);
//argmax
Eigen::VectorXd argmax(const Eigen::VectorXd &input);
//Normalize the input std::vector wiht softmax
Eigen::VectorXd softmax(const std::vector<double> & input);
//Normalize the input Eigen::VectorXd wiht softmax
Eigen::VectorXd softmax(const Eigen::VectorXd & input);
//Compute the jacobian of the softmax at a point given by a std::vector
Eigen::MatrixXd softmax_jacobian(const std::vector<double> &input);
//Compute the jacobian of the softmax at a point given by a Eigen::VectorXd
Eigen::MatrixXd softmax_jacobian(const Eigen::VectorXd &input);
#endif /* ACTIVATION_FUNCTION_ H*/