Implement the combined policy and value loss used to train an AlphaZero-style network for self-play board games.
The network produces two outputs for each input position:
p_logits of shape (batch, num_actions) -- raw scores over moves.v_pred of shape (batch,) -- a scalar estimate of the game outcome from the current player's perspective in [-1, 1].Training targets come from self-play with MCTS:
pi of shape (batch, num_actions) -- visit-count distribution from MCTS (each row sums to 1).z of shape (batch,) -- final game outcome in {-1, 0, 1}.The loss combines a mean-squared-error value term and a cross-entropy policy term:
Use a numerically stable log-softmax (subtract the per-row max before exponentiating). Return the loss as a single Python float (or 0-d numpy scalar). Do not include an L2 weight regularization term.
Inputs are numpy arrays; output is a scalar.