Skip to content
DeepForgeby svx
All problems

SAC Log Prob Tanh Correction

Problem

Correct a Gaussian log-probability for tanh squashing.

Subtract the sum of log(1 - tanh(u)^2) over the pre-tanh actions, using the stable identity 2*(ln 2 - u - ln(1 + exp(-2u))) for each u.

Hint

The change-of-variables term keeps the squashed density normalized.

Test cases

case 1
in: [0,[0]]
expected: 0
case 2
in: [0,[1]]
expected: 0.8675616609660544
case 3
in: [-1,[0.5,-0.5]]
expected: -0.51954197216689
case 4
in: [0,[]]
expected: 0
Starter codePython
import math
def sac_tanh_log_prob(base_log_prob, pre_tanh_actions):
    # Your code here
    pass

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