def test_agent_n_dimensions_setter(): try: new_agent = agent.Agent(n_variables=5, n_dimensions=0.0) except: new_agent = agent.Agent(n_variables=5, n_dimensions=4) try: new_agent = agent.Agent(n_variables=5, n_dimensions=0) except: new_agent = agent.Agent(n_variables=5, n_dimensions=4) assert new_agent.n_dimensions == 4
def test_agent_n_dimensions_setter(): try: new_agent = agent.Agent(1, 0.0, 0, 1) except: new_agent = agent.Agent(1, 1, 0, 1) try: new_agent = agent.Agent(1, 0, 0, 1) except: new_agent = agent.Agent(1, 1, 0, 1) assert new_agent.n_dimensions == 1
def test_agent_n_variables_setter(): try: new_agent = agent.Agent(0.0, 1, 0, 1) except: new_agent = agent.Agent(1, 1, 0, 1) try: new_agent = agent.Agent(0, 4, 0, 1) except: new_agent = agent.Agent(1, 1, 0, 1) assert new_agent.n_variables == 1
def test_agent_fill_with_uniform(): new_agent = agent.Agent(1, 1, 0, 1) new_agent.fill_with_uniform() assert new_agent.position[0] >= 0 assert new_agent.position[0] <= 1
def test_agent_lb_setter(): new_agent = agent.Agent(n_variables=5, n_dimensions=4) try: new_agent.lb = [1] except: new_agent.lb = np.array([1]) assert new_agent.lb[0] == 1
def test_agent_fit_setter(): new_agent = agent.Agent(n_variables=5, n_dimensions=4) try: new_agent.fit = np.array([0]) except: new_agent.fit = 0 assert new_agent.fit == 0
def test_agent_position_setter(): new_agent = agent.Agent(n_variables=1, n_dimensions=1) try: new_agent.position = 10 except: new_agent.position = np.array([10]) assert new_agent.position[0] == 10
def test_agent_fit_setter(): new_agent = agent.Agent(1, 1, 0, 1) try: new_agent.fit = np.array([0]) except: new_agent.fit = 0 assert new_agent.fit == 0
def test_agent_fill_with_static(): new_agent = agent.Agent(1, 1, 0, 1) try: new_agent.fill_with_static([20, 20]) except: new_agent.fill_with_static(20) assert new_agent.position[0] == 20
def test_agent_ts_setter(): new_agent = agent.Agent(1, 1, 0, 1) try: new_agent.ts = np.array([0]) except: new_agent.ts = 0 assert new_agent.ts == 0
def test_agent_position_setter(): new_agent = agent.Agent(1, 1, 0, 1) try: new_agent.position = 10 except: new_agent.position = np.array([10]) assert new_agent.position[0] == 10
def test_space_best_agent_setter(): new_space = space.Space() try: new_space.best_agent = None except: new_space.best_agent = agent.Agent(1, 1, 0, 1) assert isinstance(new_space.best_agent, agent.Agent)
def test_agent_clip_limits(): new_agent = agent.Agent(n_variables=1, n_dimensions=1) new_agent.lb = np.array([10]) new_agent.ub = np.array([10]) new_agent.clip_limits() assert new_agent.position[0] == 10
def test_history_dump(): new_history = history.History() agents = [agent.Agent(n_variables=2, n_dimensions=1) for _ in range(5)] new_history.dump(agents=agents, best_agent=agents[4], value=0) assert len(new_history.agents) > 0 assert len(new_history.best_agent) > 0 assert new_history.value[0] == 0
def test_agent_check_limits(): new_agent = agent.Agent(n_variables=1, n_dimensions=1) lower_bound = [10] upper_bound = [10] new_agent.check_limits(lower_bound, upper_bound) assert new_agent.position[0] == 10
def test_history_save(): new_history = history.History() agents = [agent.Agent(n_variables=2, n_dimensions=1) for _ in range(5)] new_history.dump(agents=agents, best_agent=agents[0]) new_history.save('models/test.pkl') assert os.path.isfile('./models/test.pkl')
def test_agent_clip_by_bound(): new_agent = agent.Agent(1, 1, 0, 1) new_agent.lb = np.array([10]) new_agent.ub = np.array([10]) new_agent.clip_by_bound() assert new_agent.position[0] == 10
def test_agent_check_limits(): new_agent = agent.Agent(n_variables=1, n_dimensions=1) new_agent.lb = [10] new_agent.ub = [10] new_agent.check_limits() assert new_agent.position[0] == 10
def test_history_dump(): new_history = history.History() agents = [] for _ in range(5): agents.append(agent.Agent(n_variables=2, n_dimensions=1)) new_history.dump(agents, agents[0]) assert len(new_history.agents) > 0 assert len(new_history.best_agent) > 0
def test_history_show(): new_history = history.History() agents = [] for _ in range(5): agents.append(agent.Agent(n_variables=2, n_dimensions=1)) new_history.dump(agents, agents[0]) new_history.show() assert True == True
def test_agent_lb_setter(): new_agent = agent.Agent(1, 1, 0, 1) try: new_agent.lb = [1] except: new_agent.lb = np.array([1]) assert new_agent.lb[0] == 1 try: new_agent.lb = np.array([1, 2]) except: new_agent.lb = np.array([1]) assert new_agent.lb[0] == 1
def test_agent_mapping_setter(): new_agent = agent.Agent(1, 1, 0, 1) try: new_agent.mapping = "a" except: new_agent.mapping = ["x1"] assert len(new_agent.mapping) == 1 try: new_agent.mapping = [] except: new_agent.mapping = ["x1"] assert len(new_agent.mapping) == 1
def test_history_get_convergence(): new_history = history.History(save_agents=True) agents = [ agent.Agent(n_variables=2, n_dimensions=1, lower_bound=[0, 0], upper_bound=[1, 1]) for _ in range(5) ] new_history.dump(agents=agents, best_agent=agents[4], local_position=agents[0].position, value=0) new_history.dump(agents=agents, best_agent=agents[4], local_position=agents[0].position, value=0) try: agents_pos, agents_fit = new_history.get_convergence(key='agents', index=5) except: agents_pos, agents_fit = new_history.get_convergence(key='agents', index=0) assert agents_pos.shape == (2, 2) assert agents_fit.shape == (2, ) best_agent_pos, best_agent_fit = new_history.get_convergence( key='best_agent') assert best_agent_pos.shape == (2, 2) assert best_agent_fit.shape == (2, ) try: local_position = new_history.get_convergence(key='local_position', index=5) except: local_position = new_history.get_convergence(key='local_position') assert local_position.shape == (2, ) value = new_history.get_convergence(key='value') assert value.shape == (2, )
def test_history_get(): new_history = history.History() agents = [agent.Agent(n_variables=2, n_dimensions=1) for _ in range(5)] new_history.dump(agents=agents, best_agent=agents[4], value=0) try: agents = new_history.get(key='agents', index=0) except: agents = new_history.get(key='agents', index=(0, 0)) try: agents = new_history.get(key='agents', index=(0, 0, 0)) except: agents = new_history.get(key='agents', index=(0, 0)) assert agents.shape == (2, 1)
def test_history_dump(): new_history = history.History(save_agents=True) agents = [ agent.Agent( n_variables=2, n_dimensions=1, lower_bound=[0, 0], upper_bound=[1, 1] ) for _ in range(5) ] new_history.dump(agents=agents, best_agent=agents[4], value=0) assert len(new_history.agents) > 0 assert len(new_history.best_agent) > 0 assert new_history.value[0] == 0 new_history = history.History(save_agents=False) new_history.dump(agents=agents) assert hasattr(new_history, "agents") is False
def test_agent_lb(): new_agent = agent.Agent(1, 1, 0, 1) assert len(new_agent.lb) == 1
def test_agent_n_variables(): new_agent = agent.Agent(1, 1, 0, 1) assert new_agent.n_variables == 1
def test_agent_fit(): new_agent = agent.Agent(1, 1, 0, 1) assert new_agent.fit == sys.float_info.max
def test_agent_position(): new_agent = agent.Agent(1, 1, 0, 1) assert new_agent.position.shape == (1, 1)
def test_agent_n_dimensions(): new_agent = agent.Agent(1, 1, 0, 1) assert new_agent.n_dimensions == 1