I am having the Actor network and PPoagent with continuous action space, please review…
- User
I am having the Actor network and PPoagent with continuous action space, please review the complete provided code. and address any implementation issues were existing or not in the given structure. and also address all the logical immplementation error, improper implementation, improper functions used, improper computation technique used finally address the 'log_prob were properly computed or not and check its expression.
class Actor(torch.nn.Module): def init(self, gnn_model): super(Actor, self).init() self.gnn = gnn_model # Bounds are converted to tensors for ease of calculation self.bounds_low = torch.tensor([0.18e-6, 0.18e-6, 0.18e-6, 0.18e-6, 0.18e-6, 0.5e-6, 0.5e-6, 0.5e-6, 0.5e-6, 0.5e-6, 15e-6, 0.1e-12, 0.8], dtype=torch.float32)
codeself.bounds_high = torch.tensor([0.2e-6, 0.2e-6, 0.2e-6, 0.2e-6, 0.2e-6, 50e-6, 50e-6, 50e-6, 50e-6, 50e-6, 30e-6, 10e-12, 1.4], dtype=torch.float32) def forward(self, state): node_features_tensor, _, edge_index = state processed_features = self.gnn(node_features_tensor, edge_index) # Specific (row, column) indices for action values, converted to 0-based indexing action_indices = [ (10, 19), (16, 19), (5, 19), (3, 19), (0, 19), (10, 18), (16, 18), (5, 18), (3, 18), (0, 18), (17, 20), (18, 21), (19, 22) ] # For gathering specific indices, we first convert action_indices to a tensor format that can be used with gather or indexing action_indices_tensor = torch.tensor(action_indices, dtype=torch.long).t() selected_features = processed_features[action_indices_tensor[0], action_indices_tensor[1]] print("selected_features", selected_features) # Perform min-max scaling to map selected features to the range defined by bounds #min_values = torch.min(selected_features, dim=0)[0] #max_values = torch.max(selected_features, dim=0)[0] #scaled_action = (selected_features - min_values) / (max_values - min_values) # Use sigmoid or tanh followed by scaling to the specific bounds # This assumes outputs are approximately normalized or that such a transformation is desirable. #scaled_action = torch.sigmoid(selected_features) # Sigmoid maps to (0, 1) # Alternatively, for a wider range before scaling, you could use: scaled_action = (torch.tanh(selected_features) + 1) / 2 # Maps outputs to (0, 1) # Scale the min-max scaled features to fit within the specified bounds scaled_actions = self.bounds_low + (self.bounds_high - self.bounds_low) * scaled_action return scaled_actions - Assistant
- User
Provide me the updated code with the provide suggestions
- Assistant
- User
gnn_output = self.gnn(node_features_tensor, edge_index)
code# Assuming gnn_output is already normalized to be between -1 and 1 action_means = (torch.tanh(gnn_output) + 1) / 2 # Normalize output to [0, 1]. but the gnn_output is not normalized between -1 and 1 - Assistant