Exemplo n.º 1
0
    def get_place_cell_response(self, x, y):
        """Compute the firing rate of a each place cell with Gaussian tuning curves, for the current position of the
        agent
        """
        if isinstance(self.env, PlusMaze):
            x, y = self.env.lookup_geodesic_coordinate([x, y])
            place_cell_responses = utils.gauss2d(
                (x, y),
                var=self.field_width**2,
                centre=self.geodesic_field_centres) / self.max_response
            return place_cell_responses

        place_cell_responses = utils.gauss2d(
            (x, y), var=self.field_width**2,
            centre=self.field_centres) / self.max_response
        return place_cell_responses
Exemplo n.º 2
0
 def update_place_cell_response(self):
     """Compute the firing rate of a each place cell with Gaussian tuning curves, for the current position of the
     agent
     """
     self.previous_place_cell_responses = self.place_cell_responses
     if isinstance(self.env, PlusMaze):
         x, y = self.env.lookup_geodesic_coordinate(
             [self.env.curr_x, self.env.curr_y])
         self.place_cell_responses = utils.gauss2d(
             [x, y],
             var=self.field_width**2,
             centre=self.geodesic_field_centres) / self.max_response
     else:
         self.place_cell_responses = utils.gauss2d(
             [self.env.curr_x, self.env.curr_y],
             var=self.field_width**2,
             centre=self.field_centres) / self.max_response
Exemplo n.º 3
0
	def gen_mask(self, fea_sz):
		"""
		Generates 2D guassian masked convas with shape same as 
		fea_sz. This method should only called on the first frame.

		Args:
			img_sz: input image size.
			fea_sz: feaure size, to be identical to the 
				Output of sel-CNN net.
		Returns:
			convas: fea_sz shape with 1 channel. The central region is an 
				2D gaussian.
		"""
		im_sz = self.first_img.shape
		x, y, w, h = self.first_gt
		convas = np.zeros(im_sz[:2])

		# Generates 2D gaussian mask
		scale = min([w,h]) / 3 # To be consistence with the paper
		mask = gauss2d([h, w], sigma=scale)
		print(mask.max(), 'max of mask')

		# bottom right coordinate
		x2 = x + w - 1
		y2 = y + h - 1

		# Detects wether the location has out of the img or not
		clip = min(x, y, im_sz[0]-y2, im_sz[1]-x2)
		pad = 0
		if clip <= 0:
			pad = abs(clip) + 1
			convas = np.zeros((im_sz[0] + 2*pad, im_sz[1] + 2*pad))
			x += pad
			y += pad
			x2 += pad
			y2 += pad

		# Overwrite central arear of convas with mask;
		convas[y-1:y2, x-1:x2] = mask
		if clip <= 0:
			# Remove pad
			convas = convas[pad:-pad, pad, -pad]

		if len(convas.shape) < 3:
			convas = skimage.color.gray2rgb(convas)
		assert len(convas.shape) == 3

		# Extrac ROI and resize bicubicly
		convas, _, _  = self.extract_roi(convas, self.first_gt)
		print(convas.shape)
		convas = imresize(convas[...,0], fea_sz[:2], interp='bicubic')
		print(convas.max(), 'max convas')

		# Swap back, and normalize
		convas = convas / convas.max()
		#convas = np.transpose(convas)

		return convas#[..., np.newaxis]
Exemplo n.º 4
0
 def get_place_cell_response(self, x, y):
     """Compute the firing rate of a each place cell with Gaussian tuning curves, for the current position of the
     agent
     """
     place_cell_responses = utils.gauss2d(
         (x, y), var=self.field_width**2,
         centre=self.field_centres) / self.max_response
     place_cell_responses /= np.linalg.norm(place_cell_responses)
     return place_cell_responses
    def compute_place_cell_response(self, position):
        """Compute the responses of all place cells.

        :param position: Current position (x,y) of the agent.
        :return:
        """
        return utils.gauss2d(position,
                             var=self.field_width**2,
                             centre=self.field_centres) / self.max_response
 def update_place_cell_response(self):
     """Compute the firing rate of a each place cell with Gaussian tuning curves, for the current position of the
     agent
     """
     self.previous_place_cell_responses = self.place_cell_responses
     self.place_cell_responses = utils.gauss2d(
         self.current_position,
         var=self.field_width**2,
         centre=self.field_centres) / self.max_response
Exemplo n.º 7
0
 def update_place_cell_response(self):
     """Compute the firing rate of a each place cell with Gaussian tuning curves, for the current position of the
     agent
     """
     self.previous_place_cell_responses = self.place_cell_responses
     self.place_cell_responses = utils.gauss2d(
         [self.env.curr_x, self.env.curr_y],
         var=self.field_width**2,
         centre=self.field_centres)
     self.place_cell_responses /= np.linalg.norm(self.place_cell_responses)
Exemplo n.º 8
0
def gaussian_response(x_grid, y_grid, stimulus_location):
    """Compute response of a grid of gaussian receptive fields to a stimulus location

    :param x_grid:
    :param y_grid:
    :param stimulus_location:
    :return:
    """
    rf_centres = np.dstack([x_grid.ravel(), y_grid.ravel()])[0]
    responses = utils.gauss2d(stimulus_location, .05, rf_centres.T)
    return responses
    def __init__(self, n_trials=30, env=WaterMazeEnv()):

        WaterMazeAgent.__init__(self, n_trials=n_trials, env=env)
        self.env.trial = 0

        self.field_centres = self.create_place_cells()
        self.field_width = .09
        self.max_response = utils.gauss2d([0, 0], self.field_width**2, [0, 0])
        self.place_cell_responses = np.zeros(self.field_centres[0].shape)
        self.previous_place_cell_responses = np.zeros(
            self.field_centres[0].shape)
        self.update_place_cell_response()

        self.actions = {
            idx: direction
            for (idx, direction) in zip(range(12), range(0, 360, 30))
        }
        self.actions[0] = 360

        self.current_action = np.random.choice(len(self.actions))
        self.previous_action = None

        # initialise critic:
        self.critic_weights = np.zeros(self.place_cell_responses.shape)
        self.max_sum_weights = 1.
        self.critic_activation = np.dot(self.critic_weights,
                                        self.place_cell_responses)
        self.previous_critic_activation = None

        # initialise actor:
        self.action_weights = np.zeros(
            (len(self.actions), self.place_cell_responses.shape[0]))
        self.action_values = np.dot(self.action_weights,
                                    self.place_cell_responses)
        self.policy = self.softmax(self.action_values)

        self.policies = []
        self.policies.append(self.evaluate_policy_at_field_centres())
Exemplo n.º 10
0
 def get_max_response(self):
     """Get the maximum place cell response.
     """
     return utils.gauss2d([0, 0], self.field_width**2, [0, 0])