Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chess input representation v2.8 #125

Merged
merged 3 commits into from
May 30, 2021
Merged

Chess input representation v2.8 #125

merged 3 commits into from
May 30, 2021

Conversation

QueensGambit
Copy link
Owner

@QueensGambit QueensGambit commented May 30, 2021

This PR adds 5 material count planes to the input representation of 2.7 (#122).

Feature Planes Description
P1 piece 6 (pieces are ordered: PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING)
P2 piece 6 (pieces are ordered: PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING)
En-passant square 1 (Binary map indicating the square where en-passant capture is possible)
P1 castling 2 (One if castling is possible, else zero)
P2 castling 2 (One if castling is possible, else zero)
Last Moves 2 Last move played
is960 1 indicate if 960 is active
P1 pieces 1 A grouped mask of all P1 pieces
P2 pieces 1 A grouped mask of all P2 pieces
Chessboard 1 A chess board pattern
P1 Material Diff 5 (pieces are ordered: PAWN, KNIGHT, BISHOP, ROOK, QUEEN), normalized with 8, + means positive, - means negative
Opposite Color Bishops 1 Indicates if they are only two bishops and the bishops are opposite color
Checkers 1 Indicates all pieces giving check
Checking Moves 2 Indicates all checking moves (from sq, to sq)
P1 Mobility 1 Gives the number of legal moves for the active player
P1 Material Count 5 (pieces are ordered: PAWN, KNIGHT, BISHOP, ROOK, QUEEN), normalized with 8

Total Planes: 38

Constants

NORMALIZE_MOBILITY = 64
NORMALIZE_PIECE_NUMBER = 8
# These constant describe the starting channel for the corresponding info
CHANNEL_PIECES = 0
CHANNEL_EN_PASSANT = 12
CHANNEL_CASTLING = 13
CHANNEL_LAST_MOVES = 17
CHANNEL_IS_960 = 19
CHANNEL_PIECE_MASK = 20
CHANNEL_CHECKERBOARD = 22
CHANNEL_MATERIAL = 23
CHANNEL_OPP_BISHOPS = 28
CHANNEL_CHECKERS = 29
CHANNEL_CHECK_MOVES = 30
CHANNEL_MOBILITY = 32
CHANNEL_MATERIAL_COUNT = 33

Adding material count features appears to both help the value and policy loss.

Model Info

kernels = [3] * 7

se_types = [None] * len(kernels)
se_types[5] = "eca_se"

symbol = rise_mobile_v3_symbol(channels=256, channels_operating_init=224, channel_expansion=32, act_type='relu',
                               channels_value_head=8, value_fc_size=256,
                               channels_policy_head=NB_POLICY_MAP_CHANNELS,
                               grad_scale_value=tc.val_loss_factor, grad_scale_policy=tc.policy_loss_factor, 
                               dropout_rate=tc.dropout_rate, select_policy_from_plane=True,
                               kernels=kernels, se_types=se_types, use_avg_features=False)

Performance

Representation 2.7

print(val_metric_values_best)
{'value_loss': 0.5191286853872813, 'policy_loss': 1.9544962583444057, 'value_acc_sign': 0.6256210535194651, 'policy_acc': 0.4121719751602564, 'loss': 1.9401425826148344}
metrics = metrics_gluon
evaluate_metrics(metrics, test_data, net, nb_batches=None, sparse_policy_label=True, ctx=ctx,
                 apply_select_policy_from_plane=tc.select_policy_from_plane)

{'loss': 1.948354888682973,
 'value_loss': 0.5401958049762816,
 'policy_loss': 1.9625787178113232,
 'value_acc_sign': 0.6418024494760046,
 'policy_acc': 0.4118828864816599}

Representation 2.8

print(val_metric_values_best)
{'value_loss': 0.5170979887629167, 'policy_loss': 1.9267710447311401, 'value_acc_sign': 0.632907013273931, 'policy_acc': 0.42357772435897434, 'loss': 1.912674314171458}
metrics = metrics_gluon
evaluate_metrics(metrics, test_data, net, nb_batches=None, sparse_policy_label=True, ctx=ctx,
                 apply_select_policy_from_plane=tc.select_policy_from_plane)
{'loss': 1.9227169821895014,
 'value_loss': 0.5378539902823312,
 'policy_loss': 1.936705497259271,
 'value_acc_sign': 0.6454561619801322,
 'policy_acc': 0.42199873111356534}

@QueensGambit QueensGambit merged commit d4c45d2 into master May 30, 2021
@QueensGambit QueensGambit deleted the input_v2_8 branch June 30, 2021 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant