Skip to content

Commit

Permalink
Update to eval values trained using 90% lichess-big3-resolved.book an…
Browse files Browse the repository at this point in the history
…d 10% stash_gedas.epd
  • Loading branch information
eduherminio committed Nov 29, 2023
1 parent d3d7d9f commit d980578
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 130 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Links to some training datasets:

- ['lichess-big3.resolved'](https://discord.com/channels/1132289356011405342/1137454121876721755/1153433610527981598c)

- ['Stash data'](https://drive.google.com/file/d/1LaaW7bNHBnyEdt51MP6SAZCbSdPzlk8d/view) transformed into a format comptatible with this tuner by [cj5716](https://github.com/cj5716)

- [Ethereal data dump](https://www.talkchess.com/forum3/viewtopic.php?f=7&t=75350)

## Additions to the original tuner

### Build and run instructions
Expand Down
44 changes: 22 additions & 22 deletions src/engines/lynx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,51 @@ using u64 = uint64_t;

const int base = 64 * 6 - 16; // Removing pawns from 1 and 8 rank

const int DoubledPawnPenalty_MG = -3;
const int DoubledPawnPenalty_EG = -11;
const int DoubledPawnPenalty_MG = -5;
const int DoubledPawnPenalty_EG = -14;
const int DoubledPawnPenaltyIndex = base + 0;

const int IsolatedPawnPenalty_MG = -13;
const int IsolatedPawnPenalty_EG = -10;
const int IsolatedPawnPenalty_MG = -17;
const int IsolatedPawnPenalty_EG = -14;
const int IsolatedPawnPenaltyIndex = base + 1;

const int OpenFileRookBonus_MG = 42;
const int OpenFileRookBonus_EG = 22;
const int OpenFileRookBonus_MG = 60;
const int OpenFileRookBonus_EG = 28;
const int OpenFileRookBonusIndex = base + 2;

const int SemiOpenFileRookBonus_MG = 18;
const int SemiOpenFileRookBonus_EG = 16;
const int SemiOpenFileRookBonus_MG = 25;
const int SemiOpenFileRookBonus_EG = 23;
const int SemiOpenFileRookBonusIndex = base + 3;

const int BishopMobilityBonus_MG = 8;
const int BishopMobilityBonus_EG = 7;
const int BishopMobilityBonus_MG = 10;
const int BishopMobilityBonus_EG = 10;
const int BishopMobilityBonusIndex = base + 4;

const int QueenMobilityBonus_MG = 2;
const int QueenMobilityBonus_EG = 7;
const int QueenMobilityBonus_MG = 3;
const int QueenMobilityBonus_EG = 9;
const int QueenMobilityBonusIndex = base + 5;

const int SemiOpenFileKingPenalty_MG = -29;
const int SemiOpenFileKingPenalty_EG = 19;
const int SemiOpenFileKingPenalty_MG = -38;
const int SemiOpenFileKingPenalty_EG = 25;
const int SemiOpenFileKingPenaltyIndex = base + 6;

const int OpenFileKingPenalty_MG = -80;
const int OpenFileKingPenalty_EG = 3;
const int OpenFileKingPenalty_MG = -107;
const int OpenFileKingPenalty_EG = 4;
const int OpenFileKingPenaltyIndex = base + 7;

const int KingShieldBonus_MG = 15;
const int KingShieldBonus_EG = -5;
const int KingShieldBonus_MG = 19;
const int KingShieldBonus_EG = -6;
const int KingShieldBonusIndex = base + 8;

const int BishopPairBonus_MG = 22;
const int BishopPairBonus_EG = 65;
const int BishopPairBonus_MG = 30;
const int BishopPairBonus_EG = 88;
const int BishopPairMaxBonusIndex = base + 9;

constexpr static std::array<int, 8> PassedPawnBonus_MG = {
0, -2, -13, -12, 13, 38, 53, 0};
0, -2, -16, -16, 20, 61, 92, 0};

constexpr static std::array<int, 8> PassedPawnBonus_EG = {
0, 5, 10, 32, 62, 132, 191, 0};
0, 7, 13, 44, 83, 175, 257, 0};

const int PassedPawnBonusStartIndex = base + 10;

Expand Down
198 changes: 99 additions & 99 deletions src/engines/lynx_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,156 +2,156 @@
using u64 = uint64_t;

constexpr std::array<int, 12> PieceValue = {
+73, +275, +249, +359, +788, // 0,
+109, +356, +324, +653, +1123, // 0,
+102, +382, +352, +500, +1102, // 0,
+149, +484, +435, +892, +1531, // 0,
};

std::array<int, 6> phaseValues = {0, 1, 1, 2, 4, 0};

constexpr static int EvalNormalizationCoefficient = 78;
constexpr static int EvalNormalizationCoefficient = 138;

constexpr static std::array<int, 64> MiddleGamePawnTable =
{
0, 0, 0, 0, 0, 0, 0, 0,
-24, -17, -9, -10, 0, 18, 22, -14,
-22, -19, -2, 10, 15, 20, 17, 4,
-19, -12, 3, 15, 21, 24, 1, -2,
-17, -9, 2, 18, 23, 22, 0, -3,
-21, -13, -2, 5, 12, 15, 12, 0,
-24, -14, -13, -9, 2, 13, 13, -20,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
-31, -22, -15, -11, -4, 25, 31, -18,
-29, -24, -5, 11, 19, 27, 26, 7,
-23, -14, 5, 20, 29, 34, 5, -3,
-23, -10, 3, 21, 30, 30, 4, -4,
-26, -18, -3, 4, 15, 22, 18, 1,
-31, -20, -20, -15, -7, 19, 20, -25,
0, 0, 0, 0, 0, 0, 0, 0,
};

constexpr static std::array<int, 64> EndGamePawnTable =
{
0, 0, 0, 0, 0, 0, 0, 0,
10, 9, 3, -11, 3, 1, -3, -7,
8, 9, -1, -11, -6, -6, -1, -7,
20, 14, 1, -16, -14, -10, 6, 0,
18, 14, -2, -13, -12, -7, 4, -2,
10, 8, -3, -9, -2, -3, -1, -8,
12, 9, 7, -13, 6, 4, -1, -4,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
15, 12, 7, -15, 6, 3, -4, -11,
12, 12, 0, -14, -7, -6, -3, -11,
28, 20, 0, -22, -18, -13, 8, -1,
24, 19, -2, -17, -16, -10, 5, -4,
13, 10, -4, -13, -3, -3, -2, -11,
17, 12, 9, -15, 17, 7, -1, -7,
0, 0, 0, 0, 0, 0, 0, 0,
};

constexpr static std::array<int, 64> MiddleGameKnightTable =
{
-111, -27, -42, -31, -16, -19, -20, -71,
-36, -19, -2, 13, 14, 17, -9, -14,
-24, 2, 18, 42, 47, 33, 29, -1,
-6, 22, 33, 47, 47, 47, 34, 15,
-3, 17, 36, 37, 45, 46, 34, 13,
-22, 4, 17, 36, 45, 27, 22, -1,
-33, -9, 4, 11, 12, 12, -6, -15,
-123, -30, -41, -22, -14, -13, -26, -69,
-155, -30, -62, -43, -21, -26, -16, -97,
-46, -25, -2, 16, 18, 23, -13, -17,
-27, 4, 22, 60, 62, 43, 38, -1,
-8, 28, 45, 62, 63, 63, 50, 22,
-4, 27, 48, 50, 60, 61, 51, 21,
-25, 6, 21, 51, 61, 36, 31, -2,
-48, -16, 1, 15, 17, 17, -10, -18,
-170, -33, -59, -33, -19, -17, -24, -91,
};

constexpr static std::array<int, 64> EndGameKnightTable =
{
-57, -41, -10, -8, -7, -21, -35, -69,
-15, -2, 13, 7, 7, 6, -10, -15,
-6, 11, 25, 27, 27, 13, 5, -12,
6, 15, 37, 37, 39, 34, 16, -4,
6, 21, 35, 38, 39, 29, 21, -1,
-9, 15, 19, 33, 24, 14, 4, -9,
-24, -1, 4, 9, 4, 3, -12, -16,
-61, -40, -7, -10, -7, -17, -33, -63,
-73, -70, -11, -12, -9, -27, -63, -93,
-21, -1, 15, 9, 12, 10, -12, -20,
-13, 17, 40, 39, 38, 20, 11, -14,
8, 21, 52, 53, 57, 51, 26, -5,
5, 28, 51, 55, 59, 47, 32, 0,
-17, 20, 29, 46, 36, 22, 7, -10,
-27, 2, 5, 13, 6, 2, -14, -24,
-79, -70, -7, -14, -10, -25, -60, -93,
};

constexpr static std::array<int, 64> MiddleGameBishopTable =
{
-14, 10, -7, -19, -12, -16, -14, 5,
5, 4, 5, -13, 2, -2, 23, -5,
-4, 5, -2, 1, -5, 10, 7, 23,
-2, -6, -6, 14, 12, -13, 3, 1,
-9, 0, -10, 12, 3, -8, -3, 7,
4, 4, 5, -5, 3, 4, 8, 20,
6, 13, 9, -4, -3, -1, 17, 1,
11, 10, 3, -27, -13, -18, -4, -9,
-13, 12, -10, -26, -20, -21, -27, 3,
8, 5, 8, -18, 1, -2, 30, -11,
-5, 8, -3, 4, -6, 14, 8, 32,
-4, -4, -4, 25, 21, -16, 5, 2,
-13, 1, -12, 19, 7, -10, -3, 8,
6, 8, 8, -5, 6, 7, 10, 27,
9, 16, 13, -7, -4, 1, 22, -2,
12, 15, 3, -42, -23, -27, -5, -12,
};

constexpr static std::array<int, 64> EndGameBishopTable =
{
-8, 14, -16, 4, -4, 3, -3, -28,
-3, -4, -3, 4, 1, -8, -2, -11,
11, 12, 6, 4, 10, 5, 2, 4,
10, 8, 7, 0, -1, 7, 3, 1,
7, 7, 5, 4, -7, 2, 3, 2,
10, 3, 0, 2, 5, 0, 1, 4,
-12, -9, -14, 2, 1, 0, 0, -10,
-8, -10, -13, 4, 6, 4, -1, -16,
-14, 19, -24, 5, -2, 2, 2, -31,
-4, -7, -3, 6, 5, -9, -1, -15,
15, 16, 9, 4, 14, 5, 8, 10,
13, 9, 8, -1, -5, 8, 5, 5,
8, 10, 8, 5, -9, 6, 4, 5,
13, 4, 1, 2, 7, 1, 4, 7,
-14, -10, -16, 3, 2, -1, 0, -10,
-8, -11, -17, 8, 9, 6, 0, -21,
};

constexpr static std::array<int, 64> MiddleGameRookTable =
{
-5, -11, -11, -7, 5, -4, 2, -5,
-22, -9, -10, -10, -1, 0, 14, -3,
-22, -12, -13, -7, 5, 11, 42, 22,
-20, -13, -9, -6, 0, 5, 31, 20,
-14, -10, -5, 1, 0, 9, 23, 18,
-19, -10, -7, 0, 6, 17, 41, 26,
-21, -19, -6, -6, -1, 0, 18, -1,
-4, -6, -5, 2, 11, -1, 7, 6,
-8, -16, -13, -9, 6, -6, 2, -6,
-30, -13, -14, -15, -3, 0, 19, -6,
-31, -15, -18, -7, 8, 11, 60, 31,
-24, -18, -12, -3, 3, 13, 50, 26,
-18, -12, -5, 4, -1, 14, 40, 23,
-24, -11, -12, 1, 6, 23, 56, 33,
-28, -24, -8, -8, -2, -2, 25, 0,
-5, -8, -8, 2, 15, -1, 11, 7,
};

constexpr static std::array<int, 64> EndGameRookTable =
{
5, 7, 12, 3, -4, 4, 5, -1,
10, 15, 15, 8, -1, 2, -2, 2,
6, 4, 6, 2, -7, -8, -18, -19,
8, 4, 8, 5, -4, -1, -11, -17,
7, 5, 9, 1, -2, -7, -12, -14,
7, 10, 1, -5, -9, -11, -17, -13,
14, 17, 12, 4, -3, 0, -4, 4,
0, 0, 7, -1, -9, -1, -3, -9,
6, 8, 13, 4, -6, 6, 6, -4,
16, 20, 20, 9, -1, 2, -4, 4,
9, 7, 10, 3, -9, -9, -23, -21,
12, 10, 11, 5, -4, -1, -17, -20,
12, 8, 12, 2, -1, -7, -14, -15,
12, 13, 2, -6, -11, -13, -21, -15,
21, 23, 16, 5, -3, 1, -5, 5,
0, 1, 8, -1, -13, -1, -4, -14,
};

constexpr static std::array<int, 64> MiddleGameQueenTable =
{
-13, -15, -16, -2, -9, -27, 1, -2,
4, -5, 6, 0, 3, 5, 15, 38,
-2, -2, -3, -3, -6, 8, 28, 42,
-4, -12, -9, -4, -5, 0, 13, 22,
-6, -8, -11, -11, -5, 1, 7, 17,
-1, -1, -8, -6, -1, 4, 18, 28,
-7, -15, 3, 8, 5, 0, 9, 29,
-10, -20, -10, 1, -6, -35, -14, 11,
-16, -20, -20, -2, -11, -41, 5, 0,
0, -8, 9, -1, 3, 3, 23, 49,
-5, -1, -5, -5, -8, 10, 39, 62,
-9, -14, -13, -3, -4, 2, 17, 29,
-9, -9, -13, -14, -4, 1, 15, 26,
-2, 0, -12, -9, -3, 7, 24, 42,
-15, -18, 5, 9, 7, 0, 7, 36,
-12, -22, -10, 0, -9, -49, -20, 27,
};

constexpr static std::array<int, 64> EndGameQueenTable =
{
-18, -10, 0, -8, -4, -3, -28, 1,
-19, -14, -19, -2, -1, -13, -32, -4,
-13, -4, -1, -2, 14, 14, -10, 6,
-11, 5, -5, 7, 17, 24, 29, 22,
0, 0, 6, 16, 14, 18, 18, 33,
-12, -8, 8, 6, 10, 17, 12, 15,
-11, -6, -15, -14, -5, -3, -27, 3,
-7, -4, -1, -8, 3, 21, 13, -6,
-24, -15, -1, -13, -8, -3, -36, 12,
-19, -14, -28, -1, -1, -14, -47, 0,
-17, -7, 0, -5, 18, 21, -10, 4,
-11, 4, 0, 5, 22, 35, 45, 35,
-1, -1, 9, 21, 19, 28, 23, 48,
-19, -15, 11, 9, 14, 21, 21, 19,
-12, -8, -25, -17, -11, -7, -32, 10,
-11, -8, -8, -6, 2, 29, 21, -6,
};

constexpr static std::array<int, 64> MiddleGameKingTable =
{
19, 27, 4, -74, -15, -64, 14, 32,
-16, -22, -39, -70, -79, -59, -21, 2,
-80, -74, -107, -110, -114, -123, -86, -91,
-116, -115, -135, -165, -160, -149, -150, -173,
-81, -97, -126, -154, -158, -128, -150, -157,
-71, -45, -101, -110, -94, -103, -77, -81,
56, -17, -37, -62, -63, -49, -8, 10,
28, 45, 11, -64, -4, -54, 27, 43,
44, 57, 27, -83, 6, -66, 45, 65,
1, -8, -29, -70, -83, -58, -3, 28,
-81, -68, -113, -117, -129, -135, -86, -99,
-119, -121, -139, -181, -171, -160, -159, -190,
-82, -86, -129, -160, -174, -144, -162, -181,
-76, -40, -106, -116, -100, -114, -77, -90,
89, 2, -30, -60, -64, -45, 12, 37,
59, 85, 40, -67, 17, -55, 60, 79,
};

constexpr static std::array<int, 64> EndGameKingTable =
{
-58, -32, -11, 10, -20, 5, -22, -63,
-8, 19, 29, 40, 46, 34, 17, -8,
10, 40, 56, 65, 67, 61, 43, 25,
19, 52, 72, 87, 83, 75, 64, 44,
9, 45, 69, 83, 86, 73, 66, 41,
8, 35, 55, 65, 62, 56, 43, 22,
-29, 13, 28, 37, 39, 31, 13, -13,
-66, -39, -14, 5, -17, 2, -26, -67,
-87, -50, -24, 4, -43, -2, -40, -96,
-22, 16, 29, 43, 51, 36, 14, -24,
6, 43, 64, 76, 80, 71, 47, 25,
16, 60, 84, 102, 98, 89, 75, 47,
3, 49, 82, 98, 103, 88, 78, 45,
5, 39, 63, 77, 73, 66, 47, 20,
-47, 9, 30, 40, 43, 32, 9, -28,
-100, -62, -30, -3, -35, -6, -44, -101,
};

constexpr static std::array<std::array<int, 64>, 6> MiddleGamePositionalWhiteTables =
Expand Down
3 changes: 3 additions & 0 deletions src/lynx-sources.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Path, WDL from side playing, position limit
/datasets/lichess-big3-resolved.book,0,7000000
/datasets/stash_gedas.epd,0,777777
21 changes: 12 additions & 9 deletions src/tuner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,11 @@ static void parse_fen(const bool side_to_move_wdl, const parameters_t& parameter
auto fen = board.getFen();
eval_result = TuneEval::get_fen_eval_result(fen);

if constexpr (print_eval)
{
std::cout << fen << ": " << TuneEval::NormalizeScore(eval_result.score) << std::endl;
}
}

if constexpr (print_eval)
{
std::cout << original_fen << ": " << TuneEval::NormalizeScore(eval_result.score) << std::endl;
}


Expand Down Expand Up @@ -803,11 +804,11 @@ void Tuner::run(const std::vector<DataSource>& sources)
auto parameters = TuneEval::get_initial_parameters();
cout << "Got " << parameters.size() << " parameters" << endl;

if constexpr (!print_eval)
{
cout << "Initial parameters:" << endl;
TuneEval::print_parameters(parameters);
}
if constexpr (!print_eval)
{
cout << "Initial parameters:" << endl;
TuneEval::print_parameters(parameters);
}

vector<Entry> entries;

Expand All @@ -828,10 +829,12 @@ if constexpr (!print_eval)
cout << "Data loading complete" << endl << endl;

print_statistics(parameters, entries);

if constexpr (print_eval)
{
return;
}

if constexpr (retune_from_zero)
{
for (auto& parameter : parameters)
Expand Down

0 comments on commit d980578

Please sign in to comment.