A sigmoid smoothly maps any real input to a value between 0 and 1: sigmoid(x) = 1 / (1 + exp(−x)). In a Gaussian policy, it squashes unbounded samples into the range needed for fan-speed actions. Because the sigmoid’s tails compress values near the boundaries, the transformation changes probability density; a squash correction adjusts log-probabilities for this change. section 9.7
Listing 9.7 Action sampling with Gaussian policy and squashing
def get_action_and_value(self, obs: torch.Tensor,
deterministic: bool = False):
action_mean, action_std, values, _ = self.forward(obs) #A
dist = Normal(action_mean, action_std) #B
raw_actions = action_mean if deterministic
else dist.rsample() #C
actions = torch.sigmoid(raw_actions) #D
eps = 1e-6
log_prob_raw = dist.log_prob(raw_actions) #E
squash_correction = (
torch.log(actions.clamp(eps, 1-eps)) +
torch.log((1 - actions).clamp(eps, 1-eps))) #F
log_probs = (
log_prob_raw + squash_correction).sum(dim=[1, 2]) #G
entropy = dist.entropy().sum(dim=[1, 2]) #H
return actions, log_probs, entropy, values
See the Gaussian-policy action sampling code, including sigmoid squashing and the log-probability correction. section 9.7






















