Skip to content
DeepForgeby svx
All problems

Masked Action Selection

Problem

Select the highest-value valid action without changing the Q values.

Return the index of the maximum Q value among actions where valid is True, breaking ties toward the smallest index. If no action is valid return -1.

Hint

Selecting among valid actions avoids the large negative bias of masked Q values.

Test cases

case 1
in: [[1,5,3],[true,false,true]]
expected: 2
case 2
in: [[1,5,3],[false,false,true]]
expected: 2
case 3
in: [[2,2],[true,true]]
expected: 0
case 4
in: [[1],[false]]
expected: -1
Starter codePython
def masked_argmax(q_values, valid):
    # Your code here
    pass

4 test cases · run your code against them in the editor