def generate_train_world(self): world = World(self.world_size, self.world_color) n = 0 last_entity = -1 if self.num_entities == 0: return world for _ in range(self.num_entities * self.__class__.MAX_ATTEMPTS): entity = self.sample_entity(world=world, last_entity=last_entity) combination = (entity.shape.name, entity.color.name, entity.texture.name) if combination in self.invalid_combinations: last_entity = None elif world.add_entity( entity, collision_tolerance=self.collision_tolerance, collision_shade_difference=self.collision_shade_difference, boundary_tolerance=self.boundary_tolerance): last_entity = entity n += 1 if n == self.num_entities: break else: last_entity = None else: return None if self.collision_tolerance: world.sort_entities() return world
def generate_world(self): world = World(self.world_size, self.world_color) n = 0 last_entity = -1 if self.num_entities == 0: return world for _ in range(self.num_entities * self.__class__.MAX_ATTEMPTS): entity = self.sample_entity(world=world, last_entity=last_entity) if world.add_entity( entity, collision_tolerance=self.collision_tolerance, collision_shade_difference=self.collision_shade_difference, boundary_tolerance=self.boundary_tolerance): last_entity = entity n += 1 if n == self.num_entities: break else: last_entity = None else: return None if self.collision_tolerance: world.sort_entities() return world
def generate_train_world(self): world = World(self.world_size, self.world_color, self.noise_range) n_entity = choice(self.train_entity_counts) if n_entity == 0: return world shapes = GenericGenerator.choose(self.shapes, self.shapes_range) colors = GenericGenerator.choose(self.colors, self.colors_range) textures = GenericGenerator.choose(self.textures, self.textures_range) n = 0 for _ in range(n_entity * GenericGenerator.MAX_ATTEMPTS): entity = Entity.random_instance( center=world.random_location(), shapes=shapes, size_range=self.size_range, distortion_range=self.distortion_range, rotation=self.rotation, colors=colors, shade_range=self.shade_range, textures=textures) combination = (str(entity.shape), str(entity.color), str(entity.texture)) if combination in self.validation_combinations or combination in self.test_combinations: continue n += world.add_entity(entity, boundary_tolerance=self.boundary_tolerance, collision_tolerance=self.collision_tolerance) if n >= n_entity: break else: return None if self.collision_tolerance: world.sort_entities() return world
def generate_train_world(self): world = World(self.world_size, self.world_color) if self.num_entities == 0: return world n = 0 provoke_collision = random() < self.provoke_collision_rate for _ in range(self.num_entities * self.__class__.MAX_ATTEMPTS): center = world.random_location(provoke_collision=provoke_collision) entity = Entity.random_instance( center=center, shapes=self.selected_shapes, size_range=self.size_range, distortion_range=self.distortion_range, rotation=self.rotation, colors=self.selected_colors, shade_range=self.shade_range, textures=self.selected_textures) combination = (entity.shape.name, entity.color.name, entity.texture.name) if combination in self.validation_combinations or combination in self.test_combinations: continue if world.add_entity(entity, boundary_tolerance=self.boundary_tolerance, collision_tolerance=self.collision_tolerance): n += 1 provoke_collision = random() < self.provoke_collision_rate if n == self.num_entities: break else: return None if self.collision_tolerance: world.sort_entities() return world
def generate_validation_world(self): if self.validation_combinations is None: return self.generate_train_world() world = World(self.world_size, self.world_color) n = 0 last_entity = -1 if self.num_entities == 0: return world if self.validation_combination_rate is not None: while True: entity = self.sample_entity(world=world, last_entity=last_entity, combinations=self.validation_combinations) if world.add_entity(entity, boundary_tolerance=self.boundary_tolerance, collision_tolerance=self.collision_tolerance, collision_shade_difference=self.collision_shade_difference): n += 1 last_entity = entity break else: last_entity = None if self.num_entities == 1: return world pick_space = random() < self.validation_space_rate pick_combination = pick_space and random() < self.validation_combination_rate for _ in range(self.num_entities * self.__class__.MAX_ATTEMPTS): if pick_combination: entity = self.sample_entity(world=world, last_entity=last_entity, combinations=self.validation_combinations) elif pick_space: entity = self.sample_entity(world=world, last_entity=last_entity, combinations=self.validation_space) else: entity = self.sample_entity(world=world, last_entity=last_entity) combination = (entity.shape.name, entity.color.name, entity.texture.name) if combination in self.invalid_validation_combinations: last_entity = None elif world.add_entity(entity, collision_tolerance=self.collision_tolerance, collision_shade_difference=self.collision_shade_difference, boundary_tolerance=self.boundary_tolerance): n += 1 if n == self.num_entities: break last_entity = entity pick_space = random() < self.validation_space_rate pick_combination = pick_space and random() < self.validation_combination_rate else: last_entity = None else: return None if self.collision_tolerance: world.sort_entities() return world
def generate_test_world(self): world = World(self.world_size, self.world_color) if self.num_entities == 0: return world n = 0 last_entity = -1 if self.test_combinations: while True: entity = self.sample_entity( world=world, last_entity=last_entity, combinations=self.test_combinations) if world.add_entity( entity, boundary_tolerance=self.boundary_tolerance, collision_tolerance=self.collision_tolerance): last_entity = entity n += 1 break else: last_entity = None if n < self.num_entities: for _ in range(self.num_entities * self.__class__.MAX_ATTEMPTS): entity = self.sample_entity(world=world, last_entity=last_entity) if world.add_entity( entity, boundary_tolerance=self.boundary_tolerance, collision_tolerance=self.collision_tolerance): last_entity = entity n += 1 if n == self.num_entities: break else: last_entity = None else: return None if self.collision_tolerance: world.sort_entities() return world