3 #include <dlprim/definitions.hpp> 13 case StandardActivations::identity:
15 case StandardActivations::relu:
18 for(
size_t i=0;i<n;i++) {
19 p[i] = std::max(p[i],zero);
23 case StandardActivations::tanh:
25 for(
size_t i=0;i<n;i++) {
26 p[i] = std::tanh(p[i]);
30 case StandardActivations::sigmoid:
32 for(
size_t i=0;i<n;i++) {
33 p[i] = 1 / (1 + std::exp(-p[i]));
37 case StandardActivations::relu6:
40 for(
size_t i=0;i<n;i++) {
41 p[i] = std::min(std::max(p[i],zero),T(6));
49 inline void apply_activation_diff(
size_t n,T
const *y,T
const *dy,T *dx,
StandardActivations a)
52 case StandardActivations::identity:
54 for(
size_t i=0;i<n;i++) {
59 case StandardActivations::relu:
61 for(
size_t i=0;i<n;i++) {
62 dx[i] = y[i] > 0 ? dy[i] : 0;
66 case StandardActivations::tanh:
68 for(
size_t i=0;i<n;i++) {
70 dx[i] = dy[i] * (1-yv*yv);
74 case StandardActivations::sigmoid:
76 for(
size_t i=0;i<n;i++) {
78 dx[i] = dy[i] * yv * (1-yv);
82 case StandardActivations::relu6:
84 for(
size_t i=0;i<n;i++) {
85 dx[i] = (6 > y[i] && y[i] > 0) ? dy[i] : 0;
93 inline void apply_activation_diff(
size_t n,T
const *y,T
const *dy,T *dx,
float beta,
StandardActivations a)
96 apply_activation_diff(n,y,dy,dx,a);
100 case StandardActivations::identity:
102 for(
size_t i=0;i<n;i++) {
103 dx[i] = beta*dx[i] + dy[i];
107 case StandardActivations::relu:
109 for(
size_t i=0;i<n;i++) {
110 dx[i] = beta*dx[i] + (y[i] > 0 ? dy[i] : 0);
114 case StandardActivations::tanh:
116 for(
size_t i=0;i<n;i++) {
118 dx[i] = beta*dx[i] + (dy[i] * (1-yv*yv));
122 case StandardActivations::sigmoid:
124 for(
size_t i=0;i<n;i++) {
126 dx[i] = beta*dx[i] + (dy[i] * yv * (1-yv));
130 case StandardActivations::relu6:
132 for(
size_t i=0;i<n;i++) {
133 dx[i] = beta*dx[i] + (6 > y[i] && y[i] > 0 ? dy[i] : 0);
Mane namespace.
Definition: context.hpp:9
StandardActivations
Parameterless Activations that can be embedded to general kernels like inner product or convolution...
Definition: definitions.hpp:266