Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update the Network, trained differently and on FRC data
The previous network was trained to output a score, which was, in training, applied to both the MG and EG components of the evaluation. However, in implementation, we were only applying it to the MG in Ethereal.

This new network is trained to expressly produce a score only for the MG, and to have it only be applied to the MG component of the eval. This is done correctly.

Additionally, the Network is trained using an additionally ~9.6 million FRC positions. This was done to increase diversity, and to resolve an issue where Regression Tests failed to show FRC improvements for the previous network.

Testing was done to confirm that the gains for FRC are massive. Testing was done to confirm that any changes to Standard chess are minimal.

Tests for Fischer Random Chess:

ELO   | 18.90 +- 9.10 (95%)
SPRT  | 10.0+0.1s Threads=1 Hash=8MB
LLR   | 2.97 (-2.94, 2.94) [0.00, 5.00]
Games | N: 2816 W: 785 L: 632 D: 1399
http://chess.grantnet.us/test/7548/

ELO   | 18.95 +- 8.32 (95%)
SPRT  | 60.0+0.6s Threads=1 Hash=64MB
LLR   | 3.04 (-2.94, 2.94) [0.00, 5.00]
Games | N: 2624 W: 586 L: 443 D: 1595
http://chess.grantnet.us/test/7549/

Tests for Standard Chess:

ELO   | 1.14 +- 2.53 (95%)
SPRT  | 10.0+0.1s Threads=1 Hash=8MB
LLR   | -0.93 (-2.94, 2.94) [0.00, 5.00]
Games | N: 29376 W: 6003 L: 5907 D: 17466
http://chess.grantnet.us/test/7547/

ELO   | 1.63 +- 2.27 (95%)
SPRT  | 10.0+0.1s Threads=1 Hash=8MB
LLR   | 0.25 (-2.94, 2.94) [0.00, 5.00]
Games | N: 33296 W: 6281 L: 6125 D: 20890
http://chess.grantnet.us/test/7546/

BENCH : 4,933,831
  • Loading branch information
AndyGrant committed Sep 24, 2020
1 parent b169008 commit c8b7199
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 72 deletions.
8 changes: 5 additions & 3 deletions src/network.c
Expand Up @@ -24,6 +24,7 @@

#include "bitboards.h"
#include "board.h"
#include "evaluate.h"
#include "move.h"
#include "network.h"
#include "thread.h"
Expand Down Expand Up @@ -112,11 +113,13 @@ int fullyComputePKNetwork(Thread *thread) {
outputNeurons[i] += layer1Neurons[j] * PKNN.layer1Weights[i][j];
}

return outputNeurons[0];
return MakeScore((int) outputNeurons[0], 0);
}

int partiallyComputePKNetwork(Thread *thread) {

if (TRACE) return fullyComputePKNetwork(thread);

float *layer1Neurons = thread->pknnlayer1[thread->pknndepth];
float outputNeurons[PKNETWORK_OUTPUTS];

Expand All @@ -127,7 +130,7 @@ int partiallyComputePKNetwork(Thread *thread) {
outputNeurons[i] += layer1Neurons[j] * PKNN.layer1Weights[i][j];
}

return outputNeurons[0];
return MakeScore((int) outputNeurons[0], 0);
}


Expand Down Expand Up @@ -183,7 +186,6 @@ void updatePKNetworkAfterMove(Thread *thread, uint16_t move) {
}

if (taken == PAWN) {
assert(0);
indexes[changes++] = computePKNetworkIndex(!colour, taken, to);
signs[changes - 1] = -1;
}
Expand Down
4 changes: 1 addition & 3 deletions src/network.h
Expand Up @@ -31,9 +31,7 @@ typedef struct PKNetwork {

// PKNetworks are of the form [Input, Hidden Layer 1, Output Layer]
// Our current Network is [224x32, 32x1]. The Network is trained to
// output a Score in CentiPawns, and thus Output Neurons need do not
// need activation functions. The 32x1 operation applys a ReLU, where
// as the 224x32 layer does not, since inputs are binary 0s and 1s
// output a Score in CentiPawns for the Midgame only.

ALIGN64 float inputWeights[PKNETWORK_LAYER1][PKNETWORK_INPUTS];
ALIGN64 float inputBiases[PKNETWORK_LAYER1];
Expand Down
18 changes: 5 additions & 13 deletions src/tuner.c
Expand Up @@ -205,12 +205,9 @@ void initCoefficients(TVector coeffs) {

void initTunerEntries(TEntry *entries, Thread *thread, TArray methods) {

Undo undo;
char line[256];
Limits limits = {0};
thread->limits = &limits; thread->depth = 0;

FILE *fin = fopen("FENS", "r");

for (int i = 0; i < NPOSITIONS; i++) {

if (fgets(line, 256, fin) == NULL)
Expand All @@ -225,14 +222,7 @@ void initTunerEntries(TEntry *entries, Thread *thread, TArray methods) {
// Set the board with the current FEN
boardFromFEN(&thread->board, line, 0);

// Resolve the position to mitigate tactics
if (QSRESOLVE) {
qsearch(thread, &thread->pv, -MATE, MATE, 0);
for (int pvidx = 0; pvidx < thread->pv.length; pvidx++)
applyMove(&thread->board, thread->pv.line[pvidx], &undo);
}

// Defer the set to another function
// Defer the setup to another function
initTunerEntry(&entries[i], thread, &thread->board, methods);

// Occasional reporting for total completion
Expand Down Expand Up @@ -324,13 +314,15 @@ double computeOptimalK(TEntry *entries) {
best = error, start = curr;
}

printf("Epoch [%d] K = %f E = %f\n", i, start, best);
printf("Epoch [%d] K = [%.9f] E = [%.9f]\n", i, start, best);

end = start + step;
start = start - step;
step = step / 10.0;
}

printf("\n");

return start;
}

Expand Down
36 changes: 17 additions & 19 deletions src/tuner.h
Expand Up @@ -22,25 +22,23 @@

#include "types.h"

#define NPARTITIONS ( 64) // Total thread partitions
#define KPRECISION ( 10) // Iterations for computing K

#define QSRESOLVE ( 0) // Whether to resolve via a qsearch()
#define PRETTYIFY ( 1) // Whether to format as if we tune everything
#define REPORTING ( 50) // How often to print the new parameters

#define LRRATE ( 0.10) // Global Learning rate
#define LRDROPRATE ( 1.00) // Cut LR by this each LR-step
#define LRSTEPRATE ( 250) // Cut LR after this many epochs

#define TuneNormal ( 0) // Flag to enable tuning on all Normals
#define TuneSafety ( 0) // Flag to enable tuning on all Safeties
#define TuneComplexity ( 0) // Flag to enable tuning on all Complexities

#define NTERMS ( 0) // Total terms in the Tuner (904)
#define MAXEPOCHS ( 10000) // Max number of epochs allowed
#define BATCHSIZE ( 16384) // FENs per mini-batch
#define NPOSITIONS ( 9999740) // Total FENS in the book
#define NPARTITIONS ( 64) // Total thread partitions
#define KPRECISION ( 10) // Iterations for computing K
#define PRETTYIFY ( 0) // Whether to format as if we tune everything
#define REPORTING ( 50) // How often to print the new parameters

#define LRRATE ( 0.10) // Global Learning rate
#define LRDROPRATE ( 1.00) // Cut LR by this each LR-step
#define LRSTEPRATE ( 250) // Cut LR after this many epochs

#define TuneNormal ( 0) // Flag to enable all Normals (856)
#define TuneSafety ( 0) // Flag to enable all Safeties ( 44)
#define TuneComplexity ( 0) // Flag to enable all Complexities ( 4)

#define NTERMS ( 0) // Total terms in the Tuner (904)
#define MAXEPOCHS ( 100000) // Max number of epochs allowed
#define BATCHSIZE ( 16384) // Training samples per mini-batch
#define NPOSITIONS ( 9999740) // Total Training samples in the book

#define STACKSIZE ((int)((double) NPOSITIONS * NTERMS / 64))

Expand Down
2 changes: 1 addition & 1 deletion src/uci.h
Expand Up @@ -22,7 +22,7 @@

#include "types.h"

#define VERSION_ID "12.60"
#define VERSION_ID "12.61"

#if defined(USE_PEXT)
#define ETHEREAL_VERSION VERSION_ID" (PEXT)"
Expand Down

0 comments on commit c8b7199

Please sign in to comment.