Skip to content

Commit

Permalink
Update score normalization (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio authored Nov 15, 2023
1 parent c409704 commit 05b35dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
22 changes: 11 additions & 11 deletions src/Lynx/EvaluationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ namespace Lynx;
public static class EvaluationConstants
{
/// <summary>
/// 30k games, 16+0.16, UHO_XXL_+0.90_+1.19.epd
/// Retained (W,D,L) = (791773, 1127929, 793778) positions.
/// 21454 games, 16+0.16, UHO_XXL_+0.90_+1.19.epd
/// Retained (W,D,L) = (486074, 1108791, 487345) positions.
/// </summary>
public const int EvalNormalizationCoefficient = 78;
public const int EvalNormalizationCoefficient = 138;

public static readonly double[] As = [-44.54789428, 284.90322556, -305.65458204, 143.86777995];
public static readonly double[] As = [-25.59900221, 175.23377472, -145.09355540, 133.49051930];

public static readonly double[] Bs = [-21.08101051, 127.81742295, -160.22340655, 128.53122955];
public static readonly double[] Bs = [-14.14613328, 84.98205725, -101.16332276, 120.88906952];

public static readonly int[] GamePhaseByPiece =
[
0, 1, 1, 2, 4, 0,
0, 1, 1, 2, 4, 0
];

public static readonly int[] MiddleGamePieceValues =
[
Expand All @@ -30,12 +36,6 @@ public static class EvaluationConstants
-109, -356, -324, -653, -1123, 0
];

public static readonly int[] GamePhaseByPiece =
[
0, 1, 1, 2, 4, 0,
0, 1, 1, 2, 4, 0
];

public static readonly int[] MiddleGamePawnTable =
[
0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
18 changes: 14 additions & 4 deletions tests/Lynx.Test/WDLTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ public void NormalizeCoefficientAndArrayValues()
Assert.AreEqual(EvaluationConstants.EvalNormalizationCoefficient, (int)EvaluationConstants.As.Sum());
}

[TestCase(500, 641)]
[TestCase(1000, 1282)]
[TestCase(500)]
[TestCase(1000)]
public void NormalizeScore(int score)
{
Assert.AreEqual(score * 100 / EvaluationConstants.EvalNormalizationCoefficient, WDL.NormalizeScore(score));
}

[TestCase(0, 0)]
[TestCase(EvaluationConstants.PositiveCheckmateDetectionLimit + 5, EvaluationConstants.PositiveCheckmateDetectionLimit + 5)]
[TestCase(EvaluationConstants.NegativeCheckmateDetectionLimit - 5, EvaluationConstants.NegativeCheckmateDetectionLimit - 5)]
Expand All @@ -26,8 +31,13 @@ public void NormalizeScore(int score, int expectecNormalizedEval)
Assert.AreEqual(expectecNormalizedEval, WDL.NormalizeScore(score));
}

[TestCase(1000, 780)]
[TestCase(2000, 1560)]
[TestCase(1000)]
[TestCase(2000)]
public void UnNormalizeScore(int score)
{
Assert.AreEqual(score * EvaluationConstants.EvalNormalizationCoefficient / 100, WDL.UnNormalizeScore(score));
}

[TestCase(0, 0)]
[TestCase(EvaluationConstants.PositiveCheckmateDetectionLimit + 5, EvaluationConstants.PositiveCheckmateDetectionLimit + 5)]
[TestCase(EvaluationConstants.NegativeCheckmateDetectionLimit - 5, EvaluationConstants.NegativeCheckmateDetectionLimit - 5)]
Expand Down

0 comments on commit 05b35dc

Please sign in to comment.