All problems
SAC Alpha Loss
Problem
Compute the SAC temperature (alpha) loss for a batch of action log-probabilities.
J(alpha) = -alpha * (mean(log_probs) + target_entropy). An empty batch returns 0.0.
Hint
The temperature is adjusted so the mean entropy matches the target entropy.
Test cases
case 1
in: [0.2,[-0.5,-1],-1]
expected: 0.35000000000000003
case 2
in: [0.2,[-0.5,-1],-2]
expected: 0.55
case 3
in: [1,[-0.3],-1]
expected: 1.3
case 4
in: [0,[-0.5,-1],-2]
expected: 0
case 5
in: [0.5,[],-1]
expected: 0
Starter codePython
def sac_alpha_loss(alpha, log_probs, target_entropy):
# Your code here
pass5 test cases · run your code against them in the editor