aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2021-01-12 15:51:48 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commita96ec5a74093eb800d14e143b81302d3e0905b85 (patch)
treee555252fe9003b8bb0ae648e031c0fe90d8e72bc /include
parent67dd4ba3a9adc6a9db8eb543480e9e82310eeccb (diff)
one output (of course), Pade approximant of logistic for activation
Diffstat (limited to 'include')
-rw-r--r--include/ct1975.c (renamed from include/ct1973.c)22
-rw-r--r--include/ct1975.h (renamed from include/ct1973.h)1
-rw-r--r--include/weights.h7
3 files changed, 14 insertions, 16 deletions
diff --git a/include/ct1973.c b/include/ct1975.c
index 592b0b1..760fcd1 100644
--- a/include/ct1973.c
+++ b/include/ct1975.c
@@ -1,9 +1,8 @@
-#include "ct1973.h"
+#include "ct1975.h"
float flattened[CONV_NUM+2];
float dense1[DENSE1_NUM];
float dense2[DENSE2_NUM];
-float output[OUTPUT_NUM];
#define RELU(x) ((x) = ((x)<0)?0:(x))
@@ -76,14 +75,15 @@ evaluate_black_win(void) {
/* ------------- *
* Output layer *
* ------------- */
- float norm = 0;
- for (uint8_t out = 0; out < OUTPUT_NUM; out++) {
- output[out] = output_biases[out];
- for (uint8_t d2 = 0; d2 < DENSE2_NUM; d2++) {
- output[out] += dense2[d2]*output_weights[out][d2];
- }
- output[out] = exp(output[out]);
- norm += output[out];
+ float output = output_bias;
+ for (uint8_t d2 = 0; d2 < DENSE2_NUM; d2++) {
+ output += dense2[d2]*output_weights[d2];
}
- return output[1]/norm;
+
+ // Truncated Pade approximant of logistic function
+ output = (12.0+output+50.0*output/(output*output+10.0))/24.0;
+ if (output > 1.0) return 1.0;
+ else if (output < 0.0) return 0.0;
+
+ return output;
}
diff --git a/include/ct1973.h b/include/ct1975.h
index 6350ff3..79c20d2 100644
--- a/include/ct1973.h
+++ b/include/ct1975.h
@@ -1,5 +1,4 @@
#include <stdint.h>
-#include <math.h>
#include "tak.h"
#include "weights.h"
diff --git a/include/weights.h b/include/weights.h
index 3c83010..18079ba 100644
--- a/include/weights.h
+++ b/include/weights.h
@@ -5,8 +5,7 @@
#define CONV_NUM (KERN_NUM * KERN_OSIZE * KERN_OSIZE) // 108
#define DENSE1_NUM 9
-#define DENSE2_NUM 8
-#define OUTPUT_NUM 2
+#define DENSE2_NUM 9
extern const float conv2d_weights[KERN_NUM][KERN_SIZE][KERN_SIZE][KERN_CHAN];
extern const float conv2d_biases[KERN_NUM];
@@ -14,5 +13,5 @@ extern const float dense1_weights[DENSE1_NUM][CONV_NUM+2];
extern const float dense1_biases[DENSE1_NUM];
extern const float dense2_weights[DENSE2_NUM][DENSE1_NUM];
extern const float dense2_biases[DENSE2_NUM];
-extern const float output_weights[OUTPUT_NUM][DENSE2_NUM];
-extern const float output_biases[2];
+extern const float output_weights[DENSE2_NUM];
+extern const float output_bias;