<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from base_world import World as BaseWorld <EOL> class World ( BaseWorld ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , lifespan = None ) : <EOL> """<STR_LIT>""" <EOL> BaseWorld . __init__ ( self , lifespan ) <EOL> self . VISUALIZE_PERIOD = <NUM_LIT:10> ** <NUM_LIT:4> <EOL> self . REWARD_MAGNITUDE = <NUM_LIT> <EOL> self . ENERGY_COST = <NUM_LIT> * self . REWARD_MAGNITUDE <EOL> self . JUMP_FRACTION = <NUM_LIT:0.1> <EOL> self . display_state = True <EOL> self . name = '<STR_LIT>' <EOL> self . name_long = '<STR_LIT>' <EOL> print "<STR_LIT>" , self . name_long <EOL> self . num_real_sensors = <NUM_LIT:3> <EOL> self . num_noise_sensors = <NUM_LIT:15> <EOL> self . num_sensors = self . num_noise_sensors + self . num_real_sensors <EOL> self . num_actions = <NUM_LIT:3> <EOL> self . action = np . zeros ( ( self . num_actions , <NUM_LIT:1> ) ) <EOL> self . world_state = <NUM_LIT:0> <EOL> self . simple_state = <NUM_LIT:0> <EOL> def step ( self , action ) : <EOL> """<STR_LIT>""" <EOL> self . action = action . copy ( ) . ravel ( ) <EOL> self . timestep += <NUM_LIT:1> <EOL> step_size = self . action [ <NUM_LIT:0> ] - self . action [ <NUM_LIT:1> ] <EOL> energy = self . action [ <NUM_LIT:0> ] + self . action [ <NUM_LIT:1> ] <EOL> self . world_state = self . world_state + step_size <EOL> if np . random . random_sample ( ) < self . JUMP_FRACTION : <EOL> self . world_state = ( self . num_real_sensors * <EOL> np . random . random_sample ( ) ) <EOL> self . world_state -= ( self . num_real_sensors * <EOL> np . floor_divide ( self . world_state , <EOL> self . num_real_sensors ) ) <EOL> self . simple_state = int ( np . floor ( self . world_state ) ) <EOL> real_sensors = np . zeros ( self . num_real_sensors ) <EOL> real_sensors [ self . simple_state ] = <NUM_LIT:1> <EOL> noise_sensors = np . round ( np . random . random_sample ( <EOL> self . num_noise_sensors ) ) <EOL> sensors = np . hstack ( ( real_sensors , noise_sensors ) ) <EOL> reward = - self . REWARD_MAGNITUDE <EOL> if self . simple_state == <NUM_LIT:1> : <EOL> reward = self . REWARD_MAGNITUDE <EOL> reward -= energy * self . ENERGY_COST <EOL> return sensors , reward <EOL> def set_agent_parameters ( self , agent ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def visualize ( self , agent ) : <EOL> """<STR_LIT>""" <EOL> if ( self . display_state ) : <EOL> state_image = [ '<STR_LIT:.>' ] * ( self . num_real_sensors + <EOL> self . num_actions + <NUM_LIT:2> ) <EOL> state_image [ self . simple_state ] = '<STR_LIT:O>' <EOL> state_image [ self . num_real_sensors : self . num_real_sensors + <NUM_LIT:2> ] = '<STR_LIT>' <EOL> action_index = np . where ( self . action > <NUM_LIT:0.1> ) [ <NUM_LIT:0> ] <EOL> if action_index . size > <NUM_LIT:0> : <EOL> state_image [ self . num_real_sensors + <NUM_LIT:2> + action_index [ <NUM_LIT:0> ] ] = '<STR_LIT:x>' <EOL> print ( '<STR_LIT>' . join ( state_image ) ) <EOL> if ( self . timestep % self . VISUALIZE_PERIOD ) == <NUM_LIT:0> : <EOL> print ( "<STR_LIT>" % self . timestep ) </s>
