Skip to content

Commit 3f02330

Browse files
committed
Update WDL Model (#92)
6x More data from various non-regression tests mainly relating to resizable hash. https://chess.aronpetkovski.com/test/1225/ https://chess.aronpetkovski.com/test/1250/ https://chess.aronpetkovski.com/test/1261/ https://chess.aronpetkovski.com/test/1263/ https://chess.aronpetkovski.com/test/1277/ https://chess.aronpetkovski.com/test/1357/ ![scoreWDL](https://github.com/xu-shawn/Serendipity/assets/50402888/8014eb2f-70be-4ac2-9143-7b84b8fab95d) ``` ❯ python3 scoreWDL.py --NormalizeData '{"momType": "material", "momMin": 17, "momMax": 78, "momTarget": 58, "as": [-40.00676365, 98.77222217, -182.08209988, 340.61197659]}' Converting evals with NormalizeData = {'momType': 'material', 'momMin': 17, 'momMax': 78, 'momTarget': 58, 'as': [-40.00676365, 98.77222217, -182.08209988, 340.61197659]}. Reading eval stats from scoreWDLstat.json. Retained (W,D,L) = (824989, 1928200, 825371) positions. Fit WDL model based on material. Initial objective function: 0.6350481731497092 Final objective function: 0.6350379750816926 Optimization terminated successfully. const int NormalizeToPawnValue = 236; Corresponding spread = 132; Corresponding normalized spread = 0.558809843707221; Draw rate at 0.0 eval at material 58 = 0.7137362232663982; Parameters in internal value units: p_a = ((-117.298 * x / 58 + 388.530) * x / 58 + -512.962) * x / 58 + 477.991 p_b = ((-47.751 * x / 58 + 118.817) * x / 58 + -33.058) * x / 58 + 94.017 constexpr double as[] = {-117.29796837, 388.52982654, -512.96172771, 477.99147478}; constexpr double bs[] = {-47.75093113, 118.81734426, -33.05800930, 94.01690687}; ``` bench 2164850
1 parent 4caacd2 commit 3f02330

File tree

1 file changed

+29
-29
lines changed
  • Serendipity/src/main/java/org/shawn/games/Serendipity

1 file changed

+29
-29
lines changed

Serendipity/src/main/java/org/shawn/games/Serendipity/WDLModel.java

+29-29
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,67 @@
55

66
public class WDLModel
77
{
8-
private final static double[] as = {-40.00676365, 98.77222217, -182.08209988, 340.61197659};
9-
private final static double[] bs = {62.18462409, -195.09918531, 258.58208433, 1.29372611};
10-
8+
private final static double[] as = { -117.29796837, 388.52982654, -512.96172771, 477.99147478 };
9+
private final static double[] bs = { -47.75093113, 118.81734426, -33.05800930, 94.01690687 };
10+
1111
@SuppressWarnings("unused")
12-
private final static int NormalizeToPawnValue = 217;
12+
private final static int NormalizeToPawnValue = 236;
1313

1414
private final static int PAWN_VALUE = 1;
1515
private final static int KNIGHT_VALUE = 3;
1616
private final static int BISHOP_VALUE = 3;
1717
private final static int ROOK_VALUE = 5;
1818
private final static int QUEEN_VALUE = 9;
19-
19+
2020
private static int countMaterial(Board board)
2121
{
2222
return Long.bitCount(board.getBitboard(Piece.WHITE_PAWN)) * PAWN_VALUE
23-
+ Long.bitCount(board.getBitboard(Piece.WHITE_KNIGHT)) * KNIGHT_VALUE
24-
+ Long.bitCount(board.getBitboard(Piece.WHITE_BISHOP)) * BISHOP_VALUE
25-
+ Long.bitCount(board.getBitboard(Piece.WHITE_ROOK)) * ROOK_VALUE
26-
+ Long.bitCount(board.getBitboard(Piece.WHITE_QUEEN)) * QUEEN_VALUE
27-
+ Long.bitCount(board.getBitboard(Piece.BLACK_PAWN)) * PAWN_VALUE
28-
+ Long.bitCount(board.getBitboard(Piece.BLACK_KNIGHT)) * KNIGHT_VALUE
29-
+ Long.bitCount(board.getBitboard(Piece.BLACK_BISHOP)) * BISHOP_VALUE
30-
+ Long.bitCount(board.getBitboard(Piece.BLACK_ROOK)) * ROOK_VALUE
31-
+ Long.bitCount(board.getBitboard(Piece.BLACK_QUEEN)) * QUEEN_VALUE;
23+
+ Long.bitCount(board.getBitboard(Piece.WHITE_KNIGHT)) * KNIGHT_VALUE
24+
+ Long.bitCount(board.getBitboard(Piece.WHITE_BISHOP)) * BISHOP_VALUE
25+
+ Long.bitCount(board.getBitboard(Piece.WHITE_ROOK)) * ROOK_VALUE
26+
+ Long.bitCount(board.getBitboard(Piece.WHITE_QUEEN)) * QUEEN_VALUE
27+
+ Long.bitCount(board.getBitboard(Piece.BLACK_PAWN)) * PAWN_VALUE
28+
+ Long.bitCount(board.getBitboard(Piece.BLACK_KNIGHT)) * KNIGHT_VALUE
29+
+ Long.bitCount(board.getBitboard(Piece.BLACK_BISHOP)) * BISHOP_VALUE
30+
+ Long.bitCount(board.getBitboard(Piece.BLACK_ROOK)) * ROOK_VALUE
31+
+ Long.bitCount(board.getBitboard(Piece.BLACK_QUEEN)) * QUEEN_VALUE;
3232
}
33-
33+
3434
private static double[] calculateParameters(Board board)
3535
{
3636
int material = countMaterial(board);
37-
37+
3838
material = Math.max(material, 17);
3939
material = Math.min(material, 78);
40-
40+
4141
double m = material / 58.0;
42-
42+
4343
double a = (((as[0] * m + as[1]) * m + as[2]) * m) + as[3];
44-
double b = (((bs[0] * m + bs[1]) * m + bs[2]) * m) + bs[3];
45-
46-
return new double[]{a, b};
44+
double b = (((bs[0] * m + bs[1]) * m + bs[2]) * m) + bs[3];
45+
46+
return new double[] { a, b };
4747
}
48-
48+
4949
private static int calculateWinRate(int v, Board board)
5050
{
5151
double[] parameters = calculateParameters(board);
52-
53-
return (int)(0.5 + 1000 / (1 + Math.exp((parameters[0] - (double) v) / parameters[1])));
52+
53+
return (int) (0.5 + 1000 / (1 + Math.exp((parameters[0] - (double) v) / parameters[1])));
5454
}
55-
55+
5656
public static int[] calculateWDL(int v, Board board)
5757
{
5858
int winRate = calculateWinRate(v, board);
5959
int lossRate = calculateWinRate(-v, board);
6060
int drawRate = 1000 - winRate - lossRate;
61-
62-
return new int[] {winRate, drawRate, lossRate};
61+
62+
return new int[] { winRate, drawRate, lossRate };
6363
}
64-
64+
6565
public static int normalizeEval(int v, Board board)
6666
{
6767
double a = calculateParameters(board)[0];
68-
68+
6969
return (int) Math.round((100 * v) / a);
7070
}
7171
}

0 commit comments

Comments
 (0)