diff --git a/learn/aoba_256x20b_swish_mb128.prototxt b/learn/aoba_256x20b_swish_mb128.prototxt new file mode 100644 index 0000000..61d8d32 --- /dev/null +++ b/learn/aoba_256x20b_swish_mb128.prototxt @@ -0,0 +1,1756 @@ +name: "AobaZero" + +layer { + name: "data" + type: "MemoryData" + top: "data" + top: "dummy_label1" + memory_data_param { + batch_size: 128 + channels: 362 + height: 9 + width: 9 + } +} +layer { + name: "label_policy" + type: "MemoryData" + top: "p_label" + top: "dummy_label2" + memory_data_param { + batch_size: 128 + channels: 2187 + height: 1 + width: 1 + } +} +layer { + name: "flat_policy_label" + type: "Flatten" + bottom: "p_label" + top: "label_policy" +} + +layer { + name: "label_value" + type: "MemoryData" + top: "label_value" + top: "dummy_label3" + memory_data_param { + batch_size: 128 + channels: 1 + height: 1 + width: 1 + } +} + +layer { + name:"silence" + type:"Silence" +# dummy_label1,2,3 must be 0. not to print log + bottom: "dummy_label1" + bottom: "dummy_label2" + bottom: "dummy_label3" +} + + +#this part should be the same in learning and prediction network +layer { + name: "conv1_3x3_256" + type: "Convolution" + bottom: "data" + top: "conv1" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type: "msra" } + bias_filler { type: "constant" } + } +} +layer { + name: "bn1" + type: "BatchNorm" + bottom: "conv1" + top: "bn1" +} +layer { + name: "swish1/sig" + type: "Sigmoid" + bottom:"bn1" + top: "swish1/sig" +} +layer { + name: "swish1" + type: "Eltwise" + bottom:"bn1" + bottom: "swish1/sig" + top:"swish1" + eltwise_param { operation: PROD } +} + +# ResNet starts from conv2. conv2 and conv3 are one block. + + +layer { + name:"conv2_3x3_256" + type:"Convolution" + bottom:"swish1" + top:"conv2" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn2" + type:"BatchNorm" + bottom:"conv2" + top:"bn2" +} +layer { + name: "swish2/sig" + type: "Sigmoid" + bottom:"bn2" + top: "swish2/sig" +} +layer { + name: "swish2" + type: "Eltwise" + bottom:"bn2" + bottom: "swish2/sig" + top:"swish2" + eltwise_param { operation: PROD } +} +layer { + name:"conv3_3x3_256" + type:"Convolution" + bottom:"swish2" + top:"conv3" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn3" + type:"BatchNorm" + bottom:"conv3" + top:"bn3" +} +layer { + name:"elt3" + type:"Eltwise" + bottom:"swish1" + bottom:"bn3" + top:"sum3" + eltwise_param { operation: SUM } +} +layer { + name: "swish3/sig" + type: "Sigmoid" + bottom:"sum3" + top: "swish3/sig" +} +layer { + name: "swish3" + type: "Eltwise" + bottom:"sum3" + bottom: "swish3/sig" + top:"swish3" + eltwise_param { operation: PROD } +} +layer { + name:"conv4_3x3_256" + type:"Convolution" + bottom:"swish3" + top:"conv4" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn4" + type:"BatchNorm" + bottom:"conv4" + top:"bn4" +} +layer { + name: "swish4/sig" + type: "Sigmoid" + bottom:"bn4" + top: "swish4/sig" +} +layer { + name: "swish4" + type: "Eltwise" + bottom:"bn4" + bottom: "swish4/sig" + top:"swish4" + eltwise_param { operation: PROD } +} +layer { + name:"conv5_3x3_256" + type:"Convolution" + bottom:"swish4" + top:"conv5" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn5" + type:"BatchNorm" + bottom:"conv5" + top:"bn5" +} +layer { + name:"elt5" + type:"Eltwise" + bottom:"swish3" + bottom:"bn5" + top:"sum5" + eltwise_param { operation: SUM } +} +layer { + name: "swish5/sig" + type: "Sigmoid" + bottom:"sum5" + top: "swish5/sig" +} +layer { + name: "swish5" + type: "Eltwise" + bottom:"sum5" + bottom: "swish5/sig" + top:"swish5" + eltwise_param { operation: PROD } +} +layer { + name:"conv6_3x3_256" + type:"Convolution" + bottom:"swish5" + top:"conv6" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn6" + type:"BatchNorm" + bottom:"conv6" + top:"bn6" +} +layer { + name: "swish6/sig" + type: "Sigmoid" + bottom:"bn6" + top: "swish6/sig" +} +layer { + name: "swish6" + type: "Eltwise" + bottom:"bn6" + bottom: "swish6/sig" + top:"swish6" + eltwise_param { operation: PROD } +} +layer { + name:"conv7_3x3_256" + type:"Convolution" + bottom:"swish6" + top:"conv7" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn7" + type:"BatchNorm" + bottom:"conv7" + top:"bn7" +} +layer { + name:"elt7" + type:"Eltwise" + bottom:"swish5" + bottom:"bn7" + top:"sum7" + eltwise_param { operation: SUM } +} +layer { + name: "swish7/sig" + type: "Sigmoid" + bottom:"sum7" + top: "swish7/sig" +} +layer { + name: "swish7" + type: "Eltwise" + bottom:"sum7" + bottom: "swish7/sig" + top:"swish7" + eltwise_param { operation: PROD } +} +layer { + name:"conv8_3x3_256" + type:"Convolution" + bottom:"swish7" + top:"conv8" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn8" + type:"BatchNorm" + bottom:"conv8" + top:"bn8" +} +layer { + name: "swish8/sig" + type: "Sigmoid" + bottom:"bn8" + top: "swish8/sig" +} +layer { + name: "swish8" + type: "Eltwise" + bottom:"bn8" + bottom: "swish8/sig" + top:"swish8" + eltwise_param { operation: PROD } +} +layer { + name:"conv9_3x3_256" + type:"Convolution" + bottom:"swish8" + top:"conv9" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn9" + type:"BatchNorm" + bottom:"conv9" + top:"bn9" +} +layer { + name:"elt9" + type:"Eltwise" + bottom:"swish7" + bottom:"bn9" + top:"sum9" + eltwise_param { operation: SUM } +} +layer { + name: "swish9/sig" + type: "Sigmoid" + bottom:"sum9" + top: "swish9/sig" +} +layer { + name: "swish9" + type: "Eltwise" + bottom:"sum9" + bottom: "swish9/sig" + top:"swish9" + eltwise_param { operation: PROD } +} +layer { + name:"conv10_3x3_256" + type:"Convolution" + bottom:"swish9" + top:"conv10" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn10" + type:"BatchNorm" + bottom:"conv10" + top:"bn10" +} +layer { + name: "swish10/sig" + type: "Sigmoid" + bottom:"bn10" + top: "swish10/sig" +} +layer { + name: "swish10" + type: "Eltwise" + bottom:"bn10" + bottom: "swish10/sig" + top:"swish10" + eltwise_param { operation: PROD } +} +layer { + name:"conv11_3x3_256" + type:"Convolution" + bottom:"swish10" + top:"conv11" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn11" + type:"BatchNorm" + bottom:"conv11" + top:"bn11" +} +layer { + name:"elt11" + type:"Eltwise" + bottom:"swish9" + bottom:"bn11" + top:"sum11" + eltwise_param { operation: SUM } +} +layer { + name: "swish11/sig" + type: "Sigmoid" + bottom:"sum11" + top: "swish11/sig" +} +layer { + name: "swish11" + type: "Eltwise" + bottom:"sum11" + bottom: "swish11/sig" + top:"swish11" + eltwise_param { operation: PROD } +} +layer { + name:"conv12_3x3_256" + type:"Convolution" + bottom:"swish11" + top:"conv12" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn12" + type:"BatchNorm" + bottom:"conv12" + top:"bn12" +} +layer { + name: "swish12/sig" + type: "Sigmoid" + bottom:"bn12" + top: "swish12/sig" +} +layer { + name: "swish12" + type: "Eltwise" + bottom:"bn12" + bottom: "swish12/sig" + top:"swish12" + eltwise_param { operation: PROD } +} +layer { + name:"conv13_3x3_256" + type:"Convolution" + bottom:"swish12" + top:"conv13" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn13" + type:"BatchNorm" + bottom:"conv13" + top:"bn13" +} +layer { + name:"elt13" + type:"Eltwise" + bottom:"swish11" + bottom:"bn13" + top:"sum13" + eltwise_param { operation: SUM } +} +layer { + name: "swish13/sig" + type: "Sigmoid" + bottom:"sum13" + top: "swish13/sig" +} +layer { + name: "swish13" + type: "Eltwise" + bottom:"sum13" + bottom: "swish13/sig" + top:"swish13" + eltwise_param { operation: PROD } +} +layer { + name:"conv14_3x3_256" + type:"Convolution" + bottom:"swish13" + top:"conv14" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn14" + type:"BatchNorm" + bottom:"conv14" + top:"bn14" +} +layer { + name: "swish14/sig" + type: "Sigmoid" + bottom:"bn14" + top: "swish14/sig" +} +layer { + name: "swish14" + type: "Eltwise" + bottom:"bn14" + bottom: "swish14/sig" + top:"swish14" + eltwise_param { operation: PROD } +} +layer { + name:"conv15_3x3_256" + type:"Convolution" + bottom:"swish14" + top:"conv15" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn15" + type:"BatchNorm" + bottom:"conv15" + top:"bn15" +} +layer { + name:"elt15" + type:"Eltwise" + bottom:"swish13" + bottom:"bn15" + top:"sum15" + eltwise_param { operation: SUM } +} +layer { + name: "swish15/sig" + type: "Sigmoid" + bottom:"sum15" + top: "swish15/sig" +} +layer { + name: "swish15" + type: "Eltwise" + bottom:"sum15" + bottom: "swish15/sig" + top:"swish15" + eltwise_param { operation: PROD } +} +layer { + name:"conv16_3x3_256" + type:"Convolution" + bottom:"swish15" + top:"conv16" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn16" + type:"BatchNorm" + bottom:"conv16" + top:"bn16" +} +layer { + name: "swish16/sig" + type: "Sigmoid" + bottom:"bn16" + top: "swish16/sig" +} +layer { + name: "swish16" + type: "Eltwise" + bottom:"bn16" + bottom: "swish16/sig" + top:"swish16" + eltwise_param { operation: PROD } +} +layer { + name:"conv17_3x3_256" + type:"Convolution" + bottom:"swish16" + top:"conv17" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn17" + type:"BatchNorm" + bottom:"conv17" + top:"bn17" +} +layer { + name:"elt17" + type:"Eltwise" + bottom:"swish15" + bottom:"bn17" + top:"sum17" + eltwise_param { operation: SUM } +} +layer { + name: "swish17/sig" + type: "Sigmoid" + bottom:"sum17" + top: "swish17/sig" +} +layer { + name: "swish17" + type: "Eltwise" + bottom:"sum17" + bottom: "swish17/sig" + top:"swish17" + eltwise_param { operation: PROD } +} +layer { + name:"conv18_3x3_256" + type:"Convolution" + bottom:"swish17" + top:"conv18" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn18" + type:"BatchNorm" + bottom:"conv18" + top:"bn18" +} +layer { + name: "swish18/sig" + type: "Sigmoid" + bottom:"bn18" + top: "swish18/sig" +} +layer { + name: "swish18" + type: "Eltwise" + bottom:"bn18" + bottom: "swish18/sig" + top:"swish18" + eltwise_param { operation: PROD } +} +layer { + name:"conv19_3x3_256" + type:"Convolution" + bottom:"swish18" + top:"conv19" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn19" + type:"BatchNorm" + bottom:"conv19" + top:"bn19" +} +layer { + name:"elt19" + type:"Eltwise" + bottom:"swish17" + bottom:"bn19" + top:"sum19" + eltwise_param { operation: SUM } +} +layer { + name: "swish19/sig" + type: "Sigmoid" + bottom:"sum19" + top: "swish19/sig" +} +layer { + name: "swish19" + type: "Eltwise" + bottom:"sum19" + bottom: "swish19/sig" + top:"swish19" + eltwise_param { operation: PROD } +} +layer { + name:"conv20_3x3_256" + type:"Convolution" + bottom:"swish19" + top:"conv20" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn20" + type:"BatchNorm" + bottom:"conv20" + top:"bn20" +} +layer { + name: "swish20/sig" + type: "Sigmoid" + bottom:"bn20" + top: "swish20/sig" +} +layer { + name: "swish20" + type: "Eltwise" + bottom:"bn20" + bottom: "swish20/sig" + top:"swish20" + eltwise_param { operation: PROD } +} +layer { + name:"conv21_3x3_256" + type:"Convolution" + bottom:"swish20" + top:"conv21" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn21" + type:"BatchNorm" + bottom:"conv21" + top:"bn21" +} +layer { + name:"elt21" + type:"Eltwise" + bottom:"swish19" + bottom:"bn21" + top:"sum21" + eltwise_param { operation: SUM } +} +layer { + name: "swish21/sig" + type: "Sigmoid" + bottom:"sum21" + top: "swish21/sig" +} +layer { + name: "swish21" + type: "Eltwise" + bottom:"sum21" + bottom: "swish21/sig" + top:"swish21" + eltwise_param { operation: PROD } +} +layer { + name:"conv22_3x3_256" + type:"Convolution" + bottom:"swish21" + top:"conv22" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn22" + type:"BatchNorm" + bottom:"conv22" + top:"bn22" +} +layer { + name: "swish22/sig" + type: "Sigmoid" + bottom:"bn22" + top: "swish22/sig" +} +layer { + name: "swish22" + type: "Eltwise" + bottom:"bn22" + bottom: "swish22/sig" + top:"swish22" + eltwise_param { operation: PROD } +} +layer { + name:"conv23_3x3_256" + type:"Convolution" + bottom:"swish22" + top:"conv23" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn23" + type:"BatchNorm" + bottom:"conv23" + top:"bn23" +} +layer { + name:"elt23" + type:"Eltwise" + bottom:"swish21" + bottom:"bn23" + top:"sum23" + eltwise_param { operation: SUM } +} +layer { + name: "swish23/sig" + type: "Sigmoid" + bottom:"sum23" + top: "swish23/sig" +} +layer { + name: "swish23" + type: "Eltwise" + bottom:"sum23" + bottom: "swish23/sig" + top:"swish23" + eltwise_param { operation: PROD } +} +layer { + name:"conv24_3x3_256" + type:"Convolution" + bottom:"swish23" + top:"conv24" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn24" + type:"BatchNorm" + bottom:"conv24" + top:"bn24" +} +layer { + name: "swish24/sig" + type: "Sigmoid" + bottom:"bn24" + top: "swish24/sig" +} +layer { + name: "swish24" + type: "Eltwise" + bottom:"bn24" + bottom: "swish24/sig" + top:"swish24" + eltwise_param { operation: PROD } +} +layer { + name:"conv25_3x3_256" + type:"Convolution" + bottom:"swish24" + top:"conv25" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn25" + type:"BatchNorm" + bottom:"conv25" + top:"bn25" +} +layer { + name:"elt25" + type:"Eltwise" + bottom:"swish23" + bottom:"bn25" + top:"sum25" + eltwise_param { operation: SUM } +} +layer { + name: "swish25/sig" + type: "Sigmoid" + bottom:"sum25" + top: "swish25/sig" +} +layer { + name: "swish25" + type: "Eltwise" + bottom:"sum25" + bottom: "swish25/sig" + top:"swish25" + eltwise_param { operation: PROD } +} +layer { + name:"conv26_3x3_256" + type:"Convolution" + bottom:"swish25" + top:"conv26" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn26" + type:"BatchNorm" + bottom:"conv26" + top:"bn26" +} +layer { + name: "swish26/sig" + type: "Sigmoid" + bottom:"bn26" + top: "swish26/sig" +} +layer { + name: "swish26" + type: "Eltwise" + bottom:"bn26" + bottom: "swish26/sig" + top:"swish26" + eltwise_param { operation: PROD } +} +layer { + name:"conv27_3x3_256" + type:"Convolution" + bottom:"swish26" + top:"conv27" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn27" + type:"BatchNorm" + bottom:"conv27" + top:"bn27" +} +layer { + name:"elt27" + type:"Eltwise" + bottom:"swish25" + bottom:"bn27" + top:"sum27" + eltwise_param { operation: SUM } +} +layer { + name: "swish27/sig" + type: "Sigmoid" + bottom:"sum27" + top: "swish27/sig" +} +layer { + name: "swish27" + type: "Eltwise" + bottom:"sum27" + bottom: "swish27/sig" + top:"swish27" + eltwise_param { operation: PROD } +} +layer { + name:"conv28_3x3_256" + type:"Convolution" + bottom:"swish27" + top:"conv28" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn28" + type:"BatchNorm" + bottom:"conv28" + top:"bn28" +} +layer { + name: "swish28/sig" + type: "Sigmoid" + bottom:"bn28" + top: "swish28/sig" +} +layer { + name: "swish28" + type: "Eltwise" + bottom:"bn28" + bottom: "swish28/sig" + top:"swish28" + eltwise_param { operation: PROD } +} +layer { + name:"conv29_3x3_256" + type:"Convolution" + bottom:"swish28" + top:"conv29" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn29" + type:"BatchNorm" + bottom:"conv29" + top:"bn29" +} +layer { + name:"elt29" + type:"Eltwise" + bottom:"swish27" + bottom:"bn29" + top:"sum29" + eltwise_param { operation: SUM } +} +layer { + name: "swish29/sig" + type: "Sigmoid" + bottom:"sum29" + top: "swish29/sig" +} +layer { + name: "swish29" + type: "Eltwise" + bottom:"sum29" + bottom: "swish29/sig" + top:"swish29" + eltwise_param { operation: PROD } +} +layer { + name:"conv30_3x3_256" + type:"Convolution" + bottom:"swish29" + top:"conv30" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn30" + type:"BatchNorm" + bottom:"conv30" + top:"bn30" +} +layer { + name: "swish30/sig" + type: "Sigmoid" + bottom:"bn30" + top: "swish30/sig" +} +layer { + name: "swish30" + type: "Eltwise" + bottom:"bn30" + bottom: "swish30/sig" + top:"swish30" + eltwise_param { operation: PROD } +} +layer { + name:"conv31_3x3_256" + type:"Convolution" + bottom:"swish30" + top:"conv31" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn31" + type:"BatchNorm" + bottom:"conv31" + top:"bn31" +} +layer { + name:"elt31" + type:"Eltwise" + bottom:"swish29" + bottom:"bn31" + top:"sum31" + eltwise_param { operation: SUM } +} +layer { + name: "swish31/sig" + type: "Sigmoid" + bottom:"sum31" + top: "swish31/sig" +} +layer { + name: "swish31" + type: "Eltwise" + bottom:"sum31" + bottom: "swish31/sig" + top:"swish31" + eltwise_param { operation: PROD } +} +layer { + name:"conv32_3x3_256" + type:"Convolution" + bottom:"swish31" + top:"conv32" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn32" + type:"BatchNorm" + bottom:"conv32" + top:"bn32" +} +layer { + name: "swish32/sig" + type: "Sigmoid" + bottom:"bn32" + top: "swish32/sig" +} +layer { + name: "swish32" + type: "Eltwise" + bottom:"bn32" + bottom: "swish32/sig" + top:"swish32" + eltwise_param { operation: PROD } +} +layer { + name:"conv33_3x3_256" + type:"Convolution" + bottom:"swish32" + top:"conv33" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn33" + type:"BatchNorm" + bottom:"conv33" + top:"bn33" +} +layer { + name:"elt33" + type:"Eltwise" + bottom:"swish31" + bottom:"bn33" + top:"sum33" + eltwise_param { operation: SUM } +} +layer { + name: "swish33/sig" + type: "Sigmoid" + bottom:"sum33" + top: "swish33/sig" +} +layer { + name: "swish33" + type: "Eltwise" + bottom:"sum33" + bottom: "swish33/sig" + top:"swish33" + eltwise_param { operation: PROD } +} +layer { + name:"conv34_3x3_256" + type:"Convolution" + bottom:"swish33" + top:"conv34" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn34" + type:"BatchNorm" + bottom:"conv34" + top:"bn34" +} +layer { + name: "swish34/sig" + type: "Sigmoid" + bottom:"bn34" + top: "swish34/sig" +} +layer { + name: "swish34" + type: "Eltwise" + bottom:"bn34" + bottom: "swish34/sig" + top:"swish34" + eltwise_param { operation: PROD } +} +layer { + name:"conv35_3x3_256" + type:"Convolution" + bottom:"swish34" + top:"conv35" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn35" + type:"BatchNorm" + bottom:"conv35" + top:"bn35" +} +layer { + name:"elt35" + type:"Eltwise" + bottom:"swish33" + bottom:"bn35" + top:"sum35" + eltwise_param { operation: SUM } +} +layer { + name: "swish35/sig" + type: "Sigmoid" + bottom:"sum35" + top: "swish35/sig" +} +layer { + name: "swish35" + type: "Eltwise" + bottom:"sum35" + bottom: "swish35/sig" + top:"swish35" + eltwise_param { operation: PROD } +} +layer { + name:"conv36_3x3_256" + type:"Convolution" + bottom:"swish35" + top:"conv36" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn36" + type:"BatchNorm" + bottom:"conv36" + top:"bn36" +} +layer { + name: "swish36/sig" + type: "Sigmoid" + bottom:"bn36" + top: "swish36/sig" +} +layer { + name: "swish36" + type: "Eltwise" + bottom:"bn36" + bottom: "swish36/sig" + top:"swish36" + eltwise_param { operation: PROD } +} +layer { + name:"conv37_3x3_256" + type:"Convolution" + bottom:"swish36" + top:"conv37" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn37" + type:"BatchNorm" + bottom:"conv37" + top:"bn37" +} +layer { + name:"elt37" + type:"Eltwise" + bottom:"swish35" + bottom:"bn37" + top:"sum37" + eltwise_param { operation: SUM } +} +layer { + name: "swish37/sig" + type: "Sigmoid" + bottom:"sum37" + top: "swish37/sig" +} +layer { + name: "swish37" + type: "Eltwise" + bottom:"sum37" + bottom: "swish37/sig" + top:"swish37" + eltwise_param { operation: PROD } +} +layer { + name:"conv38_3x3_256" + type:"Convolution" + bottom:"swish37" + top:"conv38" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn38" + type:"BatchNorm" + bottom:"conv38" + top:"bn38" +} +layer { + name: "swish38/sig" + type: "Sigmoid" + bottom:"bn38" + top: "swish38/sig" +} +layer { + name: "swish38" + type: "Eltwise" + bottom:"bn38" + bottom: "swish38/sig" + top:"swish38" + eltwise_param { operation: PROD } +} +layer { + name:"conv39_3x3_256" + type:"Convolution" + bottom:"swish38" + top:"conv39" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn39" + type:"BatchNorm" + bottom:"conv39" + top:"bn39" +} +layer { + name:"elt39" + type:"Eltwise" + bottom:"swish37" + bottom:"bn39" + top:"sum39" + eltwise_param { operation: SUM } +} +layer { + name: "swish39/sig" + type: "Sigmoid" + bottom:"sum39" + top: "swish39/sig" +} +layer { + name: "swish39" + type: "Eltwise" + bottom:"sum39" + bottom: "swish39/sig" + top:"swish39" + eltwise_param { operation: PROD } +} + +# ResNet block ends here. + + + +# policy head +layer { + name: "conv1_p_1x1_160" # 9*9*160 = 12960 > 11259 + type: "Convolution" + bottom: "swish39" + top: "conv1_p" + convolution_param { + num_output: 160 + kernel_size: 1 + pad: 0 + weight_filler { type: "msra" } + bias_filler { type: "constant" } + } +} +layer { + name:"bn1_p" + type:"BatchNorm" + bottom:"conv1_p" + top:"bn1_p" +} +layer { + name: "swish1_p/sig" + type: "Sigmoid" + bottom:"bn1_p" + top: "swish1_p/sig" +} +layer { + name: "swish1_p" + type: "Eltwise" + bottom:"bn1_p" + bottom: "swish1_p/sig" + top:"swish1_p" + eltwise_param { operation: PROD } +} + +layer { + # 9*9 *139 = 11259 + # 9*9 *27 = 2187 + name: "conv2_p_1x1_27" + type: "Convolution" + bottom: "swish1_p" + top: "conv2_p" + convolution_param { + num_output: 27 + kernel_size: 1 + pad: 0 + weight_filler { type: "msra" } + bias_filler { type: "constant" } + } +} +layer { + name: "flat_p" + type: "Flatten" + bottom: "conv2_p" + top: "flat_p" +} + +# from DuelNet-40-64.prototxt by Kobayashi-san +# and https://github.com/adepierre/Caffe_AlphaZero +layer { + name: "softmax" + type: "Softmax" + bottom: "flat_p" + top: "policy_probability" +} + +layer { + name: "log_probability" + type: "Log" + bottom: "policy_probability" + top: "log_policy_probability" + include { + phase: TRAIN + } +} + +layer { + name: "minus_log_probability" + type: "Scale" + bottom: "log_policy_probability" + top: "minus_log_policy_probability" + param { + lr_mult: 0 + decay_mult: 0 + } + scale_param { + axis: 0 + num_axes: 0 + filler { + type: "constant" + value: -1 + } + bias_term: false + } + include { + phase: TRAIN + } +} + +layer { + name: "cross_entropy_mult" + type: "Eltwise" + bottom: "minus_log_policy_probability" + bottom: "label_policy" + top: "eltwise_prod" + eltwise_param { + operation: PROD + } + include { + phase: TRAIN + } +} + +layer { + name: "cross_entropy_first_sum" + type: "Reduction" + bottom: "eltwise_prod" + top: "cross_entropy_sum" + reduction_param { + operation: SUM + axis: 1 + } + include { + phase: TRAIN + } +} + + +layer { + name: "cross_entroy_scale_mb128" # if same name, Caffe uses *.caffemodel's value. + type: "Scale" + bottom: "cross_entropy_sum" + top: "cross_entropy_scale" + param { + lr_mult: 0 + decay_mult: 0 + } + scale_param { + axis: 0 + num_axes: 0 + filler { + type: "constant" + value: 0.0078125 # 1 / batch_size. 0.015625(mb=64), 0.0078125(mb=128), if you change batch_size, you must change layer's "name" too. + } + bias_term: false + } + include { + phase: TRAIN + } +} + +layer { + name: "cross_entropy_loss" + type: "Reduction" + bottom: "cross_entropy_scale" + top: "policy_loss" + reduction_param { + operation: SUM + axis: 0 + } + include { + phase: TRAIN + } + loss_weight: 1 +} + + +# value head +layer { + name: "conv1_v_1x1_4" # 9*9*4 = 324 > 256 + type: "Convolution" + bottom: "swish39" + top: "conv1_v" + convolution_param { + num_output: 4 + kernel_size: 1 + pad: 0 + weight_filler { type: "msra" } + bias_filler { type: "constant" } + } +} +layer { + name:"bn1_v" + type:"BatchNorm" + bottom:"conv1_v" + top:"bn1_v" +} +layer { + name: "swish1_v/sig" + type: "Sigmoid" + bottom:"bn1_v" + top: "swish1_v/sig" +} +layer { + name: "swish1_v" + type: "Eltwise" + bottom:"bn1_v" + bottom: "swish1_v/sig" + top:"swish1_v" + eltwise_param { operation: PROD } +} +layer { + name: "ip2_v" + type: "InnerProduct" + inner_product_param { + num_output: 256 + weight_filler { type: "msra" } + bias_filler { type: "constant" } + } + bottom: "swish1_v" + top: "ip2_v" +} +layer { + name: "swish2_v/sig" + type: "Sigmoid" + bottom:"ip2_v" + top: "swish2_v/sig" +} +layer { + name: "swish2_v" + type: "Eltwise" + bottom:"ip2_v" + bottom: "swish2_v/sig" + top:"swish2_v" + eltwise_param { operation: PROD } +} +layer { + name: "ip3_v" + type: "InnerProduct" + inner_product_param { + num_output: 1 + weight_filler { type: "xavier" } + bias_filler { type: "constant" } + } + bottom: "swish2_v" + top: "ip3_v" +} +layer { + name: "tanh_v" + type: "TanH" + bottom: "ip3_v" + top: "tanh_v" +} +layer { + name: "loss_value" + type: "EuclideanLoss" + bottom: "tanh_v" + bottom: "label_value" + top: "loss_value" + loss_weight: 2 # this cancels caffe's EuclideanLoss coefficient 0.5. +} diff --git a/learn/aoba_256x20b_swish_predict.prototxt b/learn/aoba_256x20b_swish_predict.prototxt new file mode 100644 index 0000000..5f22e74 --- /dev/null +++ b/learn/aoba_256x20b_swish_predict.prototxt @@ -0,0 +1,1601 @@ +name: "AobaZero" + +input: "data" +input_dim: 1 +input_dim: 362 +input_dim: 9 +input_dim: 9 + + +#this part should be the same in learning and prediction network +layer { + name: "conv1_3x3_256" + type: "Convolution" + bottom: "data" + top: "conv1" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type: "msra" } + bias_filler { type: "constant" } + } +} +layer { + name: "bn1" + type: "BatchNorm" + bottom: "conv1" + top: "bn1" +} +layer { + name: "swish1/sig" + type: "Sigmoid" + bottom:"bn1" + top: "swish1/sig" +} +layer { + name: "swish1" + type: "Eltwise" + bottom:"bn1" + bottom: "swish1/sig" + top:"swish1" + eltwise_param { operation: PROD } +} + +# ResNet starts from conv2. conv2 and conv3 are one block. + + +layer { + name:"conv2_3x3_256" + type:"Convolution" + bottom:"swish1" + top:"conv2" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn2" + type:"BatchNorm" + bottom:"conv2" + top:"bn2" +} +layer { + name: "swish2/sig" + type: "Sigmoid" + bottom:"bn2" + top: "swish2/sig" +} +layer { + name: "swish2" + type: "Eltwise" + bottom:"bn2" + bottom: "swish2/sig" + top:"swish2" + eltwise_param { operation: PROD } +} +layer { + name:"conv3_3x3_256" + type:"Convolution" + bottom:"swish2" + top:"conv3" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn3" + type:"BatchNorm" + bottom:"conv3" + top:"bn3" +} +layer { + name:"elt3" + type:"Eltwise" + bottom:"swish1" + bottom:"bn3" + top:"sum3" + eltwise_param { operation: SUM } +} +layer { + name: "swish3/sig" + type: "Sigmoid" + bottom:"sum3" + top: "swish3/sig" +} +layer { + name: "swish3" + type: "Eltwise" + bottom:"sum3" + bottom: "swish3/sig" + top:"swish3" + eltwise_param { operation: PROD } +} +layer { + name:"conv4_3x3_256" + type:"Convolution" + bottom:"swish3" + top:"conv4" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn4" + type:"BatchNorm" + bottom:"conv4" + top:"bn4" +} +layer { + name: "swish4/sig" + type: "Sigmoid" + bottom:"bn4" + top: "swish4/sig" +} +layer { + name: "swish4" + type: "Eltwise" + bottom:"bn4" + bottom: "swish4/sig" + top:"swish4" + eltwise_param { operation: PROD } +} +layer { + name:"conv5_3x3_256" + type:"Convolution" + bottom:"swish4" + top:"conv5" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn5" + type:"BatchNorm" + bottom:"conv5" + top:"bn5" +} +layer { + name:"elt5" + type:"Eltwise" + bottom:"swish3" + bottom:"bn5" + top:"sum5" + eltwise_param { operation: SUM } +} +layer { + name: "swish5/sig" + type: "Sigmoid" + bottom:"sum5" + top: "swish5/sig" +} +layer { + name: "swish5" + type: "Eltwise" + bottom:"sum5" + bottom: "swish5/sig" + top:"swish5" + eltwise_param { operation: PROD } +} +layer { + name:"conv6_3x3_256" + type:"Convolution" + bottom:"swish5" + top:"conv6" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn6" + type:"BatchNorm" + bottom:"conv6" + top:"bn6" +} +layer { + name: "swish6/sig" + type: "Sigmoid" + bottom:"bn6" + top: "swish6/sig" +} +layer { + name: "swish6" + type: "Eltwise" + bottom:"bn6" + bottom: "swish6/sig" + top:"swish6" + eltwise_param { operation: PROD } +} +layer { + name:"conv7_3x3_256" + type:"Convolution" + bottom:"swish6" + top:"conv7" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn7" + type:"BatchNorm" + bottom:"conv7" + top:"bn7" +} +layer { + name:"elt7" + type:"Eltwise" + bottom:"swish5" + bottom:"bn7" + top:"sum7" + eltwise_param { operation: SUM } +} +layer { + name: "swish7/sig" + type: "Sigmoid" + bottom:"sum7" + top: "swish7/sig" +} +layer { + name: "swish7" + type: "Eltwise" + bottom:"sum7" + bottom: "swish7/sig" + top:"swish7" + eltwise_param { operation: PROD } +} +layer { + name:"conv8_3x3_256" + type:"Convolution" + bottom:"swish7" + top:"conv8" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn8" + type:"BatchNorm" + bottom:"conv8" + top:"bn8" +} +layer { + name: "swish8/sig" + type: "Sigmoid" + bottom:"bn8" + top: "swish8/sig" +} +layer { + name: "swish8" + type: "Eltwise" + bottom:"bn8" + bottom: "swish8/sig" + top:"swish8" + eltwise_param { operation: PROD } +} +layer { + name:"conv9_3x3_256" + type:"Convolution" + bottom:"swish8" + top:"conv9" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn9" + type:"BatchNorm" + bottom:"conv9" + top:"bn9" +} +layer { + name:"elt9" + type:"Eltwise" + bottom:"swish7" + bottom:"bn9" + top:"sum9" + eltwise_param { operation: SUM } +} +layer { + name: "swish9/sig" + type: "Sigmoid" + bottom:"sum9" + top: "swish9/sig" +} +layer { + name: "swish9" + type: "Eltwise" + bottom:"sum9" + bottom: "swish9/sig" + top:"swish9" + eltwise_param { operation: PROD } +} +layer { + name:"conv10_3x3_256" + type:"Convolution" + bottom:"swish9" + top:"conv10" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn10" + type:"BatchNorm" + bottom:"conv10" + top:"bn10" +} +layer { + name: "swish10/sig" + type: "Sigmoid" + bottom:"bn10" + top: "swish10/sig" +} +layer { + name: "swish10" + type: "Eltwise" + bottom:"bn10" + bottom: "swish10/sig" + top:"swish10" + eltwise_param { operation: PROD } +} +layer { + name:"conv11_3x3_256" + type:"Convolution" + bottom:"swish10" + top:"conv11" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn11" + type:"BatchNorm" + bottom:"conv11" + top:"bn11" +} +layer { + name:"elt11" + type:"Eltwise" + bottom:"swish9" + bottom:"bn11" + top:"sum11" + eltwise_param { operation: SUM } +} +layer { + name: "swish11/sig" + type: "Sigmoid" + bottom:"sum11" + top: "swish11/sig" +} +layer { + name: "swish11" + type: "Eltwise" + bottom:"sum11" + bottom: "swish11/sig" + top:"swish11" + eltwise_param { operation: PROD } +} +layer { + name:"conv12_3x3_256" + type:"Convolution" + bottom:"swish11" + top:"conv12" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn12" + type:"BatchNorm" + bottom:"conv12" + top:"bn12" +} +layer { + name: "swish12/sig" + type: "Sigmoid" + bottom:"bn12" + top: "swish12/sig" +} +layer { + name: "swish12" + type: "Eltwise" + bottom:"bn12" + bottom: "swish12/sig" + top:"swish12" + eltwise_param { operation: PROD } +} +layer { + name:"conv13_3x3_256" + type:"Convolution" + bottom:"swish12" + top:"conv13" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn13" + type:"BatchNorm" + bottom:"conv13" + top:"bn13" +} +layer { + name:"elt13" + type:"Eltwise" + bottom:"swish11" + bottom:"bn13" + top:"sum13" + eltwise_param { operation: SUM } +} +layer { + name: "swish13/sig" + type: "Sigmoid" + bottom:"sum13" + top: "swish13/sig" +} +layer { + name: "swish13" + type: "Eltwise" + bottom:"sum13" + bottom: "swish13/sig" + top:"swish13" + eltwise_param { operation: PROD } +} +layer { + name:"conv14_3x3_256" + type:"Convolution" + bottom:"swish13" + top:"conv14" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn14" + type:"BatchNorm" + bottom:"conv14" + top:"bn14" +} +layer { + name: "swish14/sig" + type: "Sigmoid" + bottom:"bn14" + top: "swish14/sig" +} +layer { + name: "swish14" + type: "Eltwise" + bottom:"bn14" + bottom: "swish14/sig" + top:"swish14" + eltwise_param { operation: PROD } +} +layer { + name:"conv15_3x3_256" + type:"Convolution" + bottom:"swish14" + top:"conv15" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn15" + type:"BatchNorm" + bottom:"conv15" + top:"bn15" +} +layer { + name:"elt15" + type:"Eltwise" + bottom:"swish13" + bottom:"bn15" + top:"sum15" + eltwise_param { operation: SUM } +} +layer { + name: "swish15/sig" + type: "Sigmoid" + bottom:"sum15" + top: "swish15/sig" +} +layer { + name: "swish15" + type: "Eltwise" + bottom:"sum15" + bottom: "swish15/sig" + top:"swish15" + eltwise_param { operation: PROD } +} +layer { + name:"conv16_3x3_256" + type:"Convolution" + bottom:"swish15" + top:"conv16" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn16" + type:"BatchNorm" + bottom:"conv16" + top:"bn16" +} +layer { + name: "swish16/sig" + type: "Sigmoid" + bottom:"bn16" + top: "swish16/sig" +} +layer { + name: "swish16" + type: "Eltwise" + bottom:"bn16" + bottom: "swish16/sig" + top:"swish16" + eltwise_param { operation: PROD } +} +layer { + name:"conv17_3x3_256" + type:"Convolution" + bottom:"swish16" + top:"conv17" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn17" + type:"BatchNorm" + bottom:"conv17" + top:"bn17" +} +layer { + name:"elt17" + type:"Eltwise" + bottom:"swish15" + bottom:"bn17" + top:"sum17" + eltwise_param { operation: SUM } +} +layer { + name: "swish17/sig" + type: "Sigmoid" + bottom:"sum17" + top: "swish17/sig" +} +layer { + name: "swish17" + type: "Eltwise" + bottom:"sum17" + bottom: "swish17/sig" + top:"swish17" + eltwise_param { operation: PROD } +} +layer { + name:"conv18_3x3_256" + type:"Convolution" + bottom:"swish17" + top:"conv18" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn18" + type:"BatchNorm" + bottom:"conv18" + top:"bn18" +} +layer { + name: "swish18/sig" + type: "Sigmoid" + bottom:"bn18" + top: "swish18/sig" +} +layer { + name: "swish18" + type: "Eltwise" + bottom:"bn18" + bottom: "swish18/sig" + top:"swish18" + eltwise_param { operation: PROD } +} +layer { + name:"conv19_3x3_256" + type:"Convolution" + bottom:"swish18" + top:"conv19" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn19" + type:"BatchNorm" + bottom:"conv19" + top:"bn19" +} +layer { + name:"elt19" + type:"Eltwise" + bottom:"swish17" + bottom:"bn19" + top:"sum19" + eltwise_param { operation: SUM } +} +layer { + name: "swish19/sig" + type: "Sigmoid" + bottom:"sum19" + top: "swish19/sig" +} +layer { + name: "swish19" + type: "Eltwise" + bottom:"sum19" + bottom: "swish19/sig" + top:"swish19" + eltwise_param { operation: PROD } +} +layer { + name:"conv20_3x3_256" + type:"Convolution" + bottom:"swish19" + top:"conv20" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn20" + type:"BatchNorm" + bottom:"conv20" + top:"bn20" +} +layer { + name: "swish20/sig" + type: "Sigmoid" + bottom:"bn20" + top: "swish20/sig" +} +layer { + name: "swish20" + type: "Eltwise" + bottom:"bn20" + bottom: "swish20/sig" + top:"swish20" + eltwise_param { operation: PROD } +} +layer { + name:"conv21_3x3_256" + type:"Convolution" + bottom:"swish20" + top:"conv21" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn21" + type:"BatchNorm" + bottom:"conv21" + top:"bn21" +} +layer { + name:"elt21" + type:"Eltwise" + bottom:"swish19" + bottom:"bn21" + top:"sum21" + eltwise_param { operation: SUM } +} +layer { + name: "swish21/sig" + type: "Sigmoid" + bottom:"sum21" + top: "swish21/sig" +} +layer { + name: "swish21" + type: "Eltwise" + bottom:"sum21" + bottom: "swish21/sig" + top:"swish21" + eltwise_param { operation: PROD } +} +layer { + name:"conv22_3x3_256" + type:"Convolution" + bottom:"swish21" + top:"conv22" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn22" + type:"BatchNorm" + bottom:"conv22" + top:"bn22" +} +layer { + name: "swish22/sig" + type: "Sigmoid" + bottom:"bn22" + top: "swish22/sig" +} +layer { + name: "swish22" + type: "Eltwise" + bottom:"bn22" + bottom: "swish22/sig" + top:"swish22" + eltwise_param { operation: PROD } +} +layer { + name:"conv23_3x3_256" + type:"Convolution" + bottom:"swish22" + top:"conv23" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn23" + type:"BatchNorm" + bottom:"conv23" + top:"bn23" +} +layer { + name:"elt23" + type:"Eltwise" + bottom:"swish21" + bottom:"bn23" + top:"sum23" + eltwise_param { operation: SUM } +} +layer { + name: "swish23/sig" + type: "Sigmoid" + bottom:"sum23" + top: "swish23/sig" +} +layer { + name: "swish23" + type: "Eltwise" + bottom:"sum23" + bottom: "swish23/sig" + top:"swish23" + eltwise_param { operation: PROD } +} +layer { + name:"conv24_3x3_256" + type:"Convolution" + bottom:"swish23" + top:"conv24" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn24" + type:"BatchNorm" + bottom:"conv24" + top:"bn24" +} +layer { + name: "swish24/sig" + type: "Sigmoid" + bottom:"bn24" + top: "swish24/sig" +} +layer { + name: "swish24" + type: "Eltwise" + bottom:"bn24" + bottom: "swish24/sig" + top:"swish24" + eltwise_param { operation: PROD } +} +layer { + name:"conv25_3x3_256" + type:"Convolution" + bottom:"swish24" + top:"conv25" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn25" + type:"BatchNorm" + bottom:"conv25" + top:"bn25" +} +layer { + name:"elt25" + type:"Eltwise" + bottom:"swish23" + bottom:"bn25" + top:"sum25" + eltwise_param { operation: SUM } +} +layer { + name: "swish25/sig" + type: "Sigmoid" + bottom:"sum25" + top: "swish25/sig" +} +layer { + name: "swish25" + type: "Eltwise" + bottom:"sum25" + bottom: "swish25/sig" + top:"swish25" + eltwise_param { operation: PROD } +} +layer { + name:"conv26_3x3_256" + type:"Convolution" + bottom:"swish25" + top:"conv26" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn26" + type:"BatchNorm" + bottom:"conv26" + top:"bn26" +} +layer { + name: "swish26/sig" + type: "Sigmoid" + bottom:"bn26" + top: "swish26/sig" +} +layer { + name: "swish26" + type: "Eltwise" + bottom:"bn26" + bottom: "swish26/sig" + top:"swish26" + eltwise_param { operation: PROD } +} +layer { + name:"conv27_3x3_256" + type:"Convolution" + bottom:"swish26" + top:"conv27" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn27" + type:"BatchNorm" + bottom:"conv27" + top:"bn27" +} +layer { + name:"elt27" + type:"Eltwise" + bottom:"swish25" + bottom:"bn27" + top:"sum27" + eltwise_param { operation: SUM } +} +layer { + name: "swish27/sig" + type: "Sigmoid" + bottom:"sum27" + top: "swish27/sig" +} +layer { + name: "swish27" + type: "Eltwise" + bottom:"sum27" + bottom: "swish27/sig" + top:"swish27" + eltwise_param { operation: PROD } +} +layer { + name:"conv28_3x3_256" + type:"Convolution" + bottom:"swish27" + top:"conv28" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn28" + type:"BatchNorm" + bottom:"conv28" + top:"bn28" +} +layer { + name: "swish28/sig" + type: "Sigmoid" + bottom:"bn28" + top: "swish28/sig" +} +layer { + name: "swish28" + type: "Eltwise" + bottom:"bn28" + bottom: "swish28/sig" + top:"swish28" + eltwise_param { operation: PROD } +} +layer { + name:"conv29_3x3_256" + type:"Convolution" + bottom:"swish28" + top:"conv29" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn29" + type:"BatchNorm" + bottom:"conv29" + top:"bn29" +} +layer { + name:"elt29" + type:"Eltwise" + bottom:"swish27" + bottom:"bn29" + top:"sum29" + eltwise_param { operation: SUM } +} +layer { + name: "swish29/sig" + type: "Sigmoid" + bottom:"sum29" + top: "swish29/sig" +} +layer { + name: "swish29" + type: "Eltwise" + bottom:"sum29" + bottom: "swish29/sig" + top:"swish29" + eltwise_param { operation: PROD } +} +layer { + name:"conv30_3x3_256" + type:"Convolution" + bottom:"swish29" + top:"conv30" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn30" + type:"BatchNorm" + bottom:"conv30" + top:"bn30" +} +layer { + name: "swish30/sig" + type: "Sigmoid" + bottom:"bn30" + top: "swish30/sig" +} +layer { + name: "swish30" + type: "Eltwise" + bottom:"bn30" + bottom: "swish30/sig" + top:"swish30" + eltwise_param { operation: PROD } +} +layer { + name:"conv31_3x3_256" + type:"Convolution" + bottom:"swish30" + top:"conv31" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn31" + type:"BatchNorm" + bottom:"conv31" + top:"bn31" +} +layer { + name:"elt31" + type:"Eltwise" + bottom:"swish29" + bottom:"bn31" + top:"sum31" + eltwise_param { operation: SUM } +} +layer { + name: "swish31/sig" + type: "Sigmoid" + bottom:"sum31" + top: "swish31/sig" +} +layer { + name: "swish31" + type: "Eltwise" + bottom:"sum31" + bottom: "swish31/sig" + top:"swish31" + eltwise_param { operation: PROD } +} +layer { + name:"conv32_3x3_256" + type:"Convolution" + bottom:"swish31" + top:"conv32" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn32" + type:"BatchNorm" + bottom:"conv32" + top:"bn32" +} +layer { + name: "swish32/sig" + type: "Sigmoid" + bottom:"bn32" + top: "swish32/sig" +} +layer { + name: "swish32" + type: "Eltwise" + bottom:"bn32" + bottom: "swish32/sig" + top:"swish32" + eltwise_param { operation: PROD } +} +layer { + name:"conv33_3x3_256" + type:"Convolution" + bottom:"swish32" + top:"conv33" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn33" + type:"BatchNorm" + bottom:"conv33" + top:"bn33" +} +layer { + name:"elt33" + type:"Eltwise" + bottom:"swish31" + bottom:"bn33" + top:"sum33" + eltwise_param { operation: SUM } +} +layer { + name: "swish33/sig" + type: "Sigmoid" + bottom:"sum33" + top: "swish33/sig" +} +layer { + name: "swish33" + type: "Eltwise" + bottom:"sum33" + bottom: "swish33/sig" + top:"swish33" + eltwise_param { operation: PROD } +} +layer { + name:"conv34_3x3_256" + type:"Convolution" + bottom:"swish33" + top:"conv34" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn34" + type:"BatchNorm" + bottom:"conv34" + top:"bn34" +} +layer { + name: "swish34/sig" + type: "Sigmoid" + bottom:"bn34" + top: "swish34/sig" +} +layer { + name: "swish34" + type: "Eltwise" + bottom:"bn34" + bottom: "swish34/sig" + top:"swish34" + eltwise_param { operation: PROD } +} +layer { + name:"conv35_3x3_256" + type:"Convolution" + bottom:"swish34" + top:"conv35" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn35" + type:"BatchNorm" + bottom:"conv35" + top:"bn35" +} +layer { + name:"elt35" + type:"Eltwise" + bottom:"swish33" + bottom:"bn35" + top:"sum35" + eltwise_param { operation: SUM } +} +layer { + name: "swish35/sig" + type: "Sigmoid" + bottom:"sum35" + top: "swish35/sig" +} +layer { + name: "swish35" + type: "Eltwise" + bottom:"sum35" + bottom: "swish35/sig" + top:"swish35" + eltwise_param { operation: PROD } +} +layer { + name:"conv36_3x3_256" + type:"Convolution" + bottom:"swish35" + top:"conv36" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn36" + type:"BatchNorm" + bottom:"conv36" + top:"bn36" +} +layer { + name: "swish36/sig" + type: "Sigmoid" + bottom:"bn36" + top: "swish36/sig" +} +layer { + name: "swish36" + type: "Eltwise" + bottom:"bn36" + bottom: "swish36/sig" + top:"swish36" + eltwise_param { operation: PROD } +} +layer { + name:"conv37_3x3_256" + type:"Convolution" + bottom:"swish36" + top:"conv37" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn37" + type:"BatchNorm" + bottom:"conv37" + top:"bn37" +} +layer { + name:"elt37" + type:"Eltwise" + bottom:"swish35" + bottom:"bn37" + top:"sum37" + eltwise_param { operation: SUM } +} +layer { + name: "swish37/sig" + type: "Sigmoid" + bottom:"sum37" + top: "swish37/sig" +} +layer { + name: "swish37" + type: "Eltwise" + bottom:"sum37" + bottom: "swish37/sig" + top:"swish37" + eltwise_param { operation: PROD } +} +layer { + name:"conv38_3x3_256" + type:"Convolution" + bottom:"swish37" + top:"conv38" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn38" + type:"BatchNorm" + bottom:"conv38" + top:"bn38" +} +layer { + name: "swish38/sig" + type: "Sigmoid" + bottom:"bn38" + top: "swish38/sig" +} +layer { + name: "swish38" + type: "Eltwise" + bottom:"bn38" + bottom: "swish38/sig" + top:"swish38" + eltwise_param { operation: PROD } +} +layer { + name:"conv39_3x3_256" + type:"Convolution" + bottom:"swish38" + top:"conv39" + convolution_param { + num_output: 256 + kernel_size: 3 + pad: 1 + weight_filler { type:"msra" } + bias_filler { type:"constant" } + } +} +layer { + name:"bn39" + type:"BatchNorm" + bottom:"conv39" + top:"bn39" +} +layer { + name:"elt39" + type:"Eltwise" + bottom:"swish37" + bottom:"bn39" + top:"sum39" + eltwise_param { operation: SUM } +} +layer { + name: "swish39/sig" + type: "Sigmoid" + bottom:"sum39" + top: "swish39/sig" +} +layer { + name: "swish39" + type: "Eltwise" + bottom:"sum39" + bottom: "swish39/sig" + top:"swish39" + eltwise_param { operation: PROD } +} + +# ResNet block ends here. + + + +# policy head +layer { + name: "conv1_p_1x1_160" # 9*9*160 = 12960 > 11259 + type: "Convolution" + bottom: "swish39" + top: "conv1_p" + convolution_param { + num_output: 160 + kernel_size: 1 + pad: 0 + weight_filler { type: "msra" } + bias_filler { type: "constant" } + } +} +layer { + name:"bn1_p" + type:"BatchNorm" + bottom:"conv1_p" + top:"bn1_p" +} +layer { + name: "swish1_p/sig" + type: "Sigmoid" + bottom:"bn1_p" + top: "swish1_p/sig" +} +layer { + name: "swish1_p" + type: "Eltwise" + bottom:"bn1_p" + bottom: "swish1_p/sig" + top:"swish1_p" + eltwise_param { operation: PROD } +} + +layer { + # 9*9 *139 = 11259 + # 9*9 *27 = 2187 + name: "conv2_p_1x1_27" + type: "Convolution" + bottom: "swish1_p" + top: "conv2_p" + convolution_param { + num_output: 27 + kernel_size: 1 + pad: 0 + weight_filler { type: "msra" } + bias_filler { type: "constant" } + } +} +layer { + name: "flat_p" + type: "Flatten" + bottom: "conv2_p" + top: "flat_p" +} + +# from DuelNet-40-64.prototxt by Kobayashi-san +# and https://github.com/adepierre/Caffe_AlphaZero +layer { + name: "softmax" + type: "Softmax" + bottom: "flat_p" + top: "policy_probability" +} + + +# value head +layer { + name: "conv1_v_1x1_4" # 9*9*4 = 324 > 256 + type: "Convolution" + bottom: "swish39" + top: "conv1_v" + convolution_param { + num_output: 4 + kernel_size: 1 + pad: 0 + weight_filler { type: "msra" } + bias_filler { type: "constant" } + } +} +layer { + name:"bn1_v" + type:"BatchNorm" + bottom:"conv1_v" + top:"bn1_v" +} +layer { + name: "swish1_v/sig" + type: "Sigmoid" + bottom:"bn1_v" + top: "swish1_v/sig" +} +layer { + name: "swish1_v" + type: "Eltwise" + bottom:"bn1_v" + bottom: "swish1_v/sig" + top:"swish1_v" + eltwise_param { operation: PROD } +} +layer { + name: "ip2_v" + type: "InnerProduct" + inner_product_param { + num_output: 256 + weight_filler { type: "msra" } + bias_filler { type: "constant" } + } + bottom: "swish1_v" + top: "ip2_v" +} +layer { + name: "swish2_v/sig" + type: "Sigmoid" + bottom:"ip2_v" + top: "swish2_v/sig" +} +layer { + name: "swish2_v" + type: "Eltwise" + bottom:"ip2_v" + bottom: "swish2_v/sig" + top:"swish2_v" + eltwise_param { operation: PROD } +} +layer { + name: "ip3_v" + type: "InnerProduct" + inner_product_param { + num_output: 1 + weight_filler { type: "xavier" } + bias_filler { type: "constant" } + } + bottom: "swish2_v" + top: "ip3_v" +} +layer { + name: "tanh_v" + type: "TanH" + bottom: "ip3_v" + top: "tanh_v" +} diff --git a/learn/aoba_zero_solver.prototxt b/learn/aoba_zero_solver.prototxt index a36ef7e..15eb3b1 100644 --- a/learn/aoba_zero_solver.prototxt +++ b/learn/aoba_zero_solver.prototxt @@ -1,8 +1,9 @@ #net: "aoba_zero.prototxt" #net: "aoba_zero_256x40b.prototxt" #net: "aoba_zero_256x20b.prototxt" -net: "aoba_zero_256x20b_mb128.prototxt" +#net: "aoba_zero_256x20b_mb128.prototxt" #net: "aoba_zero_256x40b_mb64.prototxt" +net: "aoba_256x20b_swish_mb128.prototxt" # test_iter specifies how many forward passes the test should carry out. # In the case of MNIST, we have test batch size 100 and 100 test iterations, diff --git a/learn/handicap_rate.txt b/learn/handicap_rate.txt new file mode 100644 index 0000000..15b9735 --- /dev/null +++ b/learn/handicap_rate.txt @@ -0,0 +1,2 @@ +52240000 52172800 52172800 52172800 52172800 52172800 52172800 +914 0 0 0 0 0 0 diff --git a/learn/learn.txt b/learn/learn.txt index 2c46606..91d0abb 100644 --- a/learn/learn.txt +++ b/learn/learn.txt @@ -9,28 +9,34 @@ xz $ sudo apt install xz-utils liblzma-dev archive/ �β��� - arch000000000000.csa.xz ���� - arch000000200000.csa.xz + arch000051420000.csa.xz ���� + arch000052500000.csa.xz ���餤�ޤǤ��֤��ޤ��� -https://drive.google.com/drive/folders/1dbE5xWGQLsduR00oxEGPpZQJtQr_EQ75 +https://drive.google.com/drive/folders/1fZJn288VhU6kE7crX7H1Ml4GcRZH0uHK -$ cd archive -$ xz -d -k *.xz +�ǥ��쥯�ȥ��̾�˹�碌�� yss_dcnn.cpp �� 2778���ܤ�����β���2�Ĥ��ѹ����ޤ��� +char dir_arch[] = "/home/yss/tcp_backup/archive/"; +char dir_pool[] = "/home/yss/tcp_backup/pool"; -�Ǥ��٤�Ÿ�����ޤ��� +yss_dcnn.cpp �� +fReplayLearning = 1; �ˤ��ޤ��� +����ǽ�������줿�Ťߤ���Ϥ����ϲ��ιԤ򥳥��ȥ����Ȥ��ޤ��� +net->CopyTrainedLayersFrom(sNet); // caffemodel���ɤ߹���dzؽ���Ƴ������� +5142�����褫��ؽ�����ˤϲ��Τ褦�ˤ��ޤ��� +int zdb_count_start = 51420000; $ make $ learn �Ǽ¹Ԥ��ޤ��� -12��������ɤ߹�����塢2000�����ɲä��Ȥ�4000��ؽ����򷫤��֤��ޤ��� -���10�����褫��������64���̤���Ф���64 minibatch�dzؽ����ޤ��� +100��������ɤ߹�����塢2000�����ɲä��Ȥ�4000��ؽ����򷫤��֤��ޤ��� +���100�����褫��������64���̤���Ф���64 minibatch�dzؽ����ޤ��� + + �ºݤζ����ؽ���Ԥ��ˤ� -yss_dcnn.cpp �� fReplayLearning = 0; -ZERO_DB_SIZE = 500000; �ˤ��ơ�pool/ �β��˺ǿ��δ��褬 no000000000000.csa.xz no000000000001.csa.xz @@ -46,5 +52,5 @@ no000000009999.csa.xz archive/arch000000000000.csa.xz �������褦�ˤ��ޤ����ܤ����ϥ�����¦�������������� -���50������ޤǸ���ˤϥ��꤬����Ǥ�19GB�ʾ�ɬ�פǤ��� +���100������ޤǸ���ˤϥ��꤬����Ǥ�12GB�ʾ�ɬ�פǤ��� diff --git a/learn/yss.cpp b/learn/yss.cpp index 130920d..da858b4 100644 --- a/learn/yss.cpp +++ b/learn/yss.cpp @@ -172,7 +172,7 @@ int GetSystemMemoryMB() const char *get_kdbDirSL() { return ""; } // NULL�ǤϤʤ���Ĺ����0��ʸ�������Ƭ���ɥ쥹���֤� -int get_learning_dir_number() { PRT("must be programmed!\n"); debug(); return 0; } +int get_learning_dir_number() { DEBUG_PRT("must be programmed!\n"); return 0; } int change_dir(const char* /* sDir */) { return 0; } void return_dir() {} @@ -208,7 +208,6 @@ int open_one_file(char *filename) PS->SetSennititeKif(); // ����������������Ͽ���� - PRT_ON(); return 1; } @@ -290,7 +289,7 @@ int get_next_file_from_dirs(char *filename, const char *ext, const char *dir_lis return 0; } if ( change_dir(p_current_dir) == 0 ) { - PRT("fail change dir=%s\n",p_current_dir); debug(); + DEBUG_PRT("fail change dir=%s\n",p_current_dir); } } @@ -386,7 +385,7 @@ void PRT_ON() { fPrtCut = 0; } #else if ( len < 0 || len >= PRT_LEN_MAX ) { PRT_sub("PRT len over!\n"); - debug(); + DEBUG_PRT("PRT len over!"); } PRT_sub("%s",text); // PRT(text) ����text="%CHUDAN"��"HUDAN"�ˤʤäƤ��ޤ��� #endif @@ -458,7 +457,7 @@ int shogi::kifu_set_move(int bz,int az,int tk,int nf, int t) // char retp[20]; // change(bz,az,tk,nf,retp); // PRT("%s, bz,az,tk,nf = %x,%x,%x,%x\n",retp,bz,az,tk,nf); - if ( tesuu >= KIFU_MAX-1 ) { PRT("KIFU_MAX Err\n"); debug(); } + if ( tesuu >= KIFU_MAX-1 ) { DEBUG_PRT("KIFU_MAX Err\n"); } move_hit(bz,az,tk,nf); tesuu++; all_tesuu = tesuu; kifu[tesuu][0] = bz; @@ -880,7 +879,6 @@ int shogi::getMoveFromCsaStr(int *bz, int *az, int *tk, int *nf, char *str) return 1; } - // CSA�����δ�����ɤ߹��� int shogi::LoadCSA() { @@ -935,6 +933,11 @@ int shogi::LoadCSA() prt_flag = 0; ban_saikousei(); // ���̤κƹ����� check_kn(); // ���̤ξ��֤����ﲽ�����å� + + // �����Ƚ�� + ZERO_DB *pz = &zdb_one; + pz->handicap = get_handicap_from_board(); + if ( pz->handicap && fGotekara==0 ) DEBUG_PRT("pz->handiacp=%d\n",pz->handicap); } // csa�����Υ����Ȥ������ @@ -972,7 +975,7 @@ int shogi::LoadCSA() char str[10]; int n = 0; for (;;) { - if ( n>=10 ) { PRT("Err csa move str >= %d,w=%d,%s\n",n,pz->weight_n,sIndex); debug(); } + if ( n>=10 ) { DEBUG_PRT("Err csa move str >= %d,w=%d,%s\n",n,pz->weight_n,sIndex); } c = *p++; str[n++] = c; if ( c==',' || c=='\r' || c =='\n' || c==0 ) break; @@ -993,7 +996,7 @@ int shogi::LoadCSA() } } else { if ( (count&1)== 0 ) { - if ( b0==0 && b1==0 ) debug(); + if ( b0==0 && b1==0 ) DEBUG_PRT(""); int v = atoi(str); if ( v > 0xffff ) v = 0xffff; sum_visit += v; @@ -1002,9 +1005,10 @@ int shogi::LoadCSA() pz->vv_move_visit[tesuu].push_back(move_visit); b0 = b1 = 0; } else { - if ( getMoveFromCsaStr(&bz, &az, &tk, &nf, str)==0 ) debug(); - if ( is_pseudo_legalYSS((Move)pack_te(bz,az,tk,nf), (Color)((tesuu&1)==1)) == false ) { - PRT("move Err %3d:%s\n",tesuu,str); debug(); + if ( getMoveFromCsaStr(&bz, &az, &tk, &nf, str)==0 ) DEBUG_PRT(""); + int c = (tesuu+(pz->handicap!=0))&1; + if ( is_pseudo_legalYSS((Move)pack_te(bz,az,tk,nf), (Color)(c==1) ) == false ) { + DEBUG_PRT("move Err %3d:%s\n",tesuu,str); } pack_from4_to_2_KDB(&b0,&b1, bz, az, tk, nf); } @@ -1051,7 +1055,7 @@ P+00KE00KE00FU ' ������ P-00HI P-00AL -*/ +*/ /* P-21KE22OU33KE23FU P+32GI14FU26KE @@ -1061,6 +1065,15 @@ P-00AL +2634KE -2232OU +0042KI +*/ +/* +PI ʿ�� +PI11KY ����� +PI22KA ����� +PI82HI ������� +PI82HI22KA 2����� +PI82HI22KA11KY91KY 4����� +PI82HI22KA11KY91KY21KE81KE 6����� */ y = lpLine[1]; @@ -1102,6 +1115,17 @@ P-00AL else if ( y == '-' ) mo_c[i]++; // ���λ��� } } + if ( y == 'I' ) { // ����������� + for (lpCopy=lpLine+2; lpCopy-lpLine9 || xx<1 || xx>9 ) { DEBUG_PRT("PI Err\n"); } + int i = get_csa_koma(lpCopy+2); + if ( i==0 ) { DEBUG_PRT("������̥��顼='%c%c'\n",*(lpCopy+2),*(lpCopy+3)); } + init_ban[yy*16+(10-xx)] = 0; + } + } + y = lpLine[1] - '0'; if ( 1<=y && y<=9 ) { // 1�Ԥζ� lpCopy = lpLine+2; @@ -1143,8 +1167,10 @@ P-00AL pz->moves = tesuu; pz->result = ZD_DRAW; pz->result_type = RT_NONE; + int is_gote_turn = (tesuu + (pz->handicap!=0))& 1; + if ( strstr(lpLine,"TORYO") ) { - if ( tesuu & 1 ) { + if ( is_gote_turn ) { pz->result = ZD_S_WIN; } else { pz->result = ZD_G_WIN; @@ -1152,7 +1178,7 @@ P-00AL pz->result_type = RT_TORYO; } if ( strstr(lpLine,"KACHI") ) { - if ( tesuu & 1 ) { + if ( is_gote_turn ) { pz->result = ZD_G_WIN; } else { pz->result = ZD_S_WIN; @@ -1180,7 +1206,7 @@ P-00AL for (i=0;i<(int)pz->vv_move_visit.size();i++) { sum += pz->vv_move_visit[i].size(); } - PRT("moves=%d,result=%d, mv_sum=%d,%.1f\n",pz->moves,pz->result,sum, (double)sum/(tesuu+0.00001f)); + PRT("handicap=%d,moves=%d,result=%d, mv_sum=%d,%.1f\n",pz->handicap,pz->moves,pz->result,sum, (double)sum/(tesuu+0.00001f)); if ( pz->result_type == RT_NONE ) DEBUG_PRT(""); #endif break; // �ɤ߹��߽�λ @@ -1264,7 +1290,7 @@ void shogi::LoadShotest(void) char *pdest; pdest = strchr( drop_shotest, c ); - if ( pdest == NULL ) { PRT("������ȯ���ߥ� shotest\n"); debug(); } + if ( pdest == NULL ) { DEBUG_PRT("������ȯ���ߥ� shotest\n"); } i = pdest - drop_shotest + 1; } tk = i + (0x80)*(tesuu&1); @@ -1361,7 +1387,7 @@ void shogi::LoadTextBan() for (i=1;i<8;i++) { sprintf(find,"%s",koma_kanji[i+16]); char *q = strstr(p+2*9,find); - if ( q==NULL) { PRT("not found ��\n"); debug(); } + if ( q==NULL) { DEBUG_PRT("not found ��\n"); } mo_c[i] = *(q+3) - '0'; } } @@ -1391,7 +1417,7 @@ void shogi::LoadTextBan() const char *sSengoSankaku[3] = {"��","��","��"}; -int shogi::IsSenteTurn() { return ( ((fGotekara+tesuu)&1) == 0 ); } // ��������������ʤ� +int shogi::IsSenteTurn() { DEBUG_PRT(""); return ( ((fGotekara+tesuu)&1) == 0 ); } // ��������������ʤ� int shogi::GetSennititeMax() { return nSennititeMax; } // ���ڷ����δ�����ɤ߹��� diff --git a/learn/yss.h b/learn/yss.h index 31478ad..5b3d3de 100644 --- a/learn/yss.h +++ b/learn/yss.h @@ -2,6 +2,12 @@ // This source code is in the public domain. /* yss.h class����� */ + + +#define F2187 + + + #define SMP // ����õ��������ˤ�������� #ifdef SMP @@ -211,6 +217,8 @@ class shogi { void allkaku(void); // ����������� void allkesu(void); + void kiki_write(int z); + void kiki_delete(int z); // yss_ki2.cpp void init(void); // kn[]���������ƺ����ꡣhash_code �� tume_hyouka ������� @@ -376,6 +384,7 @@ class shogi { void clear_mo(); void clear_init_ban(); void hirate_ban_init(int n);/*** ���̤������֤��᤹�ʶ�����դ��� ***/ + int get_handicap_from_board(); void ban_saikousei(void); // ���ߤλ��������̤ξ���(ban_init)�򸵤����̾��֤�ƹ������롣 int is_hirate_ban(); // ʿ������̤�Ƚ�ꤹ�� void hanten_with_hash_kifu(); @@ -402,11 +411,11 @@ class shogi { } // yss_bwh1.cpp - void trans_4_to_2_KDB(int b0,int b1, int num, int *bz,int *az, int *tk, int *nf); // ����������2�Х��Ȥ�4�Х��Ȥ��Ѵ��� + void trans_4_to_2_KDB(int b0,int b1, bool bGoteTurn, int *bz,int *az, int *tk, int *nf); // ����������2�Х��Ȥ�4�Х��Ȥ��Ѵ��� // yss_dcnn.cpp void make_policy_leveldb(); - void set_dcnn_channels(Color sideToMove, const int ply, float *p_data, int stock_num, int net_type); + void set_dcnn_channels(Color sideToMove, const int ply, float *p_data, int stock_num, int nHandicap); void setYssChannels(Color sideToMove, int moves, float *p_data, int net_kind, int input_num); int get_cnn_next_move(); HASH_SHOGI* HashShogiReadLock(); @@ -417,8 +426,12 @@ class shogi { int uct_search_start(Color sideToMove); int think_kifuset(); void update_zero_kif_db(); - void copy_restore_dccn_init_board(int fCopy); + void copy_restore_dccn_init_board(int handicap, bool fCopy); +#ifdef F2187 + void prepare_kif_db(int fPW, int mini_batch, float *data, float *label_policy, float *label_value, float label_policy_visit[][2187]); +#else void prepare_kif_db(int fPW, int mini_batch, float *data, float *label_policy, float *label_value, float label_policy_visit[][MOVE_C_Y_X_ID_MAX]); +#endif void init_prepare_kif_db(); float get_network_policy_value(Color sideToMove, int ply, HASH_SHOGI *phg); char *prt_pv_from_hash(int ply); diff --git a/learn/yss_dcnn.cpp b/learn/yss_dcnn.cpp index 83d74bf..37f24d6 100644 --- a/learn/yss_dcnn.cpp +++ b/learn/yss_dcnn.cpp @@ -23,17 +23,25 @@ using namespace std; +#ifdef F2187 // yss.h +const int f2187 = 1; +#else +const int f2187 = 0; +#endif + +const int HANDICAP_TYPE = 7; #define USE_CAFFE 1 #define YSS_TRAIN 0 // 0��test, 1��train DB���� const int DCNN_CHANNELS = 362; +//const int DCNN_CHANNELS = 85; // 45+2 + 14*2 + 10 #define FILE_HEADER "i361_11259_1600self_leveldb" const int fMAKE_LEVELDB = 0; -#if (YSS_TRAIN==0) +#if (YSS_TRAIN==0) const char CONVERT_DB_FILE[] = "test_" FILE_HEADER; #else const char CONVERT_DB_FILE[] = "train_" FILE_HEADER; @@ -378,7 +386,7 @@ char *find_next_file(char *sDir, const char *sExt) if ( dir == NULL ) { dir = opendir(sDir); - if ( dir == NULL ) { PRT("fail opendir() %s\n",sDir); debug(); } + if ( dir == NULL ) { DEBUG_PRT("fail opendir() %s\n",sDir); } strcpy(dir_name, sDir); } @@ -455,7 +463,7 @@ int get_one_v_file(char *filename, const char *dir_list[]) const char *sDir = dir_v_sgf_list[dir_v_sgf_n]; if ( sDir == NULL ) { PRT("done...sum_dir=%d,all_files=%d\n",sum_dir,all_files); return -1; } dir_num = scandir(sDir, &namelist, NULL, NULL); - if ( dir_num < 0 || namelist==NULL ) { PRT("Err scandir\n"); debug(); } + if ( dir_num < 0 || namelist==NULL ) { DEBUG_PRT("Err scandir\n"); } } if ( dir_i >= dir_num ) { dir_num = 0; @@ -502,11 +510,11 @@ void shuffle_prt(int *p_stock_num) const char sLabel[] = "/home/yss/yssfish/value/label_tmp.txt"; static int fFirst = 1; if ( fFirst ) { - if ( fopen(sLabel,"r")!=NULL ) { PRT("Err %s exist!!!\n",sLabel); debug(); } + if ( fopen(sLabel,"r")!=NULL ) { DEBUG_PRT("Err %s exist!!!\n",sLabel); } fFirst = 0; } FILE *fp = fopen(sLabel,"a"); - if ( fp==NULL ) { PRT("fail fopen()\n"); debug(); } + if ( fp==NULL ) { DEBUG_PRT("fail fopen()\n"); } // fprintf(fp,"%.0f\n", dcnn_label_data[r]); fprintf(fp,"%u\n",(unsigned int)(dcnn_labels[r][0])); fprintf(fp,"%d\n",dcnn_labels[r][1]); @@ -566,19 +574,19 @@ void shogi::make_policy_leveldb() }; // if ( FV_LEARNING==0 ) { PRT("\n\nset FV_LEARNING=1 for ignoring make_mm3_10_pattern_root()\n\n\n"); debug(); } - if ( fMAKE_LEVELDB == 0 ) { PRT("set fMAKE_LEVELDB=1\n"); debug(); } + if ( fMAKE_LEVELDB == 0 ) { DEBUG_PRT("set fMAKE_LEVELDB=1\n"); } create_convert_db(); dcnn_data = (unsigned char(*)[DCNN_CHANNELS][B_SIZE][B_SIZE])malloc( DCNN_DATA_SIZE ); - if ( dcnn_data == NULL ) { PRT("fail malloc()\n"); debug(); } + if ( dcnn_data == NULL ) { DEBUG_PRT("fail malloc()\n"); } clear_dcnn_data(); // dcnn_label_data = (float *)malloc( STOCK_MAX * sizeof(float) ); // if ( dcnn_label_data == NULL ) { PRT("fail malloc()\n"); debug(); } // memset(dcnn_label_data, 0, STOCK_MAX * sizeof(float) ); dcnn_labels = (int(*)[2])malloc( DCNN_LABELS_SIZE ); - if ( dcnn_labels == NULL ) { PRT("fail malloc()\n"); debug(); } + if ( dcnn_labels == NULL ) { DEBUG_PRT("fail malloc()\n"); } memset(dcnn_labels, 0, DCNN_LABELS_SIZE ); // i362_pro_flood, 6254 ����(Test), 448365 ���� (20279263����) 217545-716-230104 ��꾡Ψ0.514 @@ -695,8 +703,7 @@ void shogi::make_policy_leveldb() // dcnn_labels[stock_num][0] = u; dcnn_labels[stock_num][0] = get_move_id_c_y_x(pack_te(bz,az,tk,nf)); //pack_te(bz,az,tk,nf); dcnn_labels[stock_num][1] = win_r; - set_dcnn_channels(c, i, NULL, stock_num, NET_361); -// set_dcnn_channels(c, i, NULL, stock_num, NET_362); + set_dcnn_channels(c, i, NULL, stock_num, 0); if ( j==1 ) flip_horizontal_channels(stock_num); // PRT("%3d,%02x,%02x,%02x,%02x,%5d,%08x\n",i,bz,az,tk,nf,dcnn_labels[stock_num][0], get_move_from_c_y_x_id(dcnn_labels[stock_num][0])); // PRT("%3d,%02x,%02x,%02x,%02x,%5d,%08x\n",i,bz,az,tk,nf,dcnn_labels[stock_num][0], get_te_from_unique(dcnn_labels[stock_num][0])); @@ -804,11 +811,11 @@ void get_c_y_x_from_move(int *pc, int *py, int *px, int pack_move) void make_label_leveldb() { int ct1 = get_clock(); - if ( DCNN_CHANNELS != LABEL_CHANNELS ) { PRT("DCNN_CHANNELS err.\n"); debug(); } + if ( DCNN_CHANNELS != LABEL_CHANNELS ) { DEBUG_PRT("DCNN_CHANNELS err.\n"); } create_convert_db(); dcnn_data = (unsigned char(*)[DCNN_CHANNELS][B_SIZE][B_SIZE])malloc( DCNN_DATA_SIZE ); - if ( dcnn_data == NULL ) { PRT("fail malloc()\n"); debug(); } + if ( dcnn_data == NULL ) { DEBUG_PRT("fail malloc()\n"); } clear_dcnn_data(); FILE *fp = fopen("test_i362_pro_flood_leveldb.txt","r"); @@ -958,6 +965,44 @@ int get_move_id_c_y_x(int pack) return id; } +const int MOVE_2187_MAX = 2187; + +int get_dlshogi_policy(int bz, int az, int tk, int nf) { + int fDrop = 0; + int fNari = (nf!=0); + int dir = -1; + if ( bz==0xff ) { + fDrop = 1; + dir = (tk & 0x0f) - 1; + } else for (;;) { + // bz �� az ������������� + if ( az == bz - 0x21 ) { dir = 8; break; } // ���� + if ( az == bz - 0x1f ) { dir = 9; break; } + int dx = (bz & 0x0f) - (az & 0x0f); + int dy = ((bz & 0xf0)>>4) - ((az & 0xf0)>>4); + if ( dx==0 ) { + if ( dy > 0 ) dir = 2; + if ( dy < 0 ) dir = 6; + } else if ( dy==0 ) { + if ( dx > 0 ) dir = 0; + if ( dx < 0 ) dir = 4; + } else { + if ( abs(dx) != abs(dy) ) DEBUG_PRT(""); + if ( dx > 0 && dy > 0 ) dir = 1; + if ( dx < 0 && dy > 0 ) dir = 3; + if ( dx < 0 && dy < 0 ) dir = 5; + if ( dx > 0 && dy < 0 ) dir = 7; + } + break; + } + int ax = (az & 0x0f); + int ay = (az & 0xf0) >> 4; + int z81 = (ay-1)*9 + (ax-1); + int index = z81 + 81*dir + fNari*(81*10) + fDrop*(81*20); + if ( index < 0 || index >= 2187 || dir < 0 ) DEBUG_PRT(""); + return index; +} + void prt_dcnn_data(int stock_num,int c,int turn_n) { int x,y; @@ -1048,7 +1093,7 @@ void shogi::setYssChannels(Color sideToMove, int moves, float *p_data, int net_t for (int i=0;i mo_max[i] ) n0 = mo_max[i]; + if ( n1 > mo_max[i] ) n1 = mo_max[i]; + for (y=0;y> 4; + int xx = (az & 0x0f); + yy -= 1; + xx -= 1; + if ( xx < 0 || yy < 0 ) DEBUG_PRT(""); + if ( flip ) { + yy = B_SIZE - y -1; + xx = B_SIZE - x -1; + } + set_dcnn_data(stock_num, data, base+ n+ (loop&1)*81, yy,xx); + if ( tk ) break; + } + } + } + base += add_base; +*/ + + for (int loop_k=1; loop_k<=15; loop_k++) { + if ( loop_k == 13 ) continue; // 14�� + add_base = 2; + clear_kb_kiki_kn(); + init(); + for (y=0;yM ) n0=M; +// if ( n1>M ) n1=M; +// if ( ZERO_ON==0 ) { n0--; n1--; } +// if ( n0 >= 0 ) set_dcnn_data(stock_num, data, base+ n0, yy,xx); +// if ( n1 >= 0 ) set_dcnn_data(stock_num, data, base+M+ZERO_ON+n1, yy,xx); + if ( n0 ) set_dcnn_data(stock_num, data, base+0, yy,xx); // �����ο�̵�� + if ( n1 ) set_dcnn_data(stock_num, data, base+1, yy,xx); + } + base += add_base; + } + + add_base = 1; + clear_kb_kiki_kn(); + init(); + allkaku(); + int check = kiki_c[kn[1][1]]; + if ( flip ) { + if ( check ) DEBUG_PRT(""); + check = kiki_m[kn[2][1]]; + } else { + if ( kiki_m[kn[2][1]] ) DEBUG_PRT(""); + } + if ( check ) for (y=0;y= HANDICAP_TYPE ) DEBUG_PRT(""); + for (y=0;y= 0x06 ) a = 5; // ����5�� + int c = (k&0x80) >> 7; + decl_sum[c] += a; + if ( c==0 && y <= 2 ) { decl_in[c] += a; in_num[c]++; } + if ( c==1 && y >= 6 ) { decl_in[c] += a; in_num[c]++; } + } + + int s0 = mo_m[1] + mo_m[2] + mo_m[3] + mo_m[4] + mo_m[5] + mo_m[6]*5 + mo_m[7]*5; + int s1 = mo_c[1] + mo_c[2] + mo_c[3] + mo_c[4] + mo_c[5] + mo_c[6]*5 + mo_c[7]*5; + decl_in[0] += s0; + decl_in[1] += s1; + decl_sum[0] += s0; + decl_sum[1] += s1; + if ( flip ) { + int tmp; + tmp = in_num[0]; in_num[0] = in_num[1]; in_num[1] = tmp; + tmp = decl_in[0]; decl_in[0] = decl_in[1]; decl_in[1] = tmp; + tmp = decl_sum[0]; decl_sum[0] = decl_sum[1]; decl_sum[1] = tmp; + } + for (y=0;yM ) n0=M; + if ( n1>M ) n1=M; + int i; + if ( n0==0 ) set_dcnn_data(stock_num, data, base+0 , yy,xx); + for (i=0;i= 0 ) set_dcnn_data(stock_num, data, base+ n0, yy,xx); +// if ( n1 >= 0 ) set_dcnn_data(stock_num, data, base+M+ZERO_ON+n1, yy,xx); + } + base += add_base; + + + add_base = 0+18 + 17; + base += add_base; + + +// int left = (28 + 14 + 3)*(8-T_STEP) - (base - prev_base); // 45*X - add +// base += left; +// if ( left < 0 ) DEBUG_PRT(""); +#endif + + + add_base = 2; + if ( sideToMove == BLACK ) for (y=0;yused == 0 ) { // 1���ܤ��Ф���2���ܤ����٤Ƥ�Ʊ��(���м�)�ξ�� - PRT("not created? ��=%d,col=%d,c_num=%d\n",fukasa,phg->col,phg->child_num); - debug(); + DEBUG_PRT("not created? ��=%d,col=%d,c_num=%d\n",fukasa,phg->col,phg->child_num); // create_node(sideToMove, phg); } - if ( phg->col != sideToMove ) { PRT("hash col Err. phg->col=%d,col=%d,age=%d(%d),child_num=%d,games_sum=%d,sort=%d,phg->hash=%" PRIx64 "\n",phg->col,sideToMove,phg->age,thinking_age,phg->child_num,phg->games_sum,phg->sort_done,phg->hashcode64); debug(); } + if ( phg->col != sideToMove ) { DEBUG_PRT("hash col Err. phg->col=%d,col=%d,age=%d(%d),child_num=%d,games_sum=%d,sort=%d,phg->hash=%" PRIx64 "\n",phg->col,sideToMove,phg->age,thinking_age,phg->child_num,phg->games_sum,phg->sort_done,phg->hashcode64); } int child_num = phg->child_num; @@ -1999,7 +2280,7 @@ double shogi::uct_tree(Color sideToMove) path[fukasa] = pc->move; // ����ʰ��֤�˵��� hash_path[fukasa] = get_hashcode64(); fukasa++; - if ( fukasa >= D_MAX ) { PRT("depth over=%d\n",fukasa); debug(); } + if ( fukasa >= D_MAX ) { DEBUG_PRT("depth over=%d\n",fukasa); } double win = 0; @@ -2039,7 +2320,7 @@ double shogi::uct_tree(Color sideToMove) if ( fVirtualLoss ) { phg->games_sum -= VL_N; pc->games -= VL_N; // games�򸺤餹�Τ����˴����� ���������� games==0 ��Ƚ�ꤷ�Ƥ�Τ� - if ( pc->games < 0 ) { PRT("Err pc->games=%d\n",pc->games); debug(); } + if ( pc->games < 0 ) { DEBUG_PRT("Err pc->games=%d\n",pc->games); } if ( pc->games == 0 ) pc->value = 0; else pc->value = (float)((((double)pc->games+VL_N) * pc->value - one_win*VL_N) / pc->games); } @@ -2128,7 +2409,7 @@ float shogi::get_network_policy_value(Color sideToMove, int ply, HASH_SHOGI *phg float *data = new float[size]; memset(data, 0, sizeof(float)*size); - set_dcnn_channels( sideToMove, ply, data, 0, NET_362); + set_dcnn_channels( sideToMove, ply, data, 0, 0); // if ( ply==1 ) { prt_dcnn_data_table((float(*)[B_SIZE][B_SIZE])data); debug(); } { int sum=0; int i; for (i=0;i #include @@ -2422,20 +2702,28 @@ void free_zero_db_struct(ZERO_DB *p) p->result = 0; p->result_type = 0; p->moves = 0; + p->handicap = 0; std::vector().swap(p->v_kif); // memory free hack for vector. std::vector().swap(p->v_playouts_sum); vector< vector >().swap(p->vv_move_visit); std::vector().swap(p->v_score_x10k); } -const int ZERO_DB_SIZE = 1000000; //500000; // 100000, 500000 +//const int ZERO_DB_SIZE = 500000; // 100000, 500000 +const int ZERO_DB_SIZE = 1000000; // 100000, 500000 const int MAX_ZERO_MOVES = 513; // 512���ܤ��꤬�ؤ��Ƶͤ�Ǥʤ���С�513���ܤ���꤬�ؤ���̵���ǰ���ʬ���� ZERO_DB zdb_one; ZERO_DB zdb[ZERO_DB_SIZE]; int *pZDBsum = NULL; +unsigned char *pZDBmove; +unsigned char *pZDBmaxmove; +unsigned short *pZDBplayouts_sum; +unsigned short *pZDBscore_x10k; +const int ZDB_POS_MAX = ZERO_DB_SIZE * 256; // 128 = average moves. + int zdb_count = 0; -int zdb_count_start = 48000000; //38700000; //33900000;//27300000; //26100000; //23400000; //20300000; //18800000; //16400000; //10300000; //5200000; // 400�����褫���ɤ߹������4000000 +int zdb_count_start = 51420000;//51370000;//1000000;//48300000;//18000000;// 10000000;//11600000; //10300000; //9500000;//8500000; //7400000; //5220000; //3200000; //2100000; //390000;//130000;//460000;//29700000; //18200000;//23400000; //20300000; //18800000; //16400000; //10300000; //5200000; // 400�����褫���ɤ߹������4000000 int zero_kif_pos_num = 0; int zero_kif_games = 0; const int MINI_BATCH = 128; // aoba_zero.prototxt �� cross_entroy_scale ��Ʊ�����ѹ����뤳�ȡ�layer��name�����ѹ� @@ -2448,7 +2736,11 @@ int zero_kif_games = 0; void init_zero_kif_db() { if ( pZDBsum == NULL ) pZDBsum = (int*)malloc( ZERO_DB_SIZE * sizeof(int) ); - if ( pZDBsum == NULL ) { PRT("Fail malloc\n"); debug(); } + if ( pZDBsum == NULL ) { DEBUG_PRT("Fail malloc\n"); } + pZDBmove = (unsigned char*) malloc( ZDB_POS_MAX * sizeof(char) ); + pZDBmaxmove = (unsigned char*) malloc( ZDB_POS_MAX * sizeof(char) ); + pZDBplayouts_sum = (unsigned short*)malloc( ZDB_POS_MAX * sizeof(short) ); + pZDBscore_x10k = (unsigned short*)malloc( ZDB_POS_MAX * sizeof(short) ); memset(pZDBsum,0,ZERO_DB_SIZE * sizeof(int)); int i; @@ -2468,7 +2760,7 @@ const int USE_XZ_NONE = 0; const int USE_XZ_POOL_ONLY = 1; const int USE_XZ_BOTH = 2; -const int USE_XZ = USE_XZ_POOL_ONLY; // 1...pool�Τ� xz �ǡ�2...pool��archive�� xz �� +const int USE_XZ = USE_XZ_BOTH; // 1...pool�Τ� xz �ǡ�2...pool��archive�� xz �� // archive��������ֹ�=n �δ������Ф���KifBuf[] �����롣®��̵�롣fp�Ǥ�100���ܰʹߤ��٤�����̵���� int find_kif_from_archive(int search_n) @@ -2478,7 +2770,13 @@ int find_kif_from_archive(int search_n) // char dir_arch[] = "/home/aobaz/kifu/archive/"; // char dir_arch[] = "/home/yss/tcp_backup/archive20190304/unpack/"; // char dir_arch[] = "/home/yss/tcp_backup/archive20190325/unpack/"; - char dir_arch[] = "/home/yss/tcp_backup/archive20190421/unpack/"; +// char dir_arch[] = "/home/yss/tcp_backup/archive20190421/unpack/"; +// char dir_arch[] = "/home/yss/tcp_backup/archive20201207/"; +// char dir_arch[] = "/home/yss/prg/komaochi/archive/"; +// char dir_arch[] = "/home/yss/koma_syn/archive/"; +// char dir_arch[] = "/home/yss/tcp_backup/archive20201207/"; + char dir_arch[] = "/home/yss/tcp_backup/archive/"; + int arch_n = (search_n/10000) * 10000; // 20001 -> 20000 char filename[TMP_BUF_LEN]; @@ -2538,7 +2836,7 @@ int find_kif_from_archive(int search_n) strcpy(recent_arch_file, filename); recent_arch_size = size; if ( g != 10000 - 1 ) PRT("Err g=%d\n",g); - PRT("lines=%d,g=%d,%.3f\n",lines,g,get_spend_time(ct1)); // 100��36�á�1��0.36�� + PRT("lines=%d,g=%d,%.3f sec\n",lines,g,get_spend_time(ct1)); // 100��36�á�1��0.36�� // for (i=0;i<10;i++) PRT("%d:%d\n",i,recent_arch_table[i]); exit(0); } @@ -2568,9 +2866,9 @@ int find_kif_from_archive(int search_n) int find_kif_from_pool(int search_n) { -// char dir_pool[] = "pool"; -// char dir_pool[] = "/home/yss/tcp_backup/pool_unpack"; +// char dir_pool[] = "/home/yss/koma_syn/pool"; char dir_pool[] = "/home/yss/tcp_backup/pool"; + char filename[TMP_BUF_LEN]; if ( USE_XZ ) { sprintf(filename,"%s/no%012d.csa.xz",dir_pool,search_n); @@ -2634,14 +2932,6 @@ int get_guess_resign_moves(int moves) void shogi::add_one_kif_to_db() { -#if 1 // 40b�Υǡ�����Ȥ�ʤ� - if ( 39825686 <= zdb_count && zdb_count <= 47075521 ) { - static int count; - if ( (count++ % 10000)==0 ) PRT("skip 40b = %d\n",zdb_count); - zdb_count++; - return; - } -#endif ZERO_DB *pdb = &zdb[zdb_count % ZERO_DB_SIZE]; // �Ť��ΤϾ�� ZERO_DB *p = &zdb_one; free_zero_db_struct(pdb); @@ -2663,6 +2953,7 @@ void shogi::add_one_kif_to_db() pdb->moves = p->moves; pdb->result = p->result; pdb->result_type = p->result_type; + pdb->handicap = p->handicap; // copy(p->v_kif.begin(), p->v_kif.end(), back_inserter(pdb->v_kif)); // copy(p->v_playouts_sum.begin(), p->v_playouts_sum.end(), back_inserter(pdb->v_playouts_sum)); pdb->v_kif = p->v_kif; @@ -2684,70 +2975,281 @@ int is_exist_kif_file(int search_n) return 1; } +/* +�����Ĵ������ +���1000����ξ�Ψ��0.60��Ķ���Ƥ��顢Ĵ��(+70��Ⱦʬ��+35�����) +���2000����ξ�Ψ��0.58��Ķ���Ƥ��顢Ĵ�� +���4000����ξ�Ψ��0.56��Ķ���Ƥ��顢Ĵ�� +���8000����ξ�Ψ��̵���� ��Ĵ�� + +��¸����Τ� +�Ǹ��Ĵ�����������ֹ桢���ߤ�Ĵ���졼�� +�����Ф��Ϥ��Τϸ��ߤ�Ĵ���졼�ȡ�7����Τߡ� +*/ +int nHandicapLastID[HANDICAP_TYPE]; +int nHandicapRate[HANDICAP_TYPE]; +const char HANDICAP_ID_FILE[] = "handicap_rate.txt"; +//const char HANDICAP_SYN[] = "/home/yss/koma_syn/handicap/handicap.txt"; +const char HANDICAP_SYN[] = "/home/yss/tcp_backup/handicap/handicap.txt"; + +void load_handicap_rate() +{ + static bool bDone = false; + if ( bDone ) return; + bDone = true; + FILE *fp = fopen(HANDICAP_ID_FILE,"r"); + if ( fp==NULL ) DEBUG_PRT("fail open.\n"); + char str[TMP_BUF_LEN]; + if ( fgets( str, TMP_BUF_LEN, fp ) == NULL ) DEBUG_PRT(""); + int *p = nHandicapLastID; + int ret = sscanf(str,"%d %d %d %d %d %d %d",&p[0],&p[1],&p[2],&p[3],&p[4],&p[5],&p[6]); + if ( ret != HANDICAP_TYPE ) DEBUG_PRT("ret=%d\n",ret); + if ( fgets( str, TMP_BUF_LEN, fp ) == NULL ) DEBUG_PRT(""); + int *q = nHandicapRate; + ret = sscanf(str,"%d %d %d %d %d %d %d",&q[0],&q[1],&q[2],&q[3],&q[4],&q[5],&q[6]); + if ( ret != HANDICAP_TYPE ) DEBUG_PRT("ret=%d\n",ret); + fclose(fp); + int i; + PRT("nHandicapLastID="); + for (i=0;i0 ) strcat(str," "); + char buf[TMP_BUF_LEN]; + sprintf(buf,"%d",nHandicapLastID[i]); + strcat(str,buf); + } + strcat(str,"\n"); + fprintf(fp,"%s",str); + + str[0] = 0; + for (i=0;i0 ) strcat(str," "); + char buf[TMP_BUF_LEN]; + sprintf(buf,"%d",nHandicapRate[i]); + strcat(str,buf); + } + strcat(str,"\n"); + fprintf(fp,"%s",str); + fclose(fp); + + fp = fopen(HANDICAP_SYN,"w"); + if ( fp==NULL ) { + PRT("fail open %s\n",HANDICAP_SYN); + } else { + fprintf(fp,"%s",str); + fclose(fp); + } + + fp = fopen("handicap_history.txt","a"); + if ( fp==NULL ) DEBUG_PRT("fail open.\n"); + for (i=0;i0 ) fprintf(fp,","); + fprintf(fp,"%9d(%4d)",nHandicapLastID[i],nHandicapRate[i]); + } + fprintf(fp,"\n"); + fclose(fp); +} + +const char AVERAGE_WINRATE_SYN[] = "/home/yss/tcp_backup/handicap/average_winrate.txt"; + +void save_average_winrate(float ave_wr) { + if ( ave_wr <= 0 || ave_wr >= 1.0 ) DEBUG_PRT(""); + FILE *fp = fopen(AVERAGE_WINRATE_SYN,"w"); + if ( fp==NULL ) DEBUG_PRT("fail open.\n"); + fprintf(fp,"%d\n",(int)(ave_wr*1000.0)); + fclose(fp); + + fp = fopen("average_winrate_history.txt","a"); + if ( fp==NULL ) DEBUG_PRT("fail open.\n"); + fprintf(fp,"%9d(%.3f)\n",zdb_count,ave_wr); + fclose(fp); +} + +void count_recent_handicap_result(int h, int width, int result[]) +{ + result[0] = result[1] = result[2] = 0; + int w = width * HANDICAP_TYPE; + int loop = zdb_count; + if ( loop > ZERO_DB_SIZE ) loop = ZERO_DB_SIZE; + for (int i=0;ihandicap ) continue; + if ( p->index > zdb_count - w ) { + result[p->result]++; + } + } +} + void update_pZDBsum() { - int res_total_sum[4] = { 0,0,0,0 }; - int res_recent_sum[4] = { 0,0,0,0 }; - uint64 moves_total_sum = 0; - int moves_recent_sum = 0; - uint64 mv_total_sum = 0; - int mv_recent_sum = 0; - int mv_total_inc = 0; - int mv_recent_inc = 0; - int res_kind[4] = { 0,0,0,0 }; - int res_type[7] = { 0,0,0,0,0,0,0 }; - + const int H = HANDICAP_TYPE; + int res_total_sum[H][4] = { 0 }; // [3] �Ϲ�פ����� + int res_recent_sum[H][4] = { 0 }; + uint64 moves_total_sum[H] = { 0 }; + int moves_recent_sum[H] = { 0 }; + uint64 mv_total_sum[H] = { 0 }; + int mv_recent_sum[H] = { 0 }; + int mv_total_inc[H] = { 0 }; + int mv_recent_inc[H] = { 0 }; + int res_kind[H][4] = { 0 }; + int res_type[H][RT_MAX] = { 0 }; + int kachi[H][4] = { 0 }; + int result_hadicap_sum[H][3] = { 0 }; + int games_sum[H] = {0}; + const int G1000 = 1000*H; + const int WR_OK_GAMES = 8000; // ľ��Τ����жɿ��ξ�Ψ�ǥ졼�Ȥ���ư + + load_handicap_rate(); + const int MAX_GAMES = (WR_OK_GAMES*12/10)*H; + int i; + for (i=0;i MAX_GAMES ) nHandicapLastID[i] = zdb_count - MAX_GAMES; + } + zero_kif_pos_num = 0; zero_kif_games = 0; - int i; int loop = zdb_count; if ( loop > ZERO_DB_SIZE ) loop = ZERO_DB_SIZE; for (i=0;ihandicap; + if ( h < 0 || h >= H ) DEBUG_PRT(""); if ( p->result_type < 0 || p->result_type >= RT_MAX ) DEBUG_PRT(""); + if ( p->moves == 0 ) { PRT("Err. p->moves=0\n"); exit(0); } + if ( p->result < 0 || p->result > 2 ) DEBUG_PRT(""); + + if ( zero_kif_pos_num + p->moves >= ZDB_POS_MAX ) DEBUG_PRT("ZDB_POS_MAX!"); + for (int j=0;jmoves;j++) { + int n = zero_kif_pos_num + j; + int m0 = j; + if ( m0 > 255 ) m0 = 255; + int m1 = p->moves; + if ( m1 > 255 ) m1 = 255; + pZDBmove[n] = m0; + pZDBmaxmove[n] = m1; + pZDBplayouts_sum[n] = p->v_playouts_sum[j]; + pZDBscore_x10k[n] = p->v_score_x10k[j]; + } + zero_kif_pos_num += p->moves; pZDBsum[i] = zero_kif_pos_num; zero_kif_games += (p->moves != 0); - if ( p->moves == 0 ) { PRT("Err. p->moves=0\n"); exit(0); } - if ( p->result < 0 || p->result >=4 ) DEBUG_PRT(""); - if ( p->index >= zdb_count - 1000) { - res_recent_sum[p->result]++; - moves_recent_sum += p->moves; + + if ( p->index >= zdb_count - G1000) { + res_recent_sum[h][p->result]++; + moves_recent_sum[h] += p->moves; + } + if ( p->index > nHandicapLastID[h] ) { + result_hadicap_sum[h][p->result]++; } - res_total_sum[p->result]++; - moves_total_sum += p->moves; - if ( p->index >= zdb_count - 10000) { + games_sum[h]++; + res_total_sum[h][p->result]++; + moves_total_sum[h] += p->moves; + + if ( p->index >= zdb_count - G1000) { if ( p->result_type == RT_KACHI ) { - res_kind[p->result]++; - res_kind[3]++; + res_kind[h][p->result]++; + res_kind[h][3]++; } - res_type[p->result_type]++; + res_type[h][p->result_type]++; } - + if ( p->result_type == RT_KACHI ) { + kachi[h][p->result]++; + } + int j; for (j=0;jmoves;j++) { int n = p->vv_move_visit[j].size(); - if ( p->index >= zdb_count - 1000) { - mv_recent_sum += n; - mv_recent_inc++; + if ( p->index >= zdb_count - G1000) { + mv_recent_sum[h] += n; + mv_recent_inc[h]++; } - mv_total_sum += n; - mv_total_inc++; + mv_total_sum[h] += n; + mv_total_inc[h]++; } } - if ( loop > 0 ) { - if ( mv_recent_inc == 0 ) mv_recent_inc = 1; - if ( mv_total_inc == 0 ) mv_total_inc = 1; + if ( loop > 0 ) for (i=0;i 0.60 || wr < 0.40) ) fOK = true; + if ( k==1 && (wr > 0.58 || wr < 0.42) ) fOK = true; + if ( k==2 && (wr > 0.56 || wr < 0.44) ) fOK = true; + if ( k==3 ) fOK = true; + if ( fOK ) break; + } + + if ( wr <= 0.01 ) wr = 0.01; + if ( wr >= 0.99 ) wr = 0.99; + double d = -400.0 * log10(1.0 / wr - 1.0); + int d2 = (int)(d / 2.0f); // Ⱦʬ���ͤ�ư���� + +// PRT("%d:%.0f,%.3f(%d),",i,sum,wr,d2); if ( i==H-1 ) PRT("\n"); + if ( fOK == false ) continue; + + int prev = nHandicapRate[i]; + nHandicapRate[i] += d2; + const int RMAX = 1400+1157 - 100; + if ( nHandicapRate[i] < 0 ) nHandicapRate[i] = 0; + if ( nHandicapRate[i] > RMAX ) nHandicapRate[i] = RMAX; + hand_diff[i] = nHandicapRate[i] - prev; + if ( hand_diff[i] ) { + fUpdate = true; + nHandicapLastID[i] = zdb_count; + } + } +// if ( fUpdate ) save_handicap_rate(); + + float ave_winrate = (float)(res_total_sum[0][1] + res_total_sum[0][0]/2.0)/(res_total_sum[0][0]+res_total_sum[0][1]+res_total_sum[0][2]); + save_average_winrate(ave_winrate); + +// PRT("H:"); for (i=0;i= HANDICAP_TYPE ) DEBUG_PRT(""); + INIT_BOARD_DATA *p = &init_board_data[handicap]; - tume_hyouka = cp_tume_hyouka; - hash_code1 = cp_hash_code1; - hash_code2 = cp_hash_code2; - hash_motigoma = cp_hash_motigoma; + if ( fCopy ) { + memcpy(p->cp_init_ban, init_ban, sizeof(init_ban)); + memcpy(p->cp_mo_m, mo_m, sizeof(mo_m)); + memcpy(p->cp_mo_c, mo_c, sizeof(mo_c)); + memcpy(p->cp_ban, ban, sizeof(ban)); + memcpy(p->cp_kn, kn, sizeof(kn)); + memcpy(p->cp_kn_stoc, kn_stoc, sizeof(kn_stoc)); + memcpy(p->cp_kn_stn, kn_stn, sizeof(kn_stn)); + memcpy(p->cp_nifu_table_com, nifu_table_com, sizeof(nifu_table_com)); + memcpy(p->cp_nifu_table_man, nifu_table_man, sizeof(nifu_table_man)); + + p->cp_tume_hyouka = tume_hyouka; + p->cp_hash_code1 = hash_code1; + p->cp_hash_code2 = hash_code2; + p->cp_hash_motigoma = hash_motigoma; + } else { // restore + memcpy(init_ban, p->cp_init_ban, sizeof(init_ban)); + memcpy(mo_m, p->cp_mo_m, sizeof(mo_m)); + memcpy(mo_c, p->cp_mo_c, sizeof(mo_c)); + memcpy(ban, p->cp_ban, sizeof(ban)); + memcpy(kn, p->cp_kn, sizeof(kn)); + memcpy(kn_stoc, p->cp_kn_stoc, sizeof(kn_stoc)); + memcpy(kn_stn, p->cp_kn_stn, sizeof(kn_stn)); + memcpy(nifu_table_com, p->cp_nifu_table_com, sizeof(nifu_table_com)); + memcpy(nifu_table_man, p->cp_nifu_table_man, sizeof(nifu_table_man)); + + tume_hyouka = p->cp_tume_hyouka; + hash_code1 = p->cp_hash_code1; + hash_code2 = p->cp_hash_code2; + hash_motigoma = p->cp_hash_motigoma; } } void shogi::init_prepare_kif_db() { // fSelectZeroDB = 1; - if ( fMAKE_LEVELDB ) { PRT("fMAKE_LEVELDB=1 ! Err\n"); debug(); } + if ( fMAKE_LEVELDB ) { DEBUG_PRT("fMAKE_LEVELDB=1 ! Err\n"); } init_rnd521( (int)time(NULL)+getpid_YSS() ); // ��ư���Ȥ˰ۤʤ����������� init_zero_kif_db(); load_exist_all_kif(); - hirate_ban_init(0); - copy_restore_dccn_init_board(1); + for (int i=0; i r ) return min; if ( pZDBsum[mid] > r ) return mid; return max; @@ -3074,16 +3585,39 @@ void rand_check_test() // loop= 58850000,dsum=0.999956,sqrt()=0.999978 } */ +#ifdef F2187 +void shogi::prepare_kif_db(int fPW, int mini_batch, float *data, float *label_policy, float *label_value, float label_policy_visit[][MOVE_2187_MAX]) +#else void shogi::prepare_kif_db(int fPW, int mini_batch, float *data, float *label_policy, float *label_value, float label_policy_visit[][MOVE_C_Y_X_ID_MAX]) +#endif { // int ct1 = get_clock(); -// float *data = new float[DCNN_CHANNELS*B_SIZE*B_SIZE]; + int sum_handicap[HANDICAP_TYPE] = { 0 }; + int sum_result[3] = { 0 }; + int sum_turn[2] = { 0 }; + double sum_t = 0; + double sum_diff_win_r = 0; // pos_sum ���椫��64�ĥ���������� int *ri = new int[mini_batch]; int i; for (i=0;i (n*9+30) ) { i--; continue; } + } + if ( 1 ) { + int s = pZDBplayouts_sum[r]; + int x = pZDBscore_x10k[r]; + if ( s < 50 && (x==0 || x==10000) ) { i--; continue; } + } + int j; for (j=0;jmoves; if ( sum > r ) { t = r - (sum - p->moves); - if ( t >= p->moves || t < 0 ) { PRT("t over %d err.i=%d,j=%d,r=%d,sum=%d\n",t,i,j,r,sum); debug(); } + if ( t >= p->moves || t < 0 ) { DEBUG_PRT("t over %d err.i=%d,j=%d,r=%d,sum=%d\n",t,i,j,r,sum); } break; } } int bi = binary_search_kif_db(r); // 16�ä�1�ä� ZERO_DB *p = &zdb[bi]; t = r - (pZDBsum[bi] - zdb[bi].moves); - if ( t < 0 || t >= MAX_ZERO_MOVES ) { PRT("t=%d(%d) err.j=%d,r=%d\n",t,p->moves,j,r); debug(); } + if ( t < 0 || t >= MAX_ZERO_MOVES ) { DEBUG_PRT("t=%d(%d) err.j=%d,r=%d,bi=%d\n",t,p->moves,j,r,bi); } // PRT("%3d:%7d,j=%4d:bi=%3d,t=%3d,moves=%3d,res=%d\n",i,r,j,bi,t,p->moves,p->result); // if ( bi != j ) debug(); // if ( r - (pZDBsum[bi] - pZDB[bi].moves) != t ) debug(); // mb_count[bi]++; - copy_restore_dccn_init_board(0); + copy_restore_dccn_init_board(p->handicap, false); + + int fSymmetry = rand_m521() % 2; // ����Ǻ���ȿž + fSymmetry = 0; // ����ȿž�ʤ� for (j=0;jkif[j*2+0], p->kif[j*2+1], j, &bz, &az, &tk, &nf); - trans_4_to_2_KDB( p->v_kif[j]>>8, p->v_kif[j]&0xff, j, &bz, &az, &tk, &nf); + trans_4_to_2_KDB( p->v_kif[j]>>8, p->v_kif[j]&0xff, (j+(p->handicap!=0))&1, &bz, &az, &tk, &nf); move_hit_hash(bz,az,tk,nf); move_hit_kif[j] = pack_te( bz,az,tk,nf ); @@ -3128,11 +3664,16 @@ void shogi::prepare_kif_db(int fPW, int mini_batch, float *data, float *label_po move_hit_hashcode[j][1] = hash_code2; move_hit_hashcode[j][2] = hash_motigoma; } - - if ( j >= p->moves ) { PRT("no next move? t=%d(%d) err.j=%d,r=%d\n",t,p->moves,j,r); debug(); } + if ( j >= p->moves || j!=t ) { DEBUG_PRT("no next move? t=%d(%d) err.j=%d,r=%d\n",t,p->moves,j,r); } + if ( 1 ) { + int s = p->v_playouts_sum[t]; + int x = p->v_score_x10k[t]; + if ( s < 50 && (x==0 || x==10000) ) DEBUG_PRT("r=%8d,t=%3d,s=%5d,x=%d\n",r,t,s,x); + } + int bz,az,tk,nf; -// trans_4_to_2_KDB( p->kif[j*2+0], p->kif[j*2+1], j, &bz, &az, &tk, &nf); - trans_4_to_2_KDB( p->v_kif[j]>>8, p->v_kif[j]&0xff, j, &bz, &az, &tk, &nf); + bool bGoteTurn = (t+(p->handicap!=0)) & 1; + trans_4_to_2_KDB( p->v_kif[j]>>8, p->v_kif[j]&0xff, bGoteTurn, &bz, &az, &tk, &nf); int win_r = 0; if ( p->result == ZD_S_WIN ) win_r = +1; @@ -3143,24 +3684,40 @@ void shogi::prepare_kif_db(int fPW, int mini_batch, float *data, float *label_po float score_div = (float)score_x10k / 10000.0f; float score = score_div * 2.0f - 1.0f; // +1.0 >= x >= -1.0, ��ʬ���鸫����Ψ - if ( (t&1)==1 ) { + if ( bGoteTurn ) { hanten_sasite(&bz,&az,&tk,&nf); // �ؤ�������ȿž win_r = -win_r; // ���Ԥޤ�ȿž�Ϥ��ʤ��Ƥ褤�� ȿž���������ؽ�����ñ�ʤϤ����ФƤ�����̤�ȿž } + if ( fSymmetry ) { + hanten_sasite_sayuu(&bz,&az,&tk,&nf); + } + // �ºݤξ��Ԥ�õ���ͤ�ʿ�Ѥ�ؽ���https://tadaoyamaoka.hatenablog.com/entry/2018/07/01/121411 float ave_r = ((float)win_r + score) / 2.0; if ( score_x10k == NO_ROOT_SCORE ) ave_r = win_r; -// ave_r = win_r; // not use average + ave_r = win_r; // not use average // PRT("(%.3f,%.3f)",(float)win_r,score); - int playmove_id = get_move_id_c_y_x(pack_te(bz,az,tk,nf)); + int playmove_id = 0; + if ( f2187 ) { + playmove_id = get_dlshogi_policy(bz,az,tk,nf); + } else { + playmove_id = get_move_id_c_y_x(pack_te(bz,az,tk,nf)); + } label_policy[i] = (float)playmove_id; label_value[i] = (float)ave_r; if ( POLICY_VISIT ) { int k; - for (k=0; kv_playouts_sum[j]; @@ -3174,33 +3731,56 @@ void shogi::prepare_kif_db(int fPW, int mini_batch, float *data, float *label_po int b1 =(x>>16)&0xff; int visit = x&0xffff; int bz,az,tk,nf; - trans_4_to_2_KDB( b0, b1, j, &bz, &az, &tk, &nf); - if ( (t&1)==1 ) hanten_sasite(&bz,&az,&tk,&nf); // �ؤ�������ȿž + trans_4_to_2_KDB( b0, b1, bGoteTurn, &bz, &az, &tk, &nf); + if ( bGoteTurn ) hanten_sasite(&bz,&az,&tk,&nf); // �ؤ�������ȿž // PRT("r=%5d:b0=%3d,b1=%3d,[%3d][%3d] (%02x,%02x,%02x,%02x)v=%3d\n",r,b0,b1,j,k,bz,az,tk,nf,visit); + if ( fSymmetry ) { + hanten_sasite_sayuu(&bz,&az,&tk,&nf); + } +#ifdef F2187 + int id = get_dlshogi_policy(bz,az,tk,nf); +#else int id = get_move_id_c_y_x(pack_te(bz,az,tk,nf)); +#endif label_policy_visit[i][id] = (float)visit / playout_sum; // PRT("r=%5d:b0=%3d,b1=%3d,[%3d][%3d] (%02x,%02x,%02x,%02x)id=%5d,v=%3d,%6.4f\n",r,b0,b1,j,k,bz,az,tk,nf,id,visit,label_policy_visit[i][id]); if ( id==playmove_id ) found = 1; } - if ( found==0 ) PRT("no best move visit. id=%d\n",playmove_id); + if ( found==0 ) { static int count=0; if ( count++==0 ) PRT("no best move visit. id=%d\n",playmove_id); } } float *pd = (float *)data + ONE_SIZE * i; memset(pd, 0, sizeof(float)*ONE_SIZE); // PRT("%2d:t=%d,win_r=%d,policy=%.0f\n",i,t,win_r,label_policy[i]); hyouji(); - set_dcnn_channels((Color)(t&1), t, pd, -1, NET_362); + set_dcnn_channels((Color)bGoteTurn, t, pd, -1, p->handicap); // prt_dcnn_data_table((float(*)[B_SIZE][B_SIZE])pd); + if ( fSymmetry ) { + symmetry_dcnn_channels(pd); + } + + sum_handicap[p->handicap]++; + sum_result[p->result]++; + sum_turn[bGoteTurn]++; + sum_t +=t; + sum_diff_win_r +=fabs(win_r - ave_r); if ( fPW ) PRT("%3d ",p->weight_n); // if ( fPW ) PRT("%d(%3d) ",bi,p->weight_n); + static int tc[MAX_ZERO_MOVES],tc_all; + int tt = t; + if ( tt>199 ) tt=199; + tc[tt]++; + tc_all++; +// if ( (tc_all % 1000000)==0 ) { PRT("tc="); for (int k=0;k<200;k++) PRT("%f,",(float)tc[k]/tc_all); PRT("\n"); } } - if ( fPW ) PRT("\n"); + if ( fPW ) PRT("\nhandicap=%d,%d,%d,%d,%d,%d,%d,result=%d,%d,%d,turn=%d,%d,ave_t=%.2f,ave_diff_win_r=%.5f\n" + ,sum_handicap[0],sum_handicap[1],sum_handicap[2],sum_handicap[3],sum_handicap[4],sum_handicap[5],sum_handicap[6] + ,sum_result[0],sum_result[1],sum_result[2], sum_turn[0],sum_turn[1], sum_t/mini_batch, sum_diff_win_r/mini_batch ); // PRT("%.2f sec, mini_batch=%d,%8d,%8.1f,%6.3f\n",get_spend_time(ct1), mini_batch, ri[0], label_policy[0], label_value[0]); delete [] ri; } - void convert_caffemodel(int iteration, int weight_number) { print_time(); @@ -3330,7 +3910,7 @@ int load_network(std::string filename) linecount++; } PRT("num=%d...linecount=%d\n",num,linecount); - if ( num != WT_NUM ) debug(); + if ( num != WT_NUM ) DEBUG_PRT(""); // for (int i=0; i<100; i++) PRT("%f,",wt_keep[i]); return num; @@ -3360,8 +3940,13 @@ const int ITER_SIZE = 1; constexpr auto kDataSize = MINI_BATCH * ITER_SIZE; // ITER_SIZE=1 �� 7MB +#ifdef F2187 +float policy_visit[kDataSize][MOVE_2187_MAX]; +array dummy_policy_visit; +#else float policy_visit[kDataSize][MOVE_C_Y_X_ID_MAX]; array dummy_policy_visit; +#endif string get_short_float(float f) { @@ -3422,7 +4007,7 @@ void load_aoba_txt_weight( const caffe::shared_ptr> &net, std: PRT(", %d\n",sum_layer); } PRT("sum=%d,param_num=%d,set_num=%d\n",sum,param_num,set_num); - if ( sum != set_num || sum != param_num ) { PRT("weight param Err.\n"); debug(); } + if ( sum != set_num || sum != param_num ) { DEBUG_PRT("weight param Err.\n"); } } void start_zero_train(int *p_argc, char ***p_argv ) @@ -3431,7 +4016,6 @@ void start_zero_train(int *p_argc, char ***p_argv ) GlobalInit(p_argc, p_argv); PS->init_prepare_kif_db(); - //exit(0); if ( fWwwSample ) { PS->make_www_samples(); return; } @@ -3460,16 +4044,6 @@ void start_zero_train(int *p_argc, char ***p_argv ) std::shared_ptr> solver; solver.reset(SolverRegistry::CreateSolver(solver_param)); -/* - solver_param.set_base_lr(0.01); - solver_param.set_display(100); - solver_param.set_max_iter(10000000); - solver_param.set_lr_policy("step"); - solver_param.set_gamma(0.5); - solver_param.set_power(0.75); - solver_param.set_momentum(0.9); - solver_param.set_weight_decay(0.0002); -*/ //ɾ���ѤΥǡ�������� const auto net = solver->net(); // const char sNet[] = "20190419replay_lr001_wd00002_100000_1018000/_iter_36000.caffemodel"; // w449 @@ -3496,10 +4070,11 @@ void start_zero_train(int *p_argc, char ***p_argv ) // const char sNet[] = "/home/yss/shogi/learn/snapshots/20210311/_iter_4832000.caffemodel"; // w3298 // const char sNet[] = "/home/yss/shogi/learn/40b_8x_39770000_games_iter_3870190.caffemodel"; // 40b, next = w3460 // const char sNet[] = "/home/yss/shogi/learn/snapshots/20210426/_iter_5152000.caffemodel"; // w3459 = w3703 - const char sNet[] = "/home/yss/shogi/learn/snapshots/20211225/_iter_2112000.caffemodel"; // w3769 - +// const char sNet[] = "/home/yss/shogi/learn/snapshots/20211225/_iter_2112000.caffemodel"; // w3769 +// const char sNet[] = "/home/yss/shogi/learn/20220222_125600_256x20b_swish_no_ave_no_30_from_20220218_071436_iter_600000.caffemodel"; + const char sNet[] = "/home/yss/shogi/learn/snapshots/20220226/_iter_64000.caffemodel"; // w3883 - int next_weight_number = 3770; // ���ߤκǿ����ֹ� +1 + int next_weight_number = 3884; // ���ߤκǿ����ֹ� +1 net->CopyTrainedLayersFrom(sNet); // caffemodel���ɤ߹���dzؽ���Ƴ������� // load_aoba_txt_weight( net, "/home/yss/w000000000689.txt" ); // ��¸��w*.txt���ɤ߹��ࡣ*.caffemodel�򲿤��ɤ߹������� @@ -3508,37 +4083,31 @@ void start_zero_train(int *p_argc, char ***p_argv ) int iteration = 0; // �ؽ���� int add = 0; // �ɲä��줿����� -// int remainder = 0; + int remainder = 0; int iter_weight = 0; - float remain = 0; - + wait_again: if ( fReplayLearning ) { add = PS->add_a_little_from_archive(); if ( add < 0 ) { PRT("done..\n"); solver->Snapshot(); return; } -// if ( zdb_count <= 120000 ) goto wait_again; // no000000121031.csa �ޤǤ�random ����ʤΤ� -// if ( zdb_count <= 2520000 ) goto wait_again; -// if ( zdb_count > 2948000 ) { PRT("done..w648.\n"); solver->Snapshot(); return; } + if ( zdb_count <= ZERO_DB_SIZE ) goto wait_again; +// if ( zdb_count <= 18850000 ) goto wait_again; +// if ( zdb_count > 13000000 ) { PRT("done...\n"); solver->Snapshot(); return; } +// if ( iteration >= 100000*1 ) { PRT("done...\n"); solver->Snapshot(); return; } +// if ( iteration > 1000 ) solver_param.set_base_lr(0.01); + } else { - if ( 1 && iteration==0 && next_weight_number==3770 ) { - add = 800; // ���Τߥ��ߡ���2000�����ɲä������Ȥˤ���(����Ƴ��� 0 && ��) + if ( 1 && iteration==0 && next_weight_number==3884 ) { + add = 200; // ���Τߥ��ߡ���10000�����ɲä������Ȥˤ��� } else { add = PS->wait_and_get_new_kif(next_weight_number); } } - // AlphaZero��2400�����衢70����ؽ���mini-batch=4096��1000��ؽ����Ȥ˽Ť߹������ʤΤ�34285����(=2400/(700000/1000)) - // mini-batch=128 ����32000��ؽ�((4096/128)*1000)���Ȥ˽Ť߹������ʤΤ�34285�����32000��ؽ���1�����1.0714��ؽ��� const float ADJUST = 1.07142857; const int AVE_MOVES = 128; // 1�ɤ�ʿ�Ѽ�� float add_mul = ADJUST * (float)AVE_MOVES / MINI_BATCH; int nLoop = (int)((float)add*add_mul); // MB=64��add*2, MB=128��add*1, MB=180��add*0.711 - remain += add*add_mul - nLoop; - if ( remain > 1 ) { - nLoop += 1; - remain -= 1; - } -/* // (ITER_SIZE*MINI_BATCH)=4096 �ʤ����Ǥ�32����ɬ��(32*128=4096) int min_n = ITER_SIZE*MINI_BATCH / AVE_MOVES; if ( min_n > 1 ) { @@ -3546,9 +4115,8 @@ void start_zero_train(int *p_argc, char ***p_argv ) nLoop = add / min_n; remainder = add - nLoop * min_n; } -*/ -// const int ITER_WEIGHT_BASE = 10000*AVE_MOVES / (ITER_SIZE*MINI_BATCH); // 10000����(ʿ��128��)���Ȥ�weight����� - const int ITER_WEIGHT_BASE = 32000*AVE_MOVES / (ITER_SIZE*MINI_BATCH); // 32000�� ���Ȥ�weight����� + + const int ITER_WEIGHT_BASE = 32000*AVE_MOVES / (ITER_SIZE*MINI_BATCH); // 10000����(ʿ��128��)���Ȥ�weight����� int iter_weight_limit = ITER_WEIGHT_BASE; float reduce = 1.0; // weight��10000���褴�Ȥdzؽ������10000����8000�ʤɤ˸��餹����������®�٤�®�����뤿�� FILE *fp = fopen("reduce.txt","r"); @@ -3566,7 +4134,9 @@ void start_zero_train(int *p_argc, char ***p_argv ) fclose(fp); } - PRT("nLoop=%d,add=%d,add_mul=%.3f,MINI_BATCH=%d,kDataSize=%d,remain=%.3f,iteration=%d(%d/%d)\n",nLoop,add,add_mul,MINI_BATCH,kDataSize,remain,iteration,iter_weight,iter_weight_limit); +//nLoop /= 2; + + PRT("nLoop=%d,add=%d,add_mul=%.3f,MINI_BATCH=%d,kDataSize=%d,remainder=%d,iteration=%d(%d/%d)\n",nLoop,add,add_mul,MINI_BATCH,kDataSize,remainder,iteration,iter_weight,iter_weight_limit); int loop; for (loop=0;loop input_data; // �礭���Τ�static�� @@ -3604,7 +4174,7 @@ void start_zero_train(int *p_argc, char ***p_argv ) // solver->Snapshot(); // prototxt ���������¸����� iteration++; iter_weight++; - + if ( fReplayLearning==0 && iter_weight >= iter_weight_limit ) { iter_weight = 0; solver->Snapshot(); diff --git a/learn/yss_dcnn.h b/learn/yss_dcnn.h index dd592de..4a86b71 100644 --- a/learn/yss_dcnn.h +++ b/learn/yss_dcnn.h @@ -49,6 +49,7 @@ typedef struct ZERO_DB { int result; // ��̡���꾡������꾡��������ʬ�� int result_type;// ��λ�������ꡢ����(513��)�����������Ϣ³����β�ƨ���ˤ��ȿ§���� int moves; // ���(����Υ�������Ʊ��) + int handicap; // ����� vector v_kif; // ���� vector v_playouts_sum; // Root��õ�������̾��800���� vector < vector > vv_move_visit; // (��+������)�Υڥ� @@ -63,7 +64,6 @@ enum { RT_NONE, RT_TORYO, RT_KACHI, RT_SENNICHITE, RT_G_ILLEGAL_ACTION, RT_S_ILL const unsigned short NO_ROOT_SCORE = 10001; - void free_zero_db_struct(ZERO_DB *p); void start_zero_train(int *, char ***); diff --git a/learn/yss_ki2.cpp b/learn/yss_ki2.cpp index 67ab2dd..555fc89 100644 --- a/learn/yss_ki2.cpp +++ b/learn/yss_ki2.cpp @@ -2534,3 +2534,6 @@ void shogi::allkesu() if ( ban[z] != 0 ) kikid(z); } } + +void shogi::kiki_write(int z) { kikiw(z); } +void shogi::kiki_delete(int z) { kikid(z); } diff --git a/learn/yss_misc.cpp b/learn/yss_misc.cpp index eb07927..5c108dd 100644 --- a/learn/yss_misc.cpp +++ b/learn/yss_misc.cpp @@ -44,7 +44,7 @@ void shogi::check_kn(void) PRT("check_kn(%x) Error !!! tesuu=%d fukasa=%d\n",i,tesuu,fukasa); PRT("ban[%x]=%02x, init_b[%x]=%x\n",z,ban[z],z,init_ban[z]); print_kb(); - debug(); + DEBUG_PRT(""); } } for (i=1;i<8;i++) { @@ -52,7 +52,7 @@ void shogi::check_kn(void) if ( mo_c[i]<0 || mo_m[i]<0 || k < 0 || (i==1 && k>18) || ( (i==2||i==3||i==4||i==5) && k>4 ) || ( (i==6||i==7) && k>2 ) ) { PRT("mo_ Error !\n"); - debug(); + DEBUG_PRT(""); } } } @@ -168,7 +168,7 @@ void shogi::hanten_sayuu(void) static int hirate_ban[BAN_SIZE]= { 0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0,0,0,0,0, - + 0xff, 0x82,0x83,0x84,0x85,0x88,0x85,0x84,0x83,0x82, 0xff,0,0,0,0,0, 0xff, 0x00,0x87,0x00,0x00,0x00,0x00,0x00,0x86,0x00, 0xff,0,0,0,0,0, 0xff, 0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81, 0xff,0,0,0,0,0, @@ -197,21 +197,50 @@ void shogi::hirate_ban_init(int n) init_ban[z] = hirate_ban[z]; } } - +/* // PRT("n=%d\n",n); if ( n == 7 ) init_ban[0x99] = 0; // �����ä� if ( n == 6 ) { init_ban[0x92] = 0; init_ban[0x98] = 0; } // ���Ϥ�ä� - if ( n >= 5 && n <= 6 ) { init_ban[0x91] = 0; init_ban[0x99] = 0; } // ��֤�ä� + if ( n >= 5 && n <= 6 ) { init_ban[0x91] = 0; init_ban[0x99] = 0; } // ��֤�ä� if ( n >= 4 && n <= 6 ) { init_ban[0x82] = 0; init_ban[0x88] = 0; } // ���Ѥ�ä� if ( n == 3 ) init_ban[0x88] = 0; // ���֤�ä� if ( n == 2 ) init_ban[0x82] = 0; // �ѡ���ä� if ( n == 1 ) init_ban[0x91] = 0; // �����ä� +*/ + if ( n == 6 ) { init_ban[0x12] = 0; init_ban[0x18] = 0; } // ���Ϥ�ä� + if ( n >= 5 && n <= 6 ) { init_ban[0x11] = 0; init_ban[0x19] = 0; } // ��֤�ä� + if ( n >= 4 && n <= 6 ) { init_ban[0x22] = 0; init_ban[0x28] = 0; } // ���Ѥ�ä� + if ( n == 3 ) init_ban[0x22] = 0; // ���֤�ä� + if ( n == 2 ) init_ban[0x28] = 0; // �ѡ���ä� + if ( n == 1 ) init_ban[0x19] = 0; // �����ä� init(); /** kn[] ni kakikomu **/ allkaku(); tesuu = all_tesuu = 0; } +int shogi::get_handicap_from_board() +{ + int m[256]; + int sum = 0, mo_sum = 0; + for (int i=1;i<8;i++) { + mo_sum += mo_m[i] + mo_c[i]; + } + if ( mo_sum ) return 0; + int x,y; + for (y=1;y<10;y++) for (x=1;x<10;x++) { + int z = y*16+x; + if ( init_ban[z] == hirate_ban[z] ) continue; + m[sum++] = z; + } + if ( sum==1 && m[0]==0x19 ) return 1; // ky + if ( sum==1 && m[0]==0x28 ) return 2; // ka + if ( sum==1 && m[0]==0x22 ) return 3; // hi + if ( sum==2 && m[0]==0x22 && m[1]==0x28 ) return 4; // 2mai + if ( sum==4 && m[0]==0x11 && m[1]==0x19 && m[2]==0x22 && m[3]==0x28 ) return 5; // 4mai + if ( sum==6 && m[0]==0x11 && m[1]==0x12 && m[2]==0x18 && m[3]==0x19 && m[4]==0x22 && m[5]==0x28 ) return 6; // 6mai + return 0; +} // ���ߤλ��������̤ξ���(ban_init)�򸵤����̾��֤�ƹ������롣 void shogi::ban_saikousei() @@ -266,6 +295,19 @@ void hanten_sasite( int *bz, int *az, int *tk, int *nf ) *nf = *nf; } +void hanten_sasite_sayuu( int *bz, int *az, int *tk, int *nf ) +{ + if ( *bz == 0 ) return; + + int y = *bz & 0xf0; + int x = *bz & 0x0f; + if ( *bz != 0xff ) *bz = y | (10 - x); + + y = *az & 0xf0; + x = *az & 0x0f; + *az = y | (10 - x); +} + int get_localtime(int *year, int *month, int *day, int *week, int *hour, int *minute, int *second) { time_t timer = time(NULL); /* ����μ��� */ @@ -288,13 +330,13 @@ int get_localtime(int *year, int *month, int *day, int *week, int *hour, int *mi int get_clock() { #if defined(_MSC_VER) - if ( CLOCKS_PER_SEC_MS != CLOCKS_PER_SEC ) { PRT("CLOCKS_PER_SEC=%d Err. not Windows OS?\n"); debug(); } + if ( CLOCKS_PER_SEC_MS != CLOCKS_PER_SEC ) { PRT("CLOCKS_PER_SEC=%d Err. not Windows OS?\n"); DEBUG_PRT(""); } return clock(); // return GetTickCount(); #else struct timeval val; struct timezone zone; - if ( gettimeofday( &val, &zone ) == -1 ) { PRT("time err\n"); debug(); } + if ( gettimeofday( &val, &zone ) == -1 ) { PRT("time err\n"); DEBUG_PRT(""); } // return tv.tv_sec + (double)tv.tv_usec*1e-6; return val.tv_sec*1000 + (val.tv_usec / 1000); #endif @@ -307,7 +349,7 @@ double get_spend_time(int ct1) // ����������2�Х��Ȥ�4�Х��Ȥ��Ѵ���num�ϸ��ߤμ����num=0����Ϥޤ롣 -void shogi::trans_4_to_2_KDB(int b0,int b1, int num, int *bz,int *az, int *tk, int *nf) +void shogi::trans_4_to_2_KDB(int b0,int b1, bool bGoteTurn, int *bz,int *az, int *tk, int *nf) { int k; // b0 = p->kifu[i][0]; // b0 = 11-99, 0x81-0x87 @@ -316,7 +358,7 @@ void shogi::trans_4_to_2_KDB(int b0,int b1, int num, int *bz,int *az, int *tk, i if ( b0 > 0x80 ) { // ���Ǥ� *tk = b0 - 0x80; - if ( (num & 1) ) *tk |= 0x80; // COM + if ( bGoteTurn ) *tk |= 0x80; // COM *bz = 0xff; } else { k = b0 / 10; @@ -378,29 +420,29 @@ void InitLockYSS() void shogi::hyouji() { int x,y,i; - PRT(" 1 2 3 4 5 6 7 8 9\n"); + PRT(" 1 2 3 4 5 6 7 8 9 \n"); for (y=0;y<9;y++) { - PRT("%d|",y+1); + PRT("%d��",y+1); for (x=0;x<9;x++) { int n = ban[ (y+1)*16+x+1 ]; int k = kn[n][0]; if (k>0x80) k-=0x70; // PRT("%s",koma[i]); PRT("%s",koma_kanji[k]); - } PRT("| "); + } PRT("��"); if (y==0) { - PRT(" GOTE :"); + PRT(" COM :"); // for (i=1;i<8;i++) PRT("%s %x:",koma[i+16],mo_c[i]); for (i=1;i<8;i++) PRT("%s %x:",koma_kanji[i+16],mo_c[i]); } if (y==8) { - PRT(" SENTE :"); + PRT(" MAN :"); // for (i=1;i<8;i++) PRT("%s %x:",koma[i],mo_m[i]); for (i=1;i<8;i++) PRT("%s %x:",koma_kanji[i],mo_m[i]); } PRT("\n"); } - PRT("- - - - - - - - - - - - - - - - - -\n"); + PRT("- - - - - - - - - - - - - - - - - - - - \n"); } void shogi::print_kakinoki_banmen(int (*func_prt)(const char *, ... ), char *sName0,char *sName1) @@ -1313,7 +1355,7 @@ const char *koma_kanji_str(int n) " ","��", "��", "��", "��","��","��","��", "��","��","����","����","����"," ","��","ζ" }; - if ( n < 0 || n >= 16 ) debug(); + if ( n < 0 || n >= 16 ) DEBUG_PRT(""); return koma_kanji2[n]; } @@ -1372,7 +1414,7 @@ void shogi::change_small(int bz,int az,int tk,int nf,char retp[]) sprintf(retp,"PASS "); return; } - if ( bz < 0 || bz > 0xff || az <= 0 || az > 0x99 || nf < 0 || nf > 0x08 || tk < 0 || tk > 0x8f ) { PRT("Err bz,az,tk,nf=%02x,%02x,%02x,%02x\n",bz,az,tk,nf); debug(); } + if ( bz < 0 || bz > 0xff || az <= 0 || az > 0x99 || nf < 0 || nf > 0x08 || tk < 0 || tk > 0x8f ) { DEBUG_PRT("Err bz,az,tk,nf=%02x,%02x,%02x,%02x\n",bz,az,tk,nf); } ay = az/16; ax = 10-(az-ay*16); @@ -1413,7 +1455,7 @@ void shogi::change_sg(int bz,int az,int tk,int nf,int depth, char retp[]) strcat(retp,"PASS"); return; } - if ( bz < 0 || bz > 0xff || az <= 0 || az > 0x99 || nf < 0 || nf > 0x08 || tk < 0 || tk > 0x8f ) { PRT("Err sg bz,az,tk,nf=%02x,%02x,%02x,%02x\n",bz,az,tk,nf); debug(); } + if ( bz < 0 || bz > 0xff || az <= 0 || az > 0x99 || nf < 0 || nf > 0x08 || tk < 0 || tk > 0x8f ) { DEBUG_PRT("Err sg bz,az,tk,nf=%02x,%02x,%02x,%02x\n",bz,az,tk,nf); } ay = az/16; ax = 10-(az-ay*16); diff --git a/learn/yss_prot.h b/learn/yss_prot.h index 62e195a..015f73f 100644 --- a/learn/yss_prot.h +++ b/learn/yss_prot.h @@ -37,6 +37,7 @@ void make_move_is_tobi_check_table(); /* YSS_HISI.C */ void hanten_sasite( int *bz, int *az, int *tk, int *nf ); +void hanten_sasite_sayuu( int *bz, int *az, int *tk, int *nf ); diff --git a/src/autousi/play.cpp b/src/autousi/play.cpp index 4a1e9b3..8be68d8 100644 --- a/src/autousi/play.cpp +++ b/src/autousi/play.cpp @@ -253,7 +253,8 @@ class USIEngine : public Child { argv[argc++] = opt_p_value; char opt_kld[] = "-kldgain"; - char opt_kld_value[] = "0.0000013"; +// char opt_kld_value[] = "0.0000013"; + char opt_kld_value[] = "0.000006"; argv[argc++] = opt_kld; argv[argc++] = opt_kld_value; #endif @@ -473,8 +474,8 @@ class USIEngine : public Child { || value == HUGE_VALF) die(ERR_INT("cannot interpret value %s (engine %s)", str_value+2, get_fp())); -// if (value < th_resign) flag_resign = true; - if (value < th_resign && _nmove > 30) flag_resign = true; + if (value < th_resign) flag_resign = true; +// if (value < th_resign && _nmove > 30) flag_resign = true; const char *str_count = OSI::strtok(nullptr, " ,", &saveptr); if (!str_count) die(ERR_INT("cannot read count (engine %s)", get_fp())); diff --git a/src/playshogi/playshogi.cpp b/src/playshogi/playshogi.cpp index b5b34f5..11c2e4c 100644 --- a/src/playshogi/playshogi.cpp +++ b/src/playshogi/playshogi.cpp @@ -410,7 +410,8 @@ static void procedure_io(USIEngine &myself, USIEngine &opponent, static void node_update(USIEngine &myself, USIEngine &opponent, Node &node, string &startpos, string &record, char *line) noexcept { - assert(myself.ok() && opponent.ok() && node.ok() && line); + assert(myself.ok() && opponent.ok() && node.ok() && line); + bool has_visit = (strstr(line,"v=") != NULL); char *token = strtok(line, " "); if (token == nullptr) return; if (strcmp(token, "bestmove")) return; @@ -431,9 +432,9 @@ static void node_update(USIEngine &myself, USIEngine &opponent, } record += node.get_turn().to_str(); record += action.to_str(SAux::csa); - } + } - if ( action.is_move() && go_visit ) { + if ( action.is_move() && go_visit && has_visit ) { string new_info; const char *str_value = strtok(nullptr, " ,"); if (!str_value || str_value[0] != 'v' || str_value[1] != '=') die(ERR_INT("cannot read value (engine)")); diff --git a/src/usi-engine/bona/shogi.h b/src/usi-engine/bona/shogi.h index 1a6651f..a64a161 100644 --- a/src/usi-engine/bona/shogi.h +++ b/src/usi-engine/bona/shogi.h @@ -125,7 +125,10 @@ extern unsigned char ailast_one[512]; //#define BNZ_VER "17" // 20220108 kldgain //#define BNZ_VER "18" // 20220110 kldgain 0.0000013, -p 3200 (autousiで指定) //#define BNZ_VER "27" // 20220224 Convert from AobaKomaochi v26. Swish, mate3 kyo promote bug fix. balanced_opening, Network V3 -#define BNZ_VER "28" // 20220225 balanced_opening ply<=2 always use value +//#define BNZ_VER "28" // 20220225 balanced_opening ply<=2 always use value +//#define BNZ_VER "29" // 20220406 policy softmax temperature 1.0 -> 1.8 +//#define BNZ_VER "30" // 20220406 kldgain 0.000006, balanced_opening within +150 ELO +#define BNZ_VER "31" // 20220407 cancel balanced_opening. resign ok under 30 moves in autousi. #define BNZ_NAME "AobaZero" //#define BNZ_VER "16" // 20210528 komaochi, mate3 diff --git a/src/usi-engine/bona/ysszero.cpp b/src/usi-engine/bona/ysszero.cpp index b6a15ae..f5175ca 100644 --- a/src/usi-engine/bona/ysszero.cpp +++ b/src/usi-engine/bona/ysszero.cpp @@ -723,12 +723,11 @@ void clear_opening_hash() static int fDone = 0; int memGB = GetSystemMemoryMB() / 1024; if ( fDone == 0 ) { - if ( memGB >= 7 ) { - Opening_Hash_Size = 1024*128; // 平均31手で1個が(5*4*31)+(10*4)=660byte。1024*128=131072 で83MB, 65個並列だと5.2GB。colabは12GB。 - Opening_Hash_Stop_Ply = 8; // 8手以上の出現局面は登録しない。 - } else { - Opening_Hash_Size = 1024*16; - Opening_Hash_Stop_Ply = 3; // 3手以上の出現局面は登録しない。3手以上では2回出現で徐々に登録される + Opening_Hash_Size = 1024*16; + Opening_Hash_Stop_Ply = 3; // 3手以上の出現局面は登録しない。3手以上では2回出現で徐々に登録される + if ( memGB >= 7 ) { // そもそも35000棋譜で1重み終了。140並列だと200棋譜程度しか1プロセスで作らない。 +// Opening_Hash_Size = 1024*128; // 平均31手で1個が(5*4*31)+(10*4)=660byte。1024*128=131072 で83MB, 65個並列だと5.2GB。colabは12GB。 +// Opening_Hash_Stop_Ply = 8; // 8手以上の出現局面は登録しない。 } Opening_Hash_Mask = Opening_Hash_Size - 1; opening_hash.resize(Opening_Hash_Size); @@ -1443,6 +1442,24 @@ if (0) { } if ( sideToMove==white ) v = -v; + + if ( fOpeningHash == false ) { // policy softmax + const float temperature = 1.8f; // 1.0 より 1.4 - 1.8 の方が100-800playoutでは+50 ELO強い + double inv_temperature = 1.0 / temperature; + double wheel[MAX_LEGAL_MOVES]; + double w_sum = 0.0; + for (int i = 0; i < phg->child_num; i++) { + double d = phg->child[i].bias; + wheel[i] = pow(d, inv_temperature); + w_sum += wheel[i]; + } + double factor = 1.0 / w_sum; + for (i = 0; i < phg->child_num; i++) { +// PRT("%2d:bias=%10f -> %10f, ply=%d\n",i,phg->child[i].bias,factor * wheel[i],ply); + phg->child[i].bias = factor * wheel[i]; + } + } + phg->hashcode64 = ptree->sequence_hash; phg->hash64pos = get_marge_hash(ptree, sideToMove); phg->games_sum = 0; // この局面に来た回数(子局面の回数の合計) @@ -2178,7 +2195,7 @@ void usi_newgame(tree_t * restrict ptree) if ( (rand_m521() % 10) == 0 ) { // 10%で投了を禁止。間違った投了が5%以下か確認するため resign_winrate = 0; } - if ( average_winrate ) { + if ( 0 && average_winrate ) { char str[256] = "startpos moves "; // "position startpos moves " char *lasts = str; usi_posi( ptree, &lasts ); @@ -2476,7 +2493,7 @@ int balanced_opening(tree_t * restrict ptree, int sideToMove, int ply, int fPoli int fHashFull = 0; int stop_ply = nVisitCount+1; - const int VALUE_N = 2; // 0ですべてノードでValueを調べる。1で1回以上なら調べる + const int VALUE_N = 1; // 0ですべてノードでValueを調べる。1で1回以上なら調べる if ( (phg->games_sum >= VALUE_N || ply <= 2) && phg->child_num > 0 && phg->child[0].value == 0 && ply != stop_ply ) { int i; for (i = 0; i < phg->child_num; i++) { @@ -2505,14 +2522,28 @@ int balanced_opening(tree_t * restrict ptree, int sideToMove, int ply, int fPoli int fUseValue = (phg->child_num > 0 && phg->child[0].value != 0 && fHashFull == 0); // valueの差をPolicyの代わりに +//fUseValue = 0; + float v = phg->net_value; if ( (ply+1)&1 ) v = -v; v = (1.0+v) / 2.0; - const float vd = 0.20; // 0.20で17%が失敗。0.15で20%が失敗。0.55 だと 0.35 < x < 0.75, 投了が0.23 なのでほぼぎりぎり +// const float vd = 0.20; // 0.20で17%が失敗。0.15で20%が失敗。0.55 だと 0.35 < x < 0.75, 投了が0.23 なのでほぼぎりぎり + + double b = 0; + double c = 150; // 上下にこのレート差の勝率まで。wr=0.5 で 0.3 < v < 0.5, wr=0.7 で 0.49 < v < 0.84 + double wr = average_winrate; + if ( wr < 0.01 ) wr = 0.01; + if ( wr > 0.99 ) wr = 0.99; + double x = -400.0*log(1.0/wr - 1.0) / log(10.0); + double r0 = 1.0 / (1.0 + pow(10.0,(b+c-x)/400.0)); + double r1 = 1.0 / (1.0 + pow(10.0,(b-c-x)/400.0)); + // r0 < v < r1 ならOK +// PRT("v=%f, %f < %f < %f\n",v, r0,wr,r1); int ret = 0; - if ( ply <= stop_ply && (v > average_winrate + vd || v < average_winrate - vd) ) ret = 1; + if ( ply <= stop_ply && (v > r1 || v < r0) ) ret = 1; - if ( fPolicyBest == 0 && ret ) { + // Undoして勝率調整すると、0手目の全部の局面が同じ勝率、で学習されてしまう。 + if ( 0 && fPolicyBest == 0 && ret ) { *pUndo = 1; return ret; } @@ -2520,6 +2551,7 @@ int balanced_opening(tree_t * restrict ptree, int sideToMove, int ply, int fPoli if ( ply == stop_ply ) { // 31で30手 static int all,n[10]; static int v_dist[101]; + static int furi_file[2][9] = {0}, furi[2] = {0}; all++; // if ( BOARD[33]==-1 ) n[0]++; // 34歩 // if ( BOARD[47]==+1 ) n[0]++; // 76歩 @@ -2528,8 +2560,12 @@ int balanced_opening(tree_t * restrict ptree, int sideToMove, int ply, int fPoli if ( BOARD[43]==+1 && BOARD[24]==-6 ) n[0]++; // ▲25歩、△33角 // if ( BOARD[24]==-6 ) n[0]++; // ▲25歩、△33角 v_dist[(int)(100.0*v) % 101]++; // 0.90 - 0.10 + for (int i=0;i<81;i++) { + if ( BOARD[i] == +7 ) { furi_file[0][i%9]++; furi[0]++; } + if ( BOARD[i] == -7 ) { furi_file[1][i%9]++; furi[1]++; } + } + -/* const int SAME_MAX = 100000; static uint64 same_hash[SAME_MAX]; static int same_num = 0; @@ -2544,8 +2580,12 @@ int balanced_opening(tree_t * restrict ptree, int sideToMove, int ply, int fPoli } PRT("v=%.3f(%d),%d/%d=%f,unique=%d(%.3f)\n",v,ret,n[0],all,(float)n[0]/all,same_num,(float)same_num/all); // for (j=0;j<101;j++) PRT("%d(%.3f),",v_dist[j],(float)v_dist[j]/all); PRT("\n"); -*/ - PRT("v=%.3f(%d),%d/%d\n",v,ret,n[0],all); + +// PRT("v=%.3f(%d),%d/%d\n",v,ret,n[0],all); + for (int j=0;j<2;j++) { + for (int i=0;i<9;i++) PRT("%6.3f,",(float)furi_file[j][i]/(furi[j]+(furi[j]==0))); + PRT("\n"); + } print_board(ptree); return ret; @@ -2570,7 +2610,7 @@ int balanced_opening(tree_t * restrict ptree, int sideToMove, int ply, int fPoli hs.child[i].bias = pc->bias; hs.child[i].move = pc->move; float d = max_v - pc->value; -// PRT("%s:diff=%9f,%f,%f\n",str_CSA_move(pc->move, true),d,1.0/exp(d*70.0),1.0/exp(d*90.0)); +// PRT("%s:bias=%9f,value=%9f,diff=%9f,%f,%f\n",str_CSA_move(pc->move),pc->bias,pc->value,d,1.0/exp(d*70.0),1.0/exp(d*90.0)); if ( fUseValue ) hs.child[i].bias = 1.0/exp(d*70.0); sum += hs.child[i].bias; } @@ -2578,10 +2618,11 @@ int balanced_opening(tree_t * restrict ptree, int sideToMove, int ply, int fPoli for (i = 0; i < phg->child_num; i++) { // CHILD *pc = &phg->child[i]; hs.child[i].bias /= sum; -// PRT("%s:->%9f\n",str_CSA_move(pc->move, true),hs.child[i].bias); +// PRT("%s:->%9f\n",str_CSA_move(pc->move),hs.child[i].bias); } - const float epsilon = 0.25f; // epsilon = 0.25 +// const float epsilon = 0.25f; // epsilon = 0.25 + const float epsilon = 0.05f; // epsilon = 0.25 が通常だが探索なしはノイズの影響が大きいので減らす const float alpha = 0.15f; // alpha ... Chess = 0.3, Shogi = 0.15, Go = 0.03 if ( fAddNoise ) add_dirichlet_noise(epsilon, alpha, &hs); @@ -2609,8 +2650,8 @@ int balanced_opening(tree_t * restrict ptree, int sideToMove, int ply, int fPoli if ( pc==NULL || i==phg->child_num ) DEBUG_PRT("Err.\n"); undo: - char sg[2] = { '+','-' }; - PRT("%2d:fUseValue=%d,%2d:net_v=%7.4f(%6.3f)ret=%d:%c%s,bias=%6.3f,r=%.3f/%.3f\n",ply,fUseValue,i,phg->net_value,v,ret,sg[(ptree->nrep+ply+1) & 1],str_CSA_move(pc->move),pc->bias,indicator,w_sum); +// char sg[2] = { '+','-' }; +// PRT("%2d:fUseValue=%d,%2d:net_v=%7.4f(%6.3f)ret=%d:%c%s,bias=%6.3f,r=%.3f/%.3f\n",ply,fUseValue,i,phg->net_value,v,ret,sg[(ptree->nrep+ply+1) & 1],str_CSA_move(pc->move),pc->bias,indicator,w_sum); MakeMove( sideToMove, pc->move, ply ); MOVE_CURR = pc->move; balanced_opening_move[ply] = pc->move; @@ -2646,7 +2687,7 @@ void make_balanced_opening(tree_t * restrict ptree, int sideToMove, int ply) { for (i=0;i<30;i++) PRT("%d,",n_vCount[i]); PRT("\n"); count_OpeningHash(); - print_board(ptree); +// print_board(ptree); DEBUG_PRT("make_balanced_opening fail. average_winrate=%f\n",average_winrate); }