def test_wasabi(self): """ Tests if messages are received from wasabi. """ self.apply_settings() environment = TestEnvironment() environment.test_wasabi()
def test_005(self): from environment import TestEnvironment environment = TestEnvironment() environmentAdapter = EnvironmentAdapter(environment) constructorParameter = dict(N=10, eps=0.1, t=datetime.now()) environmentAdapter.setConstructorParameter(constructorParameter) assert constructorParameter == \ environmentAdapter.getConstructorParameter() assert environmentAdapter.getType() == environment.__class__.__name__
def test_001(self): agent = TestAgent() environment = TestEnvironment() trainer = TestTrainer(agent, environment) trainer.train() criteriaNames = trainer.getCriteriaNames() assert isinstance(criteriaNames, list) assert isinstance(criteriaNames[0], str) trainLog = trainer.getTrainLog() assert isinstance(trainLog[0][0], datetime) assert isinstance(trainLog[1][0][0], float)
def main(_): # build environment env = TestEnvironment() # create agent agent = TestAgent(env.action_space.n) # hyperdash experiment # exp = Experiment("Capsule-DQN") for episode in range(cfg.episode): # train agent _, _ = play(env, agent) # print("Episode {} completed.".format(episode)) # evaluate agent if episode % cfg.eval_freq == 0: R, step = play(env, agent, is_training=False)
def test_006(self): from agent import TestAgent from environment import TestEnvironment from trainer import TestTrainer agent = TestAgent() environment = TestEnvironment() trainer = TestTrainer(agent, environment) trainerAdapter = TrainerAdapter(trainer) constructorParameter = dict(N=10, eps=0.1, t=datetime.now()) trainerAdapter.setConstructorParameter(constructorParameter) assert constructorParameter == \ trainerAdapter.getConstructorParameter() assert trainerAdapter.getType() == trainer.__class__.__name__ trainerAdapter.getCriteriaNames() trainerAdapter.getTrainLog()
def main(mechanism, world, saveimg): """ The main script that runs the simulation. :param mechanism: which mechanism will be used to simulate behavior (simple, recursive, constructive) :param world: which world will be used for simulation (command-line simple world, real world) :param saveimg: will the simulation output be saved """ # initialize existence ex = None if world == "real": # initialize pygame environment pygame.init() clock = pygame.time.Clock() screen = pygame.display.set_mode((canvas.WIDTH, canvas.HEIGHT)) done = False # initialize output path wd = os.getcwd() output_path = '{0}/output/'.format(wd) imgsaver = None if saveimg: # empty the output folder map(os.unlink, [ os.path.join(output_path, f) for f in os.listdir(output_path) ]) imgsaver = ImageSaver(output_path) # pick random start location start_location = (random.randint(canvas.BORDER, canvas.WIDTH - canvas.BORDER), random.randint(canvas.BORDER, canvas.HEIGHT - canvas.BORDER)) # initialize agent kenny = canvas.Agent(start_location) # initialize primitive interactions primitive_interactions = { "move forward": ("e1", "r1", 2), "bump": ("e1", "r2", -50), "turn left": ("e2", "r3", -1), "turn right": ("e3", "r4", -1), "touch empty": ("e4", "r5", -1), "touch wall": ("e4", "r6", -2) } # initialize environments and existences if mechanism == "simple": environment = Environment(kenny, screen, clock) ex = Existence(primitive_interactions, environment) elif mechanism == "recursive": environment = Environment(kenny, screen, clock) ex = RecursiveExistence(primitive_interactions, environment) elif mechanism == "constructive": environment = ConstructiveEnvironment(kenny, screen, clock, imgsaver) ex = ConstructiveExistence(primitive_interactions, environment) i = 1 while not done: # screen.fill((0, 0, 0)) # quit if close button is pressed for event in pygame.event.get(): if event.type == pygame.QUIT: done = True # perform one simulation step (that might consist of several primitive steps) step_trace = ex.step() print(i, step_trace) print "\n" i += 1 # pygame.draw.polygon(screen, kenny.color, kenny.vertices) # if saveimg: # # save each frame as image # pygame.image.save(screen, output_path + str(format(i, '03'))+".jpeg") # pygame.display.flip() # clock.tick(3) elif world == "test": primitive_interactions = { "i1": ("e1", "r1", -1), "i2": ("e1", "r2", 1), "i3": ("e2", "r1", -1), "i4": ("e2", "r2", 1) } if mechanism == "simple": environment = TestEnvironmentD1() ex = Existence(primitive_interactions, environment) elif mechanism == "recursive": environment = TestEnvironmentD2() ex = RecursiveExistence(primitive_interactions, environment) elif mechanism == "constructive": environment = TestEnvironment() ex = ConstructiveExistence(primitive_interactions, environment) for i in range(0, 15): step_trace = ex.step() print(i, step_trace) print "\n"
def test(self, emotion): """ Test current settings """ environment = TestEnvironment() environment.test(emotion, 5)
def calluser(self): print (self.name) environment = TestEnvironment() environment.test(self.emo, 5)
def test_001(self): environment = TestEnvironment() assert isinstance(environment, IEnvironment)