github.com/gorgonia/agogo@v0.1.1/dualnet/config.go (about) 1 package dual 2 3 // Config configures the neural network 4 type Config struct { 5 K int // number of filters 6 SharedLayers int // number of shared residual blocks 7 FC int // fc layer width 8 L2 float64 // L2 regularization 9 10 BatchSize int // batch size 11 Width, Height int // board size 12 Features int // feature counts 13 14 ActionSpace int 15 FwdOnly bool // is this a fwd only graph? 16 } 17 18 func DefaultConf(m, n, actionSpace int) Config { 19 k := round((m * n) / 3) 20 return Config{ 21 K: k, 22 SharedLayers: m, 23 FC: 2 * k, 24 25 BatchSize: 256, 26 Width: n, 27 Height: m, 28 Features: 18, 29 ActionSpace: actionSpace, 30 } 31 } 32 33 func (conf Config) IsValid() bool { 34 return conf.K >= 1 && 35 conf.ActionSpace >= 3 && 36 // conf.SharedLayers >= conf.BoardSize && 37 conf.SharedLayers >= 0 && 38 conf.FC > 1 && 39 conf.BatchSize >= 1 && 40 // conf.ActionSpace >= conf.Width*conf.Height && 41 conf.Features > 0 42 } 43 44 func round(a int) int { 45 n := a - 1 46 n |= n >> 1 47 n |= n >> 2 48 n |= n >> 4 49 n |= n >> 8 50 n |= n >> 16 51 n++ 52 53 lt := n / 2 54 if (a - lt) < (n - a) { 55 return lt 56 } 57 return n 58 }