Environment/LASROMEnv.py
def _reward(self, observation):
        """
        Calculate reward based on observation of proximity sensor.

        All sensors have accumulated time rewards. The longer it has been triggered, the greater
        the reward will be. The reward function also uses memories of actions. For sensors with
        zero accumulated rewards, if it detects a new trigger but an action belonging to its own
        group CANNOT be found in the history, then this signal is ignored.

        Use adjusted sigmoid function to calculate the individual reward r(t)_i based on accumulated
        time reward (t)

        r(t)_i = 2*sigmoid(t/ratio) -1

        Final reward = avg(all sensors reward r(t)_i)
        """
        individual_action_summary = np.array([0]*self.lights_num)
        if len(self.action_history) > 0:
            for step_action in self.action_history:
                individual_action_summary = individual_action_summary | step_action

        group_action_summary = np.array([0]*self.group_num)
        for j in range(0, self.lights_num):
            # Notice here the group id (node number) starts from 1
            group_action_summary[self.group_id[j]-1] = group_action_summary[self.group_id[j]-1] | \
                                                       individual_action_summary[self.group_id[j]-1]

        prox_obs = observation[:self.prox_sensor_num]
        is_newly_triggered = prox_obs - self.time_reward > 0

        for i in range(0, self.lights_num):
            if prox_obs[i] == 1:
                obs = 1
                if is_newly_triggered[i] and group_action_summary[self.group_id[j]-1] == 0:
                    obs = 0
                self.time_reward[i] = self.time_reward[i] + obs
            else:
                self.time_reward[i] = 0

        # prox_obs = observation[:self.prox_sensor_num]
        # self.time_reward = (prox_obs + self.time_reward) * prox_obs

        ratio = 1000
        self.reward = np.mean(-1 + 2/(1+np.exp(-self.time_reward/ratio)))

        return self.reward

        Calculate reward based on observation of proximity sensor.

        All sensors have accumulated time rewards. The longer it has been triggered, the greater
        the reward will be. The reward function also uses memories of actions. For sensors with
        zero accumulated rewards, if it detects a new trigger but an action belonging to its own
        group CANNOT be found in the history, then this signal is ignored.

        Use adjusted sigmoid function to calculate the individual reward r(t)_i based on accumulated
        time reward (t)

        r(t)_i = 2*sigmoid(t/ratio) -1

        Final reward = avg(all sensors reward r(t)_i)
        
Calculate reward based on observation of proximity sensor.
All sensors have accumulated time rewards. The longer it has been triggered, the greater
the reward will be. The reward function also uses memories of actions. For sensors with
zero accumulated rewards, if it detects a new trigger but an action belonging to its own
group CANNOT be found in the history, then this signal is ignored.

Use adjusted sigmoid function to calculate the individual reward r(t)_i based on accumulated
time reward (t)




Calculate reward based on observation of proximity sensor . All sensors have accumulated time rewards . The longer it has been triggered the greater the reward will be . The reward function also uses memories of actions . For sensors with zero accumulated rewards if it detects a new trigger but an action belonging to its own group CANNOT be found in the history then this signal is ignored . Use adjusted sigmoid function to calculate the individual reward r ( t ) _i based on accumulated time reward ( t )
def _reward(self, observation):
        individual_action_summary = np.array([0]*self.lights_num)
        if len(self.action_history) > 0:
            for step_action in self.action_history:
                individual_action_summary = individual_action_summary | step_action
        group_action_summary = np.array([0]*self.group_num)
        for j in range(0, self.lights_num):
            group_action_summary[self.group_id[j]-1] = group_action_summary[self.group_id[j]-1] | \
                                                       individual_action_summary[self.group_id[j]-1]
        prox_obs = observation[:self.prox_sensor_num]
        is_newly_triggered = prox_obs - self.time_reward > 0
        for i in range(0, self.lights_num):
            if prox_obs[i] == 1:
                obs = 1
                if is_newly_triggered[i] and group_action_summary[self.group_id[j]-1] == 0:
                    obs = 0
                self.time_reward[i] = self.time_reward[i] + obs
            else:
                self.time_reward[i] = 0
        ratio = 1000
        self.reward = np.mean(-1 + 2/(1+np.exp(-self.time_reward/ratio)))
        return self.reward
def _reward ( self , observation ) : individual_action_summary = np . array ( [ 0 ] * self . lights_num ) if len ( self . action_history ) > 0 : for step_action in self . action_history : individual_action_summary = individual_action_summary | step_action group_action_summary = np . array ( [ 0 ] * self . group_num ) for j in range ( 0 , self . lights_num ) : group_action_summary [ self . group_id [ j ] - 1 ] = group_action_summary [ self . group_id [ j ] - 1 ] | individual_action_summary [ self . group_id [ j ] - 1 ] prox_obs = observation [ : self . prox_sensor_num ] is_newly_triggered = prox_obs - self . time_reward > 0 for i in range ( 0 , self . lights_num ) : if prox_obs [ i ] == 1 : obs = 1 if is_newly_triggered [ i ] and group_action_summary [ self . group_id [ j ] - 1 ] == 0 : obs = 0 self . time_reward [ i ] = self . time_reward [ i ] + obs else : self . time_reward [ i ] = 0 ratio = 1000 self . reward = np . mean ( - 1 + 2 / ( 1 + np . exp ( - self . time_reward / ratio ) ) ) return self . reward
Calculate reward based on observation of proximity sensor.
Calculate reward based on observation of proximity sensor .
"""
        Calculate reward based on observation of proximity sensor.

        All sensors have accumulated time rewards. The longer it has been triggered, the greater
        the reward will be. The reward function also uses memories of actions. For sensors with
        zero accumulated rewards, if it detects a new trigger but an action belonging to its own
        group CANNOT be found in the history, then this signal is ignored.

        Use adjusted sigmoid function to calculate the individual reward r(t)_i based on accumulated
        time reward (t)

        r(t)_i = 2*sigmoid(t/ratio) -1

        Final reward = avg(all sensors reward r(t)_i)
        """ # Notice here the group id (node number) starts from 1 # prox_obs = observation[:self.prox_sensor_num] # self.time_reward = (prox_obs + self.time_reward) * prox_obs
self
observation