diff options
| author | tslil clingman <tslil@posteo.de> | 2021-03-28 00:19:05 -0400 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | 2dbb9fa9b69e49d49cebb1c17559f6fe67600a4d (patch) | |
| tree | 6b90825474eb34e121b3788036ff0350484ae07b /include/cnn1986.c | |
| parent | 00a04c2929bdc8f8f4bf7d5d8cf413ebfb3cd006 (diff) | |
Fix copyright notice in files, and small preemptive optimisation
Eventually there'll be a more complicated data generation step than
the one we're presently using, so having it in-lined in the loop is
wasteful. Ideally also this would be update per ply and we could avoid
recalculating it entirely for every query -- though it's probably
``fast enough'' for now. Also, caching is WIP.
Diffstat (limited to 'include/cnn1986.c')
| -rw-r--r-- | include/cnn1986.c | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/include/cnn1986.c b/include/cnn1986.c index dc0e116..9191ec8 100644 --- a/include/cnn1986.c +++ b/include/cnn1986.c @@ -12,7 +12,7 @@ General Public License for more details. You should have received a copy of the GNU General Public License - along with Takwrap. If not, see <https://www.gnu.org/licenses/>. + along with ct. If not, see <https://www.gnu.org/licenses/>. */ #include "cnn1986.h" @@ -27,8 +27,34 @@ static float dense1[DENSE1_NUM]; static float dense2[DENSE2_NUM]; #define RELU(x) ((x) = ((x)<0)?0:(x)) - float cnn1986_evaluate_black_win(void) { + /* --------------- * + * Generate input * + * --------------- */ + + float cur_board[board_size*board_size][KERN_CHAN]; + for (int y = 0; y < board_size; y++) { + for (int x = 0; x < board_size; x++) { + const int loc = x+y*board_size; + for (int c = 0; c < KERN_CHAN; c++) { // heh, c++ + 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<<c)) ? +0.50 : -0.50; + } + } + cur_board[loc][c] = lookup; + } + } + } /* ------------------ * * Convolution layer * * ------------------ */ @@ -44,25 +70,9 @@ float cnn1986_evaluate_black_win(void) { 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+bx+(ky+by)*5; - // 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<<c)) ? +0.50 : -0.50; - } - } + const uint8_t loc = kx+bx+(ky+by)*board_size; flattened[kern+KERN_NUM*(bx+by*KERN_OSIZE)] - += lookup*conv2d_weights[kern][ky][kx][c]; + += cur_board[loc][c]*conv2d_weights[kern][ky][kx][c]; } } } |
