Convert root visit counts into the search policy used to select a self-play move. For positive temperature τ, each legal action a receives
πa=∑b∈LNb1/τNa1/τ.Here πa is the search probability, Na is the visit count, τ is temperature, and L is the legal-action set; b ranges over that set. At positive temperature, if every legal visit count is zero, use a uniform legal policy. At temperature zero, use a one-hot policy at the lowest-index legal action with the largest count. At positive temperature, select the first action whose cumulative probability is strictly greater than the supplied uniform random draw. Return a two-item tuple: the NumPy float64 policy array with the same shape as visits, followed by the selected action as a Python integer.
Input: visits = [1,3,0], legal_mask = [true,true,true], temperature = 1, uniform_draw = 0.2
Output: ([0.25,0.75,0], 0)
Explanation: Temperature one normalizes visits directly, and draw 0.2 lies in the first cumulative interval.
Input: visits = [4,4,2], legal_mask = [true,true,true], temperature = 0, uniform_draw = null
Output: ([1,0,0], 0)
Input: visits = [1,2,3], legal_mask = [true,true,true], temperature = 0.5, uniform_draw = 0.4
Output: ([0.071429,0.285714,0.642857], 2)
np.flatnonzero and np.argmax preserve the first-maximum tie break.
Logarithms can keep positive-count weights stable at small temperatures.
np.searchsorted with side="right" handles strict cumulative boundaries.
Accepts: array
Accepts: array
Accepts: number
Accepts: any
Convert root visit counts into the search policy used to select a self-play move. For positive temperature τ, each legal action a receives
πa=∑b∈LNb1/τNa1/τ.Here πa is the search probability, Na is the visit count, τ is temperature, and L is the legal-action set; b ranges over that set. At positive temperature, if every legal visit count is zero, use a uniform legal policy. At temperature zero, use a one-hot policy at the lowest-index legal action with the largest count. At positive temperature, select the first action whose cumulative probability is strictly greater than the supplied uniform random draw. Return a two-item tuple: the NumPy float64 policy array with the same shape as visits, followed by the selected action as a Python integer.
Input: visits = [1,3,0], legal_mask = [true,true,true], temperature = 1, uniform_draw = 0.2
Output: ([0.25,0.75,0], 0)
Explanation: Temperature one normalizes visits directly, and draw 0.2 lies in the first cumulative interval.
Input: visits = [4,4,2], legal_mask = [true,true,true], temperature = 0, uniform_draw = null
Output: ([1,0,0], 0)
Input: visits = [1,2,3], legal_mask = [true,true,true], temperature = 0.5, uniform_draw = 0.4
Output: ([0.071429,0.285714,0.642857], 2)
np.flatnonzero and np.argmax preserve the first-maximum tie break.
Logarithms can keep positive-count weights stable at small temperatures.
np.searchsorted with side="right" handles strict cumulative boundaries.
Accepts: array
Accepts: array
Accepts: number
Accepts: any