A newly expanded search node needs one edge per action. Only legal actions receive prior probability. For legal policy logit la and largest legal logit m, compute
Pa=∑b∈Lexp(lb−m)exp(la−m).Here L is the set of legal actions and Pa is the prior for action a. Illegal actions receive prior zero. Every edge starts with visit count N, total value W, and mean value Q equal to zero. Return a dictionary with keys N, W, Q, and P. N is a NumPy int64 array; W, Q, and P are NumPy float64 arrays. All four are one-dimensional and aligned with the input actions.
Input: policy_logits = [0,0,0], legal_mask = [true,false,true]
Output: {"N":[0,0,0],"W":[0,0,0],"Q":[0,0,0],"P":[0.5,0,0.5]}
Explanation: The illegal middle action is excluded before the two equal legal logits are normalized.
Input: policy_logits = [1000,-1000,999], legal_mask = [true,false,true]
Output: {"N":[0,0,0],"W":[0,0,0],"Q":[0,0,0],"P":[0.731059,0,0.268941]}
Input: policy_logits = [5,2,-3], legal_mask = [false,false,true]
Output: {"N":[0,0,0],"W":[0,0,0],"Q":[0,0,0],"P":[0,0,1]}
np.flatnonzero finds the legal action indices.
np.zeros supports an explicit dtype for each statistic.
np.exp can operate on just the selected legal logits.
Accepts: array
Accepts: array
A newly expanded search node needs one edge per action. Only legal actions receive prior probability. For legal policy logit la and largest legal logit m, compute
Pa=∑b∈Lexp(lb−m)exp(la−m).Here L is the set of legal actions and Pa is the prior for action a. Illegal actions receive prior zero. Every edge starts with visit count N, total value W, and mean value Q equal to zero. Return a dictionary with keys N, W, Q, and P. N is a NumPy int64 array; W, Q, and P are NumPy float64 arrays. All four are one-dimensional and aligned with the input actions.
Input: policy_logits = [0,0,0], legal_mask = [true,false,true]
Output: {"N":[0,0,0],"W":[0,0,0],"Q":[0,0,0],"P":[0.5,0,0.5]}
Explanation: The illegal middle action is excluded before the two equal legal logits are normalized.
Input: policy_logits = [1000,-1000,999], legal_mask = [true,false,true]
Output: {"N":[0,0,0],"W":[0,0,0],"Q":[0,0,0],"P":[0.731059,0,0.268941]}
Input: policy_logits = [5,2,-3], legal_mask = [false,false,true]
Output: {"N":[0,0,0],"W":[0,0,0],"Q":[0,0,0],"P":[0,0,1]}
np.flatnonzero finds the legal action indices.
np.zeros supports an explicit dtype for each statistic.
np.exp can operate on just the selected legal logits.
Accepts: array
Accepts: array