#ifndef __CORTEX_ACTIVATIONS_HEADER__ #define __CORTEX_ACTIVATIONS_HEADER__ #include "basicData.h" //#include "../cuda/cuda.h" ACTIVATION getActivation(char *s); char *getActivationString(ACTIVATION a); float activate(float x, ACTIVATION a); float gradient(float x, ACTIVATION a); void gradientArray(float *x, uint32_t n, ACTIVATION a, float *delta); void activateArray(float *x, uint32_t n, ACTIVATION a); static inline float stair_activate(float x) { int n = (int)floor(x); if (n%2 == 0) return (float)floor(x/2.f); else return (float)((x - n) + floor(x/2.f)); } static inline float hardtan_activate(float x) { if (x < -1) return -1; if (x > 1) return 1; return x; } static inline float linear_activate(float x){return x;} static inline float logistic_activate(float x){return (float)(1.f/(1.f + exp(-x)));} static inline float loggy_activate(float x){return (float)(2.f/(1.f + exp(-x)) - 1.f);} static inline float relu_activate(float x){return x*(x>0.f);} static inline float elu_activate(float x){return (float)((x >= 0.f)*x + (x < 0.f)*(exp(x)-1.f));} static inline float relie_activate(float x){return (x>0.f) ? x : .01f*x;} static inline float ramp_activate(float x){return x*(x>0.f)+.1f*x;} static inline float leaky_activate(float x){return (x>0.f) ? x : .1f*x;} static inline float tanh_activate(float x){return (float)((exp(2.f*x)-1.f)/(exp(2.f*x)+1.f));} static inline float plse_activate(float x) { if(x < -4.f) return .01f * (x + 4.f); if(x > 4.f) return .01f * (x - 4.f) + 1.f; return .125f*x + .5f; } static inline float lhtan_activate(float x) { if(x < 0.f) return .001f*x; if(x > 1.f) return .001f*(x-1.f) + 1.f; return x; } static inline float lhtan_gradient(float x) { if(x > 0.f && x < 1.f) return 1.f; return .001f; } static inline float hardtan_gradient(float x) { if (x > -1.f && x < 1.f) return 1.f; return 0.f; } static inline float linear_gradient(float x){return 1.f;} static inline float logistic_gradient(float x){return (1.f-x)*x;} static inline float loggy_gradient(float x) { float y = (x+1.f)/2.f; return 2.f*(1.f-y)*y; } static inline float stair_gradient(float x) { if (floor(x) == x) return 0.f; return 1.f; } static inline float relu_gradient(float x){return (float)(x>0.f);} static inline float elu_gradient(float x){return (x >= 0.f) + (x < 0.f)*(x + 1.f);} static inline float relie_gradient(float x){return (x>0.f) ? 1.f : .01f;} static inline float ramp_gradient(float x){return (x>0.f)+.1f;} static inline float leaky_gradient(float x){return (x>0.f) ? 1.f : .1f;} static inline float tanh_gradient(float x){return 1.f-x*x;} static inline float plse_gradient(float x){return (x < 0.f || x > 1.f) ? .01f : .125f;} #endif