TensorTonic
Study Plans
Study Plan
Select an Action with PUCT
Reinforcement Learning
Easy

PUCT balances the current action value with exploration. For edge aaa with visit count NaN_aNa​ and total value WaW_aWa​, define

Qa={0,Na=0Wa/Na,Na>0.Q_a=\begin{cases} 0,&N_a=0\\ W_a/N_a,&N_a>0. \end{cases}Qa​={0,Wa​/Na​,​Na​=0Na​>0.​

Let T=∑bNbT=\sum_b N_bT=∑b​Nb​ be the node visit total. With prior PaP_aPa​ and exploration constant c supplied as cpuct, compute

Sa=Qa+cPaT1+Na.S_a=Q_a+cP_a\frac{\sqrt{T}}{1+N_a}.Sa​=Qa​+cPa​1+Na​T​​.

Here SaS_aSa​ is the selection score. Illegal actions receive negative infinity. If scores tie, select the lowest legal action index. Return a two-item tuple containing the selected Python integer and the complete 64-bit floating-point NumPy score array.

Loading visualization...

Examples

Input: visits = [0,0,0], total_values = [0,0,0], priors = [0.1,0.7,0.2], legal_mask = [true,true,true], cpuct = 1.5

Output: (0, [0,0,0])

Explanation: The total visit count is zero, so every exploration bonus is zero and the lowest-index action wins the tie.

Input: visits = [4,1,0], total_values = [2,0.8,0], priors = [0.2,0.3,0.5], legal_mask = [true,true,true], cpuct = 1

Output: (1, [0.589443,1.135410,1.118034])

Input: visits = [8,2,2], total_values = [8,0.5,0.5], priors = [0,0.5,0.5], legal_mask = [false,true,true], cpuct = 2

Output: (1, [-Infinity,1.404701,1.404701])

Hint 1

np.divide supports a where mask for unvisited edges.

Hint 2

np.full can initialize illegal scores to negative infinity.

Hint 3

np.argmax returns the first maximum; int() gives a Python integer.

Requirements

  • Use NumPy float64 computation and score output.
  • Use the supplied visit-count sum without adding one.
  • Preserve every input array.

Constraints

  • Visit counts, total values, priors, and the legal mask are aligned, nonempty one-dimensional NumPy arrays.
  • Visit counts are nonnegative integers and total values are finite.
  • Priors are normalized over legal actions and are zero for illegal actions.
  • The legal mask has Boolean dtype and contains at least one legal action.
  • The exploration constant is positive and finite.
Try Similar Problems
Initialize Legal MCTS Edge StatisticsEasyBack Up an MCTS Simulation PathMediumFind a Go Group and Its LibertiesEasyMix Dirichlet Noise into Root PriorsEasySample a Recent Self-Play Replay BatchEasyTurn Root Visits into a Search PolicyMediumCompute the Policy and Value HeadsMediumApply an AlphaGo Residual BlockMediumEpsilon-Greedy Action SelectionEasyDouble DQN TargetEasySoftmax (Boltzmann) ExplorationEasyQ-Learning UpdateEasy

Accepts: array

Accepts: array

Accepts: array

Accepts: array

Accepts: number

You must run your code first.

Select an Action with PUCT

Reinforcement Learning
Easy

PUCT balances the current action value with exploration. For edge aaa with visit count NaN_aNa​ and total value WaW_aWa​, define

Qa={0,Na=0Wa/Na,Na>0.Q_a=\begin{cases} 0,&N_a=0\\ W_a/N_a,&N_a>0. \end{cases}Qa​={0,Wa​/Na​,​Na​=0Na​>0.​

Let T=∑bNbT=\sum_b N_bT=∑b​Nb​ be the node visit total. With prior PaP_aPa​ and exploration constant c supplied as cpuct, compute

Sa=Qa+cPaT1+Na.S_a=Q_a+cP_a\frac{\sqrt{T}}{1+N_a}.Sa​=Qa​+cPa​1+Na​T​​.

Here SaS_aSa​ is the selection score. Illegal actions receive negative infinity. If scores tie, select the lowest legal action index. Return a two-item tuple containing the selected Python integer and the complete 64-bit floating-point NumPy score array.

Loading visualization...

Examples

Input: visits = [0,0,0], total_values = [0,0,0], priors = [0.1,0.7,0.2], legal_mask = [true,true,true], cpuct = 1.5

Output: (0, [0,0,0])

Explanation: The total visit count is zero, so every exploration bonus is zero and the lowest-index action wins the tie.

Input: visits = [4,1,0], total_values = [2,0.8,0], priors = [0.2,0.3,0.5], legal_mask = [true,true,true], cpuct = 1

Output: (1, [0.589443,1.135410,1.118034])

Input: visits = [8,2,2], total_values = [8,0.5,0.5], priors = [0,0.5,0.5], legal_mask = [false,true,true], cpuct = 2

Output: (1, [-Infinity,1.404701,1.404701])

Hint 1

np.divide supports a where mask for unvisited edges.

Hint 2

np.full can initialize illegal scores to negative infinity.

Hint 3

np.argmax returns the first maximum; int() gives a Python integer.

Requirements

  • Use NumPy float64 computation and score output.
  • Use the supplied visit-count sum without adding one.
  • Preserve every input array.

Constraints

  • Visit counts, total values, priors, and the legal mask are aligned, nonempty one-dimensional NumPy arrays.
  • Visit counts are nonnegative integers and total values are finite.
  • Priors are normalized over legal actions and are zero for illegal actions.
  • The legal mask has Boolean dtype and contains at least one legal action.
  • The exploration constant is positive and finite.
Try Similar Problems
Initialize Legal MCTS Edge StatisticsEasyBack Up an MCTS Simulation PathMediumFind a Go Group and Its LibertiesEasyMix Dirichlet Noise into Root PriorsEasySample a Recent Self-Play Replay BatchEasyTurn Root Visits into a Search PolicyMediumCompute the Policy and Value HeadsMediumApply an AlphaGo Residual BlockMediumEpsilon-Greedy Action SelectionEasyDouble DQN TargetEasySoftmax (Boltzmann) ExplorationEasyQ-Learning UpdateEasy

Accepts: array

Accepts: array

Accepts: array

Accepts: array

Accepts: number

You must run your code first.