Define Circuit Environment class CircuitEnvironment: VERYCLOSEREWARD = 40 LARGEREWARD =…
- User
Define Circuit Environment
class CircuitEnvironment: VERY_CLOSE_REWARD = 40 LARGE_REWARD = 10 VERY_HIGH_REWARD = 50 PENALTY = 20 SEVERE_PENALTY = 200 REGULAR_PENALTY = 100
def __init__(self, bounds_low, bounds_high): # Initialization code: setup bounds def calculate_reward(self, c_metrics, p_metrics): metrics_order = ['gain', 'bw', 'ugf', 'pm'] reward = 0 target_metrics = {k: self.target_metrics[i] for i, k in enumerate(metrics_order)} print("target_metrics", target_metrics) for metric_name in metrics_order: c_value = c_metrics[metric_name] p_value = p_metrics[metric_name] target_value = target_metrics[metric_name] # First condition: Penalty if 'gain' metric is negative, or lessthan 20 and 'pm' is beyond required limit if metric_name == 'gain': if c_value < 0: reward -= self.SEVERE_PENALTY return reward elif c_value < 20: reward -= self.REGULAR_PENALTY return reward elif metric_name == 'pm': if c_value < 60 or c_value > 75: reward -= self.REGULAR_PENALTY return reward # Second condition: Check if c_value is exactly the target value if c_value == target_value: reward += self.VERY_HIGH_REWARD continue # Third condition: Check if c_value is very close to the target value if metric_name == 'gain' and abs(c_value - target_value) <= 1: reward += self.VERY_CLOSE_REWARD continue elif metric_name == 'bw' and abs(c_value - target_value) <= 1000: reward += self.VERY_CLOSE_REWARD continue elif metric_name == 'ugf' and abs(c_value - target_value) <= 1000000: reward += self.VERY_CLOSE_REWARD continue elif metric_name == 'pm' and abs(c_value - target_value) <= 1: reward += self.VERY_HIGH_REWARD continue # Fourth condition: Check if c_value is closer to target value than p_value if abs(c_value - target_value) < abs(p_value - target_value): reward += self.LARGE_REWARD else: # Fifth condition: Apply penalty if none of the above conditions are met reward -= self.PENALTY return rewardI modified the first condition with the below conditions and after the modification i am not getting the expected reward as outputs with in first condition i include additional checking logic, here already i had on condition in the c_value, if the metric_name 'gain' is lessthan 0 then give severe penalty of 200 and return the reward without check any further condition below, along with this i added the additional conditions, if the 'gain' is lessthan 0 is true then return the reward without checking further conditions, if gain is not lessthan 0 need to check the two conditions if either one is true we need to give penalty of 100 and return the reward without checking any other further conditions, in the c_value, either the metric_name 'gain' is lessthan 20, or if the metric_name 'pm' is not between 60 to 75, any one condition is true then we need to give penalty as 100. and return the reward no further conditions are need to be check. if all the above first conditions are failed then need to check second, third, fourth and fifth conditions for reward generation.
- Assistant
- User
this reward i which are returning in the first conditions are i am giving as a intermediate reward into the reinforcement learning, because if the newly added condition i an getting continuously the intermediate reward (before this i used only the intermediate reward as when gain is lessthan 0, then i occasionally get the intermediate reward) due to this continuous intermediate reward with in the episode will affect the performance of policy agent or improve the policy agent?
- Assistant