예제 #1
0
파일: fruit.py 프로젝트: fdoperezi/becca
 def __init__(self, lifespan=None, test=False):
     """ 
     Set up the world 
     """
     BaseWorld.__init__(self, lifespan)
     self.name = 'fruit'
     self.name_long = 'fruit selection world'
     print "Entering", self.name_long
     """
     Break out the sensors into
        0: large?
        1: small?
        2: yellow?
        3: purple?
     A sample sensor array would be
         [1., 0., 1., 0.]
     indicating a ripe peach.
     """
     self.num_sensors = 4
     """
     Break out the actions into
         0: eat
         1: discard
         2: do nothing this time step
     """
     self.num_actions = 2
     self.action = np.zeros(self.num_actions)
     self.grab_fruit()
     # If REWARD is 1, the agent is very content and doesn't make 
     # a move on the next time step
     # This might also be due to the fact that the features are built
     # of two-timestep daisychains
     self.REWARD = 1.
     self.verbose =  False
    def __init__(self, lifespan=None):
        """ Set up the world """
        BaseWorld.__init__(self, lifespan)
        self.VISUALIZE_PERIOD = 10 ** 0
        # Set the constants that determine the details of the world
        # Typical interval between moving target and changing background image
        self.TASK_DURATION = 30.0
        self.TARGET_SIZE_FRACTION = 0.25
        self.REWARD_MAGNITUDE = 100.0
        self.print_feature_set = False
        self.name_long = "find square world"
        self.name = "square"
        print "Entering", self.name_long
        self.small_fov_span = 11
        self.large_fov_span = 11

        # Initialize the square_image_data to be used as the environment
        self.square_image_filename = os.path.join(".", "becca_world_find_square", "images", "square.png")
        self.square_image_data = plt.imread(self.square_image_filename)

        # Convert it to grayscale if it's in color
        if self.square_image_data.shape[2] == 3:
            # Collapse the three RGB matrices into one b/w value matrix
            self.square_image_data = np.sum(self.square_image_data, axis=2) / 3.0
        self.image_filenames = []
        path = os.path.join(".", "becca_world_find_square", "data")
        extensions = [".png"]
        for localpath, directories, filenames in os.walk(path):
            for filename in filenames:
                for extension in extensions:
                    if filename.endswith(extension):
                        self.image_filenames.append(os.path.join(localpath, filename))
        self.image_count = len(self.image_filenames)
        if self.image_count == 0:
            try:
                raise RuntimeError("Add image files to 'data'")
            except RuntimeError:
                print "Error in watch.py: No images loaded."
                print "    Make sure the 'data' directory contains "
                print "    some image files."
                raise
        else:
            print self.image_count, "image_data filenames loaded."

        # Initialize the image_data to be viewed
        self.initialize_image()
        self.num_sensors = 2 * self.small_fov_span ** 2 + 2 * self.large_fov_span ** 2
        self.num_actions = 17
        self.sensors = np.zeros(self.num_sensors)
        self.column_history = []
        self.row_history = []
        self.step_counter = 0
        self.frame_counter = 100000
예제 #3
0
파일: grid_1D.py 프로젝트: eimirae/becca
 def __init__(self, lifespan=None):
     """ Set up the world """
     BaseWorld.__init__(self, lifespan)
     self.VISUALIZE_PERIOD = 10 ** 4
     self.REWARD_MAGNITUDE = 100.
     self.ENERGY_COST = 0.01 * self.REWARD_MAGNITUDE
     self.JUMP_FRACTION = 0.1
     self.name = 'grid_1D'
     self.name_long = 'one dimensional grid world'
     print "Entering", self.name_long
     self.num_sensors = 9
     self.num_actions = 9
     self.action = np.zeros((self.num_actions,1))
     self.world_state = 0
     self.simple_state = 0
     self.display_state = True 
예제 #4
0
 def __init__(self, lifespan=None):
     """ Set up the world """
     BaseWorld.__init__(self, lifespan)
     self.VISUALIZE_PERIOD = 10**4
     self.REWARD_MAGNITUDE = 100.
     self.ENERGY_COST = self.REWARD_MAGNITUDE / 100.
     self.JUMP_FRACTION = 0.1
     self.name = 'grid_1D'
     self.name_long = 'one dimensional grid world'
     print "Entering", self.name_long
     self.num_sensors = 9
     self.num_actions = 9
     self.action = np.zeros((self.num_actions, 1))
     self.world_state = 0
     self.simple_state = 0
     self.display_state = True
