MCPcopy Create free account
hub / github.com/OpenDriveLab/TCP / log_prob

Method log_prob

roach/models/distributions.py:143–157  ·  view source on GitHub ↗
(self, actions: th.Tensor, gaussian_actions: Optional[th.Tensor] = None)

Source from the content-addressed store, hash-verified

141 return self
142
143 def log_prob(self, actions: th.Tensor, gaussian_actions: Optional[th.Tensor] = None) -> th.Tensor:
144 # Inverse tanh
145 if gaussian_actions is None:
146 gaussian_actions = th.clamp(actions, min=-1.0 + self.eps, max=1.0 - self.eps)
147 gaussian_actions = 0.5 * (gaussian_actions.log1p() - (-gaussian_actions).log1p())
148
149 # Log likelihood for a Gaussian distribution
150 log_prob = self.distribution.log_prob(gaussian_actions)
151 log_prob = sum_independent_dims(log_prob)
152
153 # sb3 correction
154 # log_prob -= th.sum(th.log(1 - actions ** 2 + self.eps), dim=1)
155 # spinning-up correction
156 log_prob -= (2*(np.log(2) - gaussian_actions - F.softplus(-2*gaussian_actions))).sum(axis=1)
157 return log_prob
158
159 def entropy(self) -> Optional[th.Tensor]:
160 return None

Callers

nothing calls this directly

Calls 2

sum_independent_dimsFunction · 0.85
log_probMethod · 0.45

Tested by

no test coverage detected