From a96ec5a74093eb800d14e143b81302d3e0905b85 Mon Sep 17 00:00:00 2001 From: tslil Date: Tue, 12 Jan 2021 15:51:48 -0500 Subject: one output (of course), Pade approximant of logistic for activation --- include/ct1973.c | 89 ------------------------------------------------------- include/ct1973.h | 7 ----- include/ct1975.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/ct1975.h | 6 ++++ include/weights.h | 7 ++--- 5 files changed, 98 insertions(+), 100 deletions(-) delete mode 100644 include/ct1973.c delete mode 100644 include/ct1973.h create mode 100644 include/ct1975.c create mode 100644 include/ct1975.h (limited to 'include') diff --git a/include/ct1973.c b/include/ct1973.c deleted file mode 100644 index 592b0b1..0000000 --- a/include/ct1973.c +++ /dev/null @@ -1,89 +0,0 @@ -#include "ct1973.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)) - -float -evaluate_black_win(void) { - /* ------------------ * - * Convolution layer * - * ------------------ */ - // for each kernel - for (uint8_t kern = 0; kern < KERN_NUM; kern++) { - // the stride is 1, march across the board - for (uint8_t bx = 0; bx < KERN_OSIZE; bx++) { - for (uint8_t by = 0; by < KERN_OSIZE; by++) { - flattened[kern+KERN_NUM*(bx+by*KERN_OSIZE)] = - conv2d_biases[kern]; - // Compute the convolution for this position - for (uint8_t ky = 0; ky < KERN_SIZE; ky++) { - for (uint8_t kx = 0; kx < KERN_SIZE; kx++) { - for (uint8_t c = 0; c < KERN_CHAN; c++) { - // Where we are on the board - const uint8_t loc = kx+by+(ky+bx)*board_size; - // Look up what's on the board at this location, and - // multiply it. For c=0 we have to do some extra work - float lookup = 0; - if (COUNT_AT(loc)>c) { - if (c==0) { - if (STONE_AT(loc) == STONE_STANDING) { - lookup = (colours[loc] & 1) ? +0.25 : -0.25; - } else if (STONE_AT(loc) == STONE_CAPSTONE) { - lookup = (colours[loc] & 1) ? +1.00 : -1.00; - } else { - lookup = (colours[loc] & 1) ? +0.50 : -0.50; - } - } else { - lookup = (colours[loc] & (1< -#include -#include "tak.h" -#include "weights.h" - -float -evaluate_black_win(void); diff --git a/include/ct1975.c b/include/ct1975.c new file mode 100644 index 0000000..760fcd1 --- /dev/null +++ b/include/ct1975.c @@ -0,0 +1,89 @@ +#include "ct1975.h" + +float flattened[CONV_NUM+2]; +float dense1[DENSE1_NUM]; +float dense2[DENSE2_NUM]; + +#define RELU(x) ((x) = ((x)<0)?0:(x)) + +float +evaluate_black_win(void) { + /* ------------------ * + * Convolution layer * + * ------------------ */ + // for each kernel + for (uint8_t kern = 0; kern < KERN_NUM; kern++) { + // the stride is 1, march across the board + for (uint8_t bx = 0; bx < KERN_OSIZE; bx++) { + for (uint8_t by = 0; by < KERN_OSIZE; by++) { + flattened[kern+KERN_NUM*(bx+by*KERN_OSIZE)] = + conv2d_biases[kern]; + // Compute the convolution for this position + for (uint8_t ky = 0; ky < KERN_SIZE; ky++) { + for (uint8_t kx = 0; kx < KERN_SIZE; kx++) { + for (uint8_t c = 0; c < KERN_CHAN; c++) { + // Where we are on the board + const uint8_t loc = kx+by+(ky+bx)*board_size; + // Look up what's on the board at this location, and + // multiply it. For c=0 we have to do some extra work + float lookup = 0; + if (COUNT_AT(loc)>c) { + if (c==0) { + if (STONE_AT(loc) == STONE_STANDING) { + lookup = (colours[loc] & 1) ? +0.25 : -0.25; + } else if (STONE_AT(loc) == STONE_CAPSTONE) { + lookup = (colours[loc] & 1) ? +1.00 : -1.00; + } else { + lookup = (colours[loc] & 1) ? +0.50 : -0.50; + } + } else { + lookup = (colours[loc] & (1< 1.0) return 1.0; + else if (output < 0.0) return 0.0; + + return output; +} diff --git a/include/ct1975.h b/include/ct1975.h new file mode 100644 index 0000000..79c20d2 --- /dev/null +++ b/include/ct1975.h @@ -0,0 +1,6 @@ +#include +#include "tak.h" +#include "weights.h" + +float +evaluate_black_win(void); 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; -- cgit v1.2.3