diff options
Diffstat (limited to 'src/lib/src/activation.h')
-rw-r--r-- | src/lib/src/activation.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lib/src/activation.h b/src/lib/src/activation.h new file mode 100644 index 0000000..42ab73f --- /dev/null +++ b/src/lib/src/activation.h | |||
@@ -0,0 +1,21 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <neuralnet/types.h> | ||
4 | |||
5 | #include <math.h> | ||
6 | |||
7 | static inline R sigmoid(R x) { | ||
8 | return 1. / (1. + exp(-x)); | ||
9 | } | ||
10 | |||
11 | static inline R relu(R x) { | ||
12 | return fmax(0, x); | ||
13 | } | ||
14 | |||
15 | #define NN_MAP_ARRAY(f, in, out, size) \ | ||
16 | for (int i = 0; i < size; ++i) { \ | ||
17 | out[i] = f(in[i]); \ | ||
18 | } | ||
19 | |||
20 | #define sigmoid_array(in, out, size) NN_MAP_ARRAY(sigmoid, in, out, size) | ||
21 | #define relu_array(in, out, size) NN_MAP_ARRAY(relu, in, out, size) | ||