model.network

model.network

ResNet policy-value network for backgammon.

Classes

Name Description
RaccoonNet ResNet with policy and value heads for backgammon.
ResidualBlock Conv3x3 -> BN -> ReLU -> Conv3x3 -> BN -> skip add -> ReLU.

RaccoonNet

model.network.RaccoonNet(
    in_channels=26,
    board_h=2,
    board_w=12,
    num_actions=1352,
    channels=128,
    num_blocks=6,
    feature_channels=None,
    input_bn=False,
    value_head='scalar',
    trunk='resnet',
    hidden=256,
    hidden_layers=1,
    mlp_input='flat',
)

ResNet with policy and value heads for backgammon.

Methods

Name Description
forward Forward pass.
predict Single-position inference for MCTS.
predict_batch Batched inference for multiple positions.
value_equity Scalar equity/3 in [-1, 1] per position, for both head types.
value_probs6 The full six-outcome distribution, shape (batch, 6).
forward
model.network.RaccoonNet.forward(x)

Forward pass.

Args: x: (batch, in_channels, 2, 12)

Returns: policy_logits: (batch, 1352) raw logits (not masked) value: “scalar” head -> (batch, 1) tanh in [-1, 1]; “outcomes6” head -> (batch, 6) raw logits (softmax applied by the caller / value_equity).

predict
model.network.RaccoonNet.predict(obs, legal_actions)

Single-position inference for MCTS.

Args: obs: (C, 2, 12) numpy array (C = in_channels) legal_actions: list of valid action indices

Returns: policy: dict mapping action -> probability (sums to ~1, only legal) value: scalar float in [-1, 1]

predict_batch
model.network.RaccoonNet.predict_batch(obs_list, legal_actions_list)

Batched inference for multiple positions.

Args: obs_list: list of (C, 2, 12) numpy arrays (C = in_channels) legal_actions_list: list of legal action lists

Returns: list of (policy_dict, value) tuples

value_equity
model.network.RaccoonNet.value_equity(x)

Scalar equity/3 in [-1, 1] per position, for both head types.

This is what 0-ply move selection reads (see lookahead.eval_values_batch), so a scalar net and an outcomes6 net are interchangeable at play time.

value_probs6
model.network.RaccoonNet.value_probs6(x)

The full six-outcome distribution, shape (batch, 6).

Order is [win, win_gammon, win_bg, lose, lose_gammon, lose_bg]: mutually exclusive, summing to 1. The doubling cube needs the whole distribution rather than the single number it collapses to, because a double or a take turns on the gammon rates that value_equity has already folded away. See raccoon.cube.janowski.probs6_to_cumulative5 for the conversion into the nested 5-vector the cube formulas expect.

ResidualBlock

model.network.ResidualBlock(channels)

Conv3x3 -> BN -> ReLU -> Conv3x3 -> BN -> skip add -> ReLU.

Functions

Name Description
load_model Create a RaccoonNet from a checkpoint, using its saved config.

load_model

model.network.load_model(path)

Create a RaccoonNet from a checkpoint, using its saved config.

Falls back to default config for older checkpoints without config.