Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug fix] make TanhNormal.mode a property #2

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions offlinerl/utils/net/tanhpolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def __init__(self, normal_mean, normal_std, max_action=1, min_action=-1, epsilon
self.normal_std = normal_std
self.normal = Normal(normal_mean, normal_std)
self.epsilon = epsilon
self.mode = torch.tanh(normal_mean)
self.max_action = max_action
self.min_action = min_action

Expand All @@ -41,6 +40,10 @@ def atanh(self,x):
one_plus_x = (1 + x).clamp(min=1e-6)
one_minus_x = (1 - x).clamp(min=1e-6)
return 0.5 * torch.log(one_plus_x / one_minus_x)

@property
def mode(self):
return torch.tanh(self.normal_mean)

def log_prob(self, value, pre_tanh_value=None):
"""
Expand Down Expand Up @@ -161,4 +164,4 @@ def forward(
return TanhNormal(mean, std)

def policy_infer(self, obs):
return self(obs).mode
return self(obs).mode