The data of 'actionmean' for the variables ['L1', 'L3', 'L5', 'L6', 'L7', 'W1', 'W3',…
- User
The data of 'action_mean' for the variables ['L1', 'L3', 'L5', 'L6', 'L7', 'W1', 'W3', 'W5', 'W6', 'W7', 'Io', 'Cp', 'Vc'] corresponding to the timesteps1, timesteps2, timesteps3, timesteps4, timesteps5 computation by the function 'select_action' using 'action_mean, action_log_std = actor(state_tensor)' is shown below, L1 0.0493 0.0494 0.0493 0.0492 0.0494 L3 -0.0140 -0.0138 -0.0139 -0.0138 -0.0139 ..... W1 -0.0962 -0.0960 -0.0960 -0.0961 -0.0961 W3 0.0428 0.0429 0.0430 0.0430 0.0429 ...... Io 0.0583 0.0584 0.0584 0.0584 0.0583 Cp -0.1001 -0.0997 -0.0998 -0.0999 -0.0999 Vc 0.0405 0.0409 0.0405 0.0408 0.0404
Similarly The data of 'action normal dist' for the variables ['L1', 'L3', 'L5', 'L6', 'L7', 'W1', 'W3', 'W5', 'W6', 'W7', 'Io', 'Cp', 'Vc'] corresponding to the timesteps1, timesteps2, timesteps3, timesteps4, timesteps5 computation by the function using 'normal_dist = torch.distributions.Normal(action_mean, action_std), action = normal_dist.sample()' is shown below, L1 -0.9160 -2.6290 -3.2240 1.8690 1.7923 L3 -5.4789 -2.3684 0.8237 -3.7364 -0.3974 ..... W1 0.6880 1.7303 0.3826 -3.2003 -4.0168 W3 -2.9907 2.2373 -2.0852 2.0636 1.9714 ...... Io 2.1719 -2.8532 -0.5820 -3.0144 -2.9840 Cp 3.1442 -1.0641 -0.6412 -0.7443 -0.0610 Vc 1.9117 1.7867 1.2009 -3.4727 -1.9496
by clip the action data after the normal distribution, with in the bounds, i am only getting the values of edges (either min or max) of the bounds for all variables, i am not getting the range of values with in the bounds bounds_low = np.array([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]) bounds_high = np.array([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])
The data of 'action normal dist' for the variables ['L1', 'L3', 'L5', 'L6', 'L7', 'W1', 'W3', 'W5', 'W6', 'W7', 'Io', 'Cp', 'Vc'] corresponding to the timesteps1, timesteps2, timesteps3, timesteps4, timesteps5 computation by the function 'select_action' using 'action = action.clamp(bounds_low_tensor, bounds_high_tensor)' is shown below, L1 1.8e-07 1.8e-07 1.8000000e-07 2.0e-07 2.0e-07 L3 1.8e-07 1.8e-07 2.0000000e-07 1.8e-07 1.8e-07 ..... W1 5.0e-05 5.0e-05 4.9999999e-05 5.0e-07 5.0e-07 W3 5.0e-07 5.0e-05 5.0000000e-07 5.0e-05 5.0e-05 ...... Io 3.0e-05 1.5e-05 1.5000000e-05 1.5e-05 1.5e-05 Cp 1.0e-11 1.0e-13 9.9999998e-14 1.0e-13 1.0e-13 Vc 1.4e+00 1.4e+00 1.2009218e+00 8.0e-01 8.0e-01
Select Action Function
def select_action(state, actor, critic, bounds_low, bounds_high, performance_metrics): state_tensor = torch.from_numpy(state).float().unsqueeze(0) action_mean, action_log_std = actor(state_tensor) print("action_mean",action_mean) action_std = action_log_std.exp()
# Create a normal distribution and sample an action normal_dist = torch.distributions.Normal(action_mean, action_std) action = normal_dist.sample() print("action normal dist", action) log_prob = normal_dist.log_prob(action).sum(1) # Convert bounds to PyTorch tensors bounds_low_tensor = torch.tensor(bounds_low).float().unsqueeze(0) bounds_high_tensor = torch.tensor(bounds_high).float().unsqueeze(0) # Clip your actions to their limits if needed action = action.clamp(bounds_low_tensor, bounds_high_tensor) # Estimate the value of the state using the critic network value = critic(state_tensor) return action.numpy(), log_prob, value.squeeze(), performance_metrics - Assistant
- User
- Assistant
- User
provide me the updated complete code based on your suggestion for solving my issue
- Assistant