예제 #5
0
파일: image_2D.py 프로젝트: automenta/becca
    def __init__(self, lifespan=None):
        """ Set up the world """
        BaseWorld.__init__(self, lifespan)
        self.VISUALIZE_PERIOD = 10**4
        self.REWARD_MAGNITUDE = 100.
        self.JUMP_FRACTION = 1. / 10.
        self.print_feature_set = True
        self.animate = False
        self.name = 'image_2D'
        self.name_long = 'two dimensional visual world'
        print "Entering", self.name_long

        self.fov_span = 10
        # Initialize the block_image_data to be used as the environment
        self.block_image_filename = "./images/block_test.png"
        self.block_image_data = plt.imread(self.block_image_filename)
        # Convert it to grayscale if it's in color
        if self.block_image_data.shape[2] == 3:
            # Collapse the three RGB matrices into one b/w value matrix
            self.block_image_data = np.sum(self.block_image_data, axis=2) / 3.0
        # Define the size of the field of view, its range of
        # allowable positions, and its initial position.
        (im_height, im_width) = self.block_image_data.shape
        im_size = np.minimum(im_height, im_width)
        self.MAX_STEP_SIZE = im_size / 2
        self.TARGET_COLUMN = im_width / 2
        self.TARGET_ROW = im_height / 2
        self.REWARD_REGION_WIDTH = im_size / 8
        self.NOISE_MAGNITUDE = 0.1
        self.FIELD_OF_VIEW_FRACTION = 0.5
        self.fov_height = im_size * self.FIELD_OF_VIEW_FRACTION
        self.fov_width = self.fov_height
        self.column_min = np.ceil(self.fov_width / 2)
        self.column_max = np.floor(im_width - self.column_min)
        self.row_min = np.ceil(self.fov_height / 2)
        self.row_max = np.floor(im_height - self.row_min)
        self.column_position = np.random.random_integers(
            self.column_min, self.column_max)
        self.row_position = np.random.random_integers(self.row_min,
                                                      self.row_max)
        self.num_sensors = 2 * self.fov_span**2
        self.num_actions = 17
        self.sensors = np.zeros(self.num_sensors)
        self.column_history = []
        self.row_history = []
        self.last_feature_vizualized = 0
        self.step_counter = 0
예제 #6
0
파일: grid_2D.py 프로젝트: automenta/becca
 def __init__(self, lifespan=None):
     """ Set up the world """
     BaseWorld.__init__(self, lifespan)
     self.VISUALIZE_PERIOD = 10**4
     self.REWARD_MAGNITUDE = 100.
     self.ENERGY_COST = 0.05 * self.REWARD_MAGNITUDE
     self.JUMP_FRACTION = 0.1
     self.display_state = False
     self.name = 'grid_2D'
     self.name_long = 'two dimensional grid world'
     print "Entering", self.name_long
     self.num_actions = 9
     self.world_size = 5
     self.num_sensors = self.world_size**2
     self.world_state = np.array([1, 1])
     self.targets = [(1, 1), (3, 3)]
     self.obstacles = [(1, 3), (3, 1)]
예제 #7
0
파일: grid_2D.py 프로젝트: automenta/becca
 def __init__(self, lifespan=None):
     """ Set up the world """
     BaseWorld.__init__(self, lifespan)
     self.VISUALIZE_PERIOD = 10 ** 4
     self.REWARD_MAGNITUDE = 100.
     self.ENERGY_COST = 0.05 * self.REWARD_MAGNITUDE
     self.JUMP_FRACTION = 0.1
     self.display_state = False
     self.name = 'grid_2D'
     self.name_long = 'two dimensional grid world'
     print "Entering", self.name_long
     self.num_actions = 9            
     self.world_size = 5
     self.num_sensors = self.world_size ** 2
     self.world_state = np.array([1, 1])
     self.targets = [(1,1), (3,3)]
     self.obstacles = [(1,3), (3,1)]
