Apache SINGA
A distributed deep learning platform .
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros
cxxnet_op.h
Go to the documentation of this file.
1 #ifndef CXXNET_OP_H
2 #define CXXNET_OP_H
3 #pragma once
4 
9 #include "mshadow/tensor.h"
10 
11 namespace mshadow {
13  namespace op {
14  struct sigmoid {
15  MSHADOW_XINLINE static real_t Map(real_t a) {
16  return 1.0f / (1.0f + expf(-a));
17  }
18  };
19  struct sigmoid_grad {
20  MSHADOW_XINLINE static real_t Map(real_t a) {
21  return a * ( 1.0f - a );
22  }
23  };
24 
26  struct relu {
27  MSHADOW_XINLINE static real_t Map(real_t a) {
28  using namespace std;
29  return max( a, 0.0f );
30  }
31  };
32  struct relu_grad {
33  MSHADOW_XINLINE static real_t Map(real_t a) {
34  return a > 0.0f ? 1.0f : 0.0f;
35  }
36  };
37 
38  struct tanh {
39  MSHADOW_XINLINE static real_t Map(real_t a) {
40  return tanhf( a );
41  }
42  };
43  struct tanh_grad {
44  MSHADOW_XINLINE static real_t Map(real_t a) {
45  return 1.0f - a * a;
46  }
47  };
48  struct softplus {
49  MSHADOW_XINLINE static real_t Map(real_t a) {
50  return logf(1 + expf(a));
51  }
52  };
53  struct softplus_grad {
54  MSHADOW_XINLINE static real_t Map(real_t a) {
55  return 1.0f / (1.0f + expf(-a));
56  }
57  };
58  struct bnll {
59  MSHADOW_XINLINE static real_t Map(real_t a) {
60  return a > 0.0f ? a + logf(1.0f + expf(-a)) : logf(1.0f + expf(a));
61  }
62  };
63  struct bnll_grad {
64  MSHADOW_XINLINE static real_t Map(real_t a) {
65  real_t expval = a > 50.0f ? 50.0f : a; // kBNLL_THRESHOLD = 50.0f
66  expval = expf(-expval);
67  return 1.0f / (1.0f + expval);
68  }
69  };
70 
71  struct square {
72  MSHADOW_XINLINE static real_t Map(real_t a) {
73  return a * a;
74  }
75  };
77  struct stanh {
78  MSHADOW_XINLINE static real_t Map(real_t a) {
79  return 1.7159047*tanhf(0.66666667 *a);
80  }
81  };
83  struct stanh_grad {
84  MSHADOW_XINLINE static real_t Map(real_t a) {
85  return 0.66666667*1.7159047 -0.66666667/1.7159047*a*a;
86  }
87  };
88 
89  }; //namespace op
90 
91 }; //namespace mshadow
92 
93 namespace mshadow {
94  namespace op {
96  struct threshold {
97  MSHADOW_XINLINE static real_t Map(real_t a, real_t b) {
98  return a < b ? 1.0f : 0.0f;
99  }
100  };
101 
103  struct power {
104  MSHADOW_XINLINE static real_t Map(real_t a, real_t b) {
105  return powf( a, b );
106  }
107  };
108  struct sqrtop {
109  MSHADOW_XINLINE static real_t Map(real_t a, real_t b) {
110  return sqrt(a+b);
111  }
112  };
113  }; // namespace op
114 }; // namespace mshadow
115 
116 #endif // CXXNET_OP_H
Definition: cxxnet_op.h:43
Definition: cxxnet_op.h:63
Definition: cxxnet_op.h:32
scaled tanh, hard code the scale factor
Definition: cxxnet_op.h:77
float real_t
type that will be used for content
Definition: tensor_base.h:118
Rectified Linear Operation.
Definition: cxxnet_op.h:26
header file of tensor data structure and functions covention: this lib requires explicit memory alloc...
used for generate Bernoulli mask
Definition: cxxnet_op.h:96
Definition: cxxnet_op.h:19
Definition: cxxnet_op.h:71
used for generate element of power
Definition: cxxnet_op.h:103
Definition: cxxnet_op.h:83
Definition: cxxnet_op.h:38
Definition: cxxnet_op.h:48
Definition: cxxnet_op.h:108
Definition: cxxnet_op.h:14
Definition: cxxnet_op.h:58
Definition: cxxnet_op.h:53