Skip to content

Commit

Permalink
MAE
Browse files Browse the repository at this point in the history
Bench: 10437873
  • Loading branch information
Dannyj1 committed Feb 9, 2023
1 parent 931dfce commit 454e12c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <iostream>

namespace Zagreus {
int evalValues[72] = { 101, 105, 356, 344, 364, 354, 535, 533, 1002, 1008, 1, 6, 6, -1, 7, 5, 5, 5, 2, 10, -50, 0, -25, 0, -29, 1, -20, -6, 0, -3, -2, 8, -4, 4, -2, 0, 8, 9, 9, 3, 7, 8, 0, 0, 0, -2, 20, 20, 15, 15, 5, 2, 4, 2, 3, 2, -24, -24, 15, 2, -5, 0, 0, 0, -20, -20, 0, -3, 3, 3, 24, 0, };
int evalValues[72] = { 104, 110, 353, 353, 357, 357, 533, 532, 1011, 1010, 1, 12, 8, 3, 10, 8, 3, 11, 8, 17, -50, 0, -25, 0, -27, -4, -5, 1, -9, 0, 0, 0, 2, 2, 1, 0, 17, 18, 13, 11, 15, 13, 11, 9, 11, 10, 20, 20, 15, 15, 12, 12, 3, 0, 9, 12, -31, -18, 14, 0, -4, -1, 0, 0, -20, -20, -7, -10, 3, 3, 28, 2, };

int baseEvalValues[72] = {
100, // MIDGAME_PAWN_MATERIAL
Expand Down
26 changes: 12 additions & 14 deletions src/pst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,23 @@
#include <vector>

namespace Zagreus {
int midgamePawnTable[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 99, 129, 64, 91, 67, 123, 34, -12, -1, 8, 26, 33, 58, 59, 26, -15, -19, 7, 0, 18, 25, 17, 20, -19, -31, -5, -15, 12, 11, 12, 16, -22, -25, 3, -11, -6, 2, 4, 21, -17, -28, 1, -5, -14, -10, 5, 33, -19, 0, 0, 0, 0, 0, 0, 0, 0 };
int endgamePawnTable[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 181, 172, 162, 134, 150, 130, 166, 186, 94, 101, 82, 69, 58, 52, 79, 93, 32, 23, 11, 0, -2, 6, 21, 20, 7, 10, -8, -11, -8, -10, 4, 8, 6, 1, -5, 4, 4, -2, 1, -2, 10, 9, 13, 16, 7, 3, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int midgamePawnTable[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 100, 130, 65, 93, 68, 124, 35, -9, 1, 9, 27, 33, 60, 61, 26, -13, -17, 2, -2, 17, 23, 16, 18, -15, -37, -8, -20, 12, 8, 8, 14, -27, -26, 0, -13, -6, 3, 5, 18, -18, -20, 6, 0, -12, -6, 6, 37, -15, 0, 0, 0, 0, 0, 0, 0, 0 };
int endgamePawnTable[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 183, 175, 164, 137, 151, 132, 168, 190, 98, 105, 85, 72, 63, 55, 83, 98, 33, 22, 8, 1, -1, 9, 23, 24, 6, 8, -10, -9, -5, -8, 7, 9, 7, 0, -5, 5, 5, 1, 2, 0, 13, 10, 15, 17, 9, 6, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0 };

int midgameKnightTable[64] = { -167, -88, -33, -48, 58, -95, -14, -105, -71, -40, 77, 38, 26, 65, 7, -15, -46, 58, 36, 66, 90, 132, 77, 46, -5, 14, 21, 49, 33, 60, 20, 23, -9, 3, 13, 14, 30, 18, 23, -2, -24, -8, 12, 14, 14, 0, 20, -14, -21, -47, -10, 3, 6, 20, -14, -13, -104, -28, -53, -32, -16, -26, -15, -23 };
int endgameKnightTable[64] = { -59, -36, -12, -28, -31, -27, -63, -98, -25, -6, -25, -1, -3, -26, -23, -50, -24, -20, 7, 8, 0, -7, -20, -38, -14, 2, 24, 21, 26, 7, 7, -20, -14, -7, 14, 28, 18, 18, 4, -18, -26, -2, -10, 13, 7, -10, -24, -23, -38, -18, -10, -4, 4, -19, -23, -43, -30, -50, -21, -14, -23, -17, -44, -63 };
int midgameKnightTable[64] = { -165, -87, -31, -45, 59, -94, -13, -102, -71, -40, 77, 38, 26, 65, 7, -15, -46, 59, 37, 65, 91, 130, 76, 44, -5, 13, 22, 47, 32, 61, 20, 24, -10, 4, 12, 13, 32, 19, 23, -5, -23, -8, 16, 17, 14, 4, 19, -15, -21, -47, -9, 5, 8, 19, -12, -12, -104, -31, -55, -35, -17, -28, -13, -22 };
int endgameKnightTable[64] = { -58, -35, -10, -26, -29, -25, -63, -96, -24, -4, -24, 0, -2, -26, -22, -49, -24, -18, 8, 8, 2, -6, -20, -37, -13, 3, 24, 21, 26, 8, 8, -17, -14, -6, 13, 27, 19, 19, 4, -18, -26, -2, -12, 13, 7, -10, -23, -23, -37, -17, -9, -4, 4, -19, -22, -42, -30, -50, -22, -16, -21, -19, -44, -63 };

int midgameBishopTable[64] = { -29, 3, -81, -37, -27, -42, 5, -5, -27, 15, -15, -11, 31, 57, 22, -44, -12, 36, 46, 39, 37, 51, 39, 0, -7, 3, 20, 50, 37, 33, 7, 1, 0, 14, 7, 28, 30, 5, 10, 4, 0, 21, 13, 10, 6, 21, 16, 12, 7, 28, 16, 0, 4, 21, 38, 5, -30, -7, -10, -20, -10, -7, -40, -22 };
int endgameBishopTable[64] = { -16, -21, -7, -9, -7, -7, -18, -21, -7, -5, 6, -11, 0, -12, -3, -14, 0, -8, 0, -1, 0, 9, 0, 1, -5, 7, 11, 2, 10, 8, 4, 2, -4, 3, 12, 15, 9, 6, -3, -6, -9, 0, 11, 7, 9, 0, -7, -15, -10, -10, -5, -1, 2, -8, -12, -25, -19, -11, -13, -3, -3, -13, -5, -17 };
int midgameBishopTable[64] = { -25, 3, -80, -34, -24, -41, 4, -1, -26, 15, -12, -9, 32, 56, 21, -42, -10, 35, 46, 39, 36, 51, 38, 0, -6, 3, 22, 50, 38, 34, 3, 3, 1, 15, 5, 28, 29, 3, 11, 3, 0, 19, 15, 11, 8, 23, 15, 13, 6, 32, 16, 6, 8, 22, 42, 5, -29, -8, -8, -20, -10, -3, -39, -22 };
int endgameBishopTable[64] = { -14, -20, -6, -6, -4, -5, -17, -18, -5, -4, 6, -8, 1, -11, -3, -12, 1, -7, 1, 0, 0, 10, 0, 1, -4, 7, 12, 2, 10, 7, 5, 4, -3, 3, 14, 15, 9, 5, -1, -5, -9, 0, 12, 11, 9, 1, -7, -13, -10, -5, -3, 4, 6, -6, -10, -24, -18, -9, -11, 0, 0, -11, -3, -17 };

int midgameRookTable[64] = { 34, 41, 28, 48, 64, 9, 29, 42, 25, 29, 58, 59, 81, 68, 28, 41, -2, 21, 26, 36, 18, 43, 60, 22, -25, -11, 12, 29, 23, 38, -7, -18, -40, -26, -14, -2, 6, -8, 5, -26, -46, -22, -15, -11, 6, 3, -5, -28, -40, -17, -20, -7, -3, 15, -5, -69, -14, -16, -3, 13, 18, 10, -28, -34 };
int endgameRookTable[64] = { 16, 8, 14, 10, 11, 9, 0, 3, 10, 9, 9, 7, 0, 3, 12, 0, 6, 7, 4, 4, 3, -6, -4, 2, 8, 1, 10, 2, 2, 2, 0, 9, 3, 7, 7, 3, -4, -5, -6, -9, -5, 2, -1, 1, -2, -5, -5, -15, -4, -2, -1, 4, -7, -7, -13, -2, -4, 0, -1, -1, 0, -11, 7, -18 };

int midgameQueenTable[64] = { -22, 0, 27, 11, 59, 42, 38, 43, -21, -41, -5, 1, -18, 58, 27, 51, -8, -18, 11, 7, 24, 53, 45, 53, -21, -26, -16, -15, 1, 12, 2, 1, -6, -26, -12, -13, -1, 0, 3, -7, -17, -4, -10, -9, -11, -3, 15, 3, -34, -11, 7, 3, 8, 13, -4, 2, 0, -17, -5, -2, 2, -17, -29, -42 };
int endgameQueenTable[64] = { -6, 22, 20, 27, 27, 18, 6, 18, -10, 21, 33, 43, 55, 25, 32, 1, -14, 3, 12, 50, 43, 32, 18, 8, 5, 24, 23, 43, 59, 32, 57, 37, -13, 26, 15, 44, 31, 33, 38, 21, -18, -25, 15, 0, 7, 11, 11, 7, -21, -26, -27, -17, -17, -25, -35, -29, -31, -29, -18, -43, 0, -26, -16, -39 };

int midgameKingTable[64] = { -64, 23, 16, -14, -56, -33, 1, 13, 30, 0, -19, -6, -6, -4, -37, -28, -9, 25, 2, -15, -19, 7, 23, -21, -16, -20, -10, -27, -31, -21, -13, -38, -48, 0, -28, -36, -43, -43, -33, -50, -15, -19, -24, -43, -46, -26, -13, -25, 1, 5, -10, -66, -43, -11, 8, 10, -5, 31, 1, -33, -13, -23, 26, 10 };
int endgameKingTable[64] = { -73, -35, -17, -18, -10, 15, 4, -16, -10, 21, 14, 15, 16, 39, 26, 12, 8, 20, 21, 13, 22, 48, 45, 10, -8, 20, 25, 28, 19, 33, 22, 5, -16, -4, 19, 25, 27, 24, 11, -8, -20, -5, 9, 18, 25, 16, 6, -9, -28, -12, 2, 14, 12, 8, -7, -10, -52, -37, -19, -6, -36, -8, -22, -48 };
int midgameRookTable[64] = { 35, 39, 28, 47, 64, 9, 28, 44, 24, 28, 59, 58, 82, 68, 29, 41, -1, 21, 26, 36, 20, 43, 61, 23, -23, -10, 14, 29, 24, 39, -6, -17, -39, -26, -12, -1, 7, -8, 5, -24, -47, -23, -13, -11, 5, 3, -4, -29, -40, -17, -20, -8, -1, 14, -3, -68, -10, -18, 1, 11, 19, 14, -30, -29 };
int endgameRookTable[64] = { 16, 8, 14, 10, 11, 10, 0, 3, 10, 9, 10, 7, 0, 4, 13, 0, 8, 9, 6, 4, 7, -4, -2, 4, 10, 3, 12, 2, 6, 4, 0, 11, 3, 9, 10, 4, -1, -3, -5, -7, -2, 3, 0, 1, 0, -2, -2, -15, -2, 0, 1, 3, -5, -5, -12, 0, 0, -1, 2, 0, 0, -7, 8, -12 };

int midgameQueenTable[64] = { -18, 0, 30, 13, 61, 44, 39, 47, -21, -41, -5, 1, -16, 57, 26, 50, -6, -16, 12, 7, 25, 53, 46, 54, -19, -27, -15, -16, 0, 14, 2, 1, -7, -22, -11, -14, -1, 0, 5, -9, -16, -5, -9, -11, -11, -4, 15, 2, -32, -9, 9, 5, 11, 15, -2, 2, 0, -16, -5, 7, 12, -18, -28, -43 };
int endgameQueenTable[64] = { -2, 23, 24, 30, 30, 20, 9, 22, -9, 21, 33, 44, 57, 26, 32, 1, -12, 4, 13, 51, 45, 33, 19, 9, 6, 25, 23, 43, 59, 32, 58, 38, -10, 28, 17, 44, 31, 34, 40, 22, -16, -22, 16, 0, 7, 12, 13, 7, -19, -26, -26, -14, -12, -23, -33, -27, -30, -28, -16, -34, 7, -25, -13, -37 };

int midgameKingTable[64] = { -63, 23, 16, -14, -55, -32, 1, 12, 30, 0, -19, -5, -5, -3, -36, -28, -9, 26, 3, -14, -18, 6, 23, -20, -16, -18, -8, -27, -30, -18, -11, -36, -49, 0, -29, -35, -40, -42, -33, -49, -15, -20, -23, -43, -44, -24, -10, -24, 0, 4, -10, -70, -47, -11, 7, 9, -7, 34, -2, -32, -13, -23, 26, 7 };
int endgameKingTable[64] = { -72, -35, -17, -19, -9, 16, 4, -15, -10, 22, 12, 16, 17, 41, 27, 12, 6, 21, 21, 14, 23, 50, 46, 11, -7, 21, 25, 29, 20, 35, 25, 6, -17, -5, 19, 25, 28, 27, 12, -5, -21, -6, 8, 18, 25, 18, 7, -9, -31, -15, 0, 12, 9, 7, -6, -10, -54, -37, -21, -9, -37, -9, -24, -51 };

/* int midgamePawnTable[64] = {
0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
6 changes: 3 additions & 3 deletions src/tuner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Zagreus {
float K = 0.0;

int batchSize = 256;
float learningRate = 0.4f;
float learningRate = 0.1f;
float epsilon = 6.0f;
float optimizerEpsilon = 1e-6f;
float epsilonDecay = 0.97f;
Expand Down Expand Up @@ -97,10 +97,10 @@ namespace Zagreus {
tunerBoard.setFromFenTuner(pos.fen);
int evalScore = searchManager.evaluate(tunerBoard, maxEndTime, engine);
float loss = pos.result - sigmoid((float) evalScore);
totalLoss += loss * loss;
totalLoss += fabs(loss);
}

return 1.0f / (2.0f * (float) amountOfPositions) * totalLoss;
return totalLoss / (float) amountOfPositions;
}

float findOptimalK(std::vector<TunePosition> &positions, std::chrono::time_point<std::chrono::high_resolution_clock> &maxEndTime, ZagreusEngine &engine) {
Expand Down

0 comments on commit 454e12c

Please sign in to comment.