예제 #8
0
파일: image_1D.py 프로젝트: eimirae/becca
    def __init__(self, lifespan=None):
        """ Set up the world """
        BaseWorld.__init__(self, lifespan)
        self.VISUALIZE_PERIOD = 10 ** 4
        self.print_feature_set = True
        self.REWARD_MAGNITUDE = 100.
        self.JUMP_FRACTION = 0.1
        self.STEP_COST = 0.1 * self.REWARD_MAGNITUDE
        self.animate = False 
        self.graphing = True
        self.name_long = 'one dimensional visual world'
        #self.name = 'image_1D'
        self.name = 'image_1D_slow_fast_decay'
        #self.name = 'image_1D_fast'
        print "Entering", self.name_long
        self.step_counter = 0
        self.fov_span = 5 
        self.num_sensors = 2 * self.fov_span ** 2
        self.num_actions = 9

        # Initialize the image to be used as the environment
        self.block_image_filename = "./images/bar_test.png" 
        self.data = plt.imread(self.block_image_filename)
        # Convert it to grayscale if it's in color
        if self.data.shape[2] == 3:
            # Collapse the three RGB matrices into one b/w value matrix
            self.data = np.sum(self.data, axis=2) / 3.0
        # Define the size of the field of view, its range of 
        # allowable positions, and its initial position.
        image_width = self.data.shape[1]
        self.MAX_STEP_SIZE = image_width / 2
        self.TARGET_COLUMN = image_width / 2
        self.REWARD_REGION_WIDTH = image_width / 8
        self.NOISE_MAGNITUDE = 0.1
    
        self.column_history = []
        self.fov_height = np.min(self.data.shape)
        self.fov_width = self.fov_height
        self.column_min = np.ceil(self.fov_width / 2)
        self.column_max = np.floor(self.data.shape[1] - self.column_min)
        self.column_position = np.random.random_integers(self.column_min, 
                                                         self.column_max)
        self.block_width = self.fov_width / (self.fov_span + 2)
        self.sensors = np.zeros(self.num_sensors)
예제 #9
0
 def __init__(self, lifespan=None):
     """ Set up the world """
     BaseWorld.__init__(self, lifespan)
     self.VISUALIZE_PERIOD = 10 ** 4
     self.REWARD_MAGNITUDE = 100.
     self.ENERGY_COST = 0.01 * self.REWARD_MAGNITUDE
     self.JUMP_FRACTION = 0.1
     self.display_state = True  
     self.name = 'grid_1D_noise'
     self.name_long = 'noisy one dimensional grid world'
     print "Entering", self.name_long
     self.num_real_sensors = 3
     # Number of sensors that have no basis in the world. 
     # These are noise meant to distract.
     self.num_noise_sensors = 15        
     self.num_sensors = self.num_noise_sensors + self.num_real_sensors
     self.num_actions = 3
     self.action = np.zeros((self.num_actions,1))
     self.world_state = 0      
     self.simple_state = 0       
예제 #10
0
파일: fruit.py 프로젝트: btapo/becca
    def __init__(self, lifespan=None):
        """ 
        Set up the world.

        Parameters
        ----------
        lifespan : int
            The number of time steps to continue the world.
        """
        BaseWorld.__init__(self, lifespan)
        self.name = 'fruit'
        self.name_long = 'fruit selection world'
        print "Entering", self.name_long
        self.world_visualize_period = 1e6
        self.brain_visualize_period = 1e3
        """
        Break out the sensors into
           0: large?
           1: small?
           2: yellow?
           3: purple?
        A sample sensor array would be
            [1., 0., 1., 0.]
        indicating a ripe peach.
        """
        self.num_sensors = 4
        """
        Break out the actions into
            0: eat
            1: discard
        """
        self.num_actions = 2
        self.action = np.zeros(self.num_actions)
        self.grab_fruit()
        self.reward_magnitude = 1.
        self.verbose =  False
예제 #11
0
    def __init__(self, lifespan=None):
        """ 
        Set up the world.

        Parameters
        ----------
        lifespan : int
            The number of time steps to continue the world.
        """
        BaseWorld.__init__(self, lifespan)
        self.name = 'fruit'
        self.name_long = 'fruit selection world'
        print "Entering", self.name_long
        self.world_visualize_period = 1e6
        self.brain_visualize_period = 1e3
        """
        Break out the sensors into
           0: large?
           1: small?
           2: yellow?
           3: purple?
        A sample sensor array would be
            [1., 0., 1., 0.]
        indicating a ripe peach.
        """
        self.num_sensors = 4
        """
        Break out the actions into
            0: eat
            1: discard
        """
        self.num_actions = 2
        self.action = np.zeros(self.num_actions)
        self.grab_fruit()
        self.reward_magnitude = 1.
        self.verbose = False