aboutsummaryrefslogtreecommitdiff
path: root/include/nn.h
blob: 871bd0f691b36d8b77033436cd59cf9bf7436929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
  This file is part of ctak.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with ctak. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef NN_H
#define NN_H

#include <stdint.h>

#include <tak.h>

// Number of cell states: empty, then {black, white} x {flat, standing, road}
#define NN_N_EMB 7

// ===================================================================
// Input encoding
// ===================================================================

// somewhat internal, important for generating training data
void nn_cell_idxs(uint8_t *out, tak_state_p state);
void nn_prepare_head(float out_head[3], tak_state_p state);

void nn_prepare_input(float *cur_board, tak_state_p state,
                      const float embedding[NN_N_EMB]);

int nn_last_cell_idxs(uint8_t *out, tak_state_p state);
// ===================================================================
// Network
// ===================================================================

float eval_net(const float *board, const unsigned int n_inp,
               const float *w, const float *biases,
               const float *logit_w, const float logit_b,
               const unsigned int n_dense);

// Evaluators for the two built-in networks.
float five_nn_fn(tak_state_p state);
float six_nn_fn(tak_state_p state);

#endif