def extend_new_segment(self, id: int, owner: Axon, target: np.ndarray): new_segment_origin = self.end distance_from_target = np.linalg.norm(new_segment_origin - owner.target) desired_weight, momentum_weight = self.calculate_desired_and_momentum_weights(distance_from_target) desired_direction = get_unit_direction_vector(new_segment_origin, target) momentum_direction = get_unit_direction_vector(self.origin, self.end) desired_and_momentum = desired_weight * desired_direction + momentum_weight * momentum_direction unit_desired_and_momentum = get_unit_vector(desired_and_momentum) prenoise_pol = cart_to_pol(unit_desired_and_momentum)[1] r = np.random.normal(retino.AXON_SEGMENT_LENGTH_AVG, retino.AXON_SEGMENT_LENGTH_STD, size=1)[0] noise = np.random.normal(0, retino.AXON_SEGMENT_GROWTH_DIRECTION_NOISE_STD, size=1)[0] if self.is_going_away(): self.noise = np.random.normal(0, 2, size=1)[0] theta = prenoise_pol + noise cart_result = pol_to_cart(np.asarray([r, theta])) new_segment_end = new_segment_origin + cart_result new_segment = AxonSegment(id, self, owner, origin=new_segment_origin, end=new_segment_end) if np.linalg.norm(new_segment.end - target) < retino.SYNAPSE_ATTEMPT_GOLDILOCKS_RADIUS: if owner.model is not None: new_segment.attempt_synapses() owner.segments.append(new_segment)
def attempt_synapses(self): postsynapticcells = self.owner.model.postsynapticcells origins = generate_random_points_along_line(self.origin, cart_to_pol(self.end - self.origin), retino.AXON_SEGMENT_SYNAPSE_POOL_COUNT, retino.AXON_SEGMENT_SYNAPSE_COUNT, retino.AXON_SEGMENT_SYNAPSE_JITTER_STD) for origin in origins: i = choose_random_circle_as_connection_index(origin, [p.origin for p in postsynapticcells], [p.size for p in postsynapticcells]) if i is not None: connection = Synapse(i, self, i, origin=origin) self.synapses.append(connection) self.owner.synapses.append(connection) postsynapticcells[i].synapses.append(connection)
def attempt_synapses(self): postsynapticcells = self.owner.model.postsynapticcells origins = generate_random_points_along_line( self.origin, cart_to_pol(self.end - self.origin), retino.AXON_SEGMENT_SYNAPSE_POOL_COUNT, retino.AXON_SEGMENT_SYNAPSE_COUNT, retino.AXON_SEGMENT_SYNAPSE_JITTER_STD) for origin in origins: i = choose_random_circle_as_connection_index( origin, [p.origin for p in postsynapticcells], [p.size for p in postsynapticcells]) if i is not None: connection = Synapse(i, self, i, origin=origin) self.synapses.append(connection) self.owner.synapses.append(connection) postsynapticcells[i].synapses.append(connection)
def extend_new_segment(self, id: int, owner: Axon, target: np.ndarray): new_segment_origin = self.end distance_from_target = np.linalg.norm(new_segment_origin - owner.target) desired_weight, momentum_weight = self.calculate_desired_and_momentum_weights( distance_from_target) desired_direction = get_unit_direction_vector(new_segment_origin, target) momentum_direction = get_unit_direction_vector(self.origin, self.end) desired_and_momentum = desired_weight * desired_direction + momentum_weight * momentum_direction unit_desired_and_momentum = get_unit_vector(desired_and_momentum) prenoise_pol = cart_to_pol(unit_desired_and_momentum)[1] r = np.random.normal(retino.AXON_SEGMENT_LENGTH_AVG, retino.AXON_SEGMENT_LENGTH_STD, size=1)[0] noise = np.random.normal( 0, retino.AXON_SEGMENT_GROWTH_DIRECTION_NOISE_STD, size=1)[0] if self.is_going_away(): self.noise = np.random.normal(0, 2, size=1)[0] theta = prenoise_pol + noise cart_result = pol_to_cart(np.asarray([r, theta])) new_segment_end = new_segment_origin + cart_result new_segment = AxonSegment(id, self, owner, origin=new_segment_origin, end=new_segment_end) if np.linalg.norm(new_segment.end - target) < retino.SYNAPSE_ATTEMPT_GOLDILOCKS_RADIUS: if owner.model is not None: new_segment.attempt_synapses() owner.segments.append(new_segment)