def test_bpso_update(): boolean_space = boolean.BooleanSpace(n_agents=2, n_variables=5) new_bpso = bpso.BPSO() new_bpso.compile(boolean_space) new_bpso.update(boolean_space)
def test_bmrfo_cyclone_foraging(): new_bmrfo = bmrfo.BMRFO() boolean_space = boolean.BooleanSpace(n_agents=100, n_variables=2) cyclone = new_bmrfo._cyclone_foraging(boolean_space.agents, boolean_space.best_agent.position, 0, 1, 100) assert cyclone[0].item() is False or cyclone[0].item() is True cyclone = new_bmrfo._cyclone_foraging(boolean_space.agents, boolean_space.best_agent.position, 1, 1, 100) assert cyclone[0].item() is False or cyclone[0].item() is True cyclone = new_bmrfo._cyclone_foraging(boolean_space.agents, boolean_space.best_agent.position, 0, 1, 1) assert cyclone[0].item() is False or cyclone[0].item() is True cyclone = new_bmrfo._cyclone_foraging(boolean_space.agents, boolean_space.best_agent.position, 1, 1, 1) assert cyclone[0].item() is False or cyclone[0].item() is True
def test_boolean_initialize_agents(): new_boolean_space = boolean.BooleanSpace(1, 1) assert ( new_boolean_space.agents[0].position[0][0] == 0 or new_boolean_space.agents[0].position[0][0] == 1 )
def test_boolean_clip_limits(): new_boolean_space = boolean.BooleanSpace() new_boolean_space.agents[0].position[0][0] = 20 new_boolean_space.clip_limits() assert new_boolean_space.agents[0].position[0][0] == 1
def test_umda_calculate_probability(): new_umda = umda.UMDA() boolean_space = boolean.BooleanSpace(n_agents=5, n_variables=2) probs = new_umda._calculate_probability(boolean_space.agents) assert probs.shape == (2, 1)
def test_boolean_clip_by_bound(): new_boolean_space = boolean.BooleanSpace(1, 1) new_boolean_space.agents[0].position[0][0] = 20 new_boolean_space.clip_by_bound() assert new_boolean_space.agents[0].position[0][0] == 1
def test_bmrfo_somersault_foraging(): new_bmrfo = bmrfo.BMRFO() boolean_space = boolean.BooleanSpace(n_agents=100, n_variables=2) somersault = new_bmrfo._somersault_foraging( boolean_space.agents[0].position, boolean_space.best_agent.position) assert somersault[0].item() is False or somersault[0].item() is True
def test_bmrfo_update(): new_function = function.Function(pointer=Knapsack( values=(55, 10, 47, 5, 4), weights=(95, 4, 60, 32, 23), max_capacity=100)) new_bmrfo = bmrfo.BMRFO() boolean_space = boolean.BooleanSpace(n_agents=100, n_variables=5) new_bmrfo.update(boolean_space, new_function, 1, 20)
def test_bmrfo_chain_foraging(): new_bmrfo = bmrfo.BMRFO() boolean_space = boolean.BooleanSpace(n_agents=100, n_variables=2) chain = new_bmrfo._chain_foraging(boolean_space.agents, boolean_space.best_agent.position, 0) assert chain[0].item() is False or chain[0].item() is True
def test_udma_calculate_probability(): new_udma = udma.UDMA() boolean_space = boolean.BooleanSpace(n_agents=5, n_iterations=20, n_variables=2) probs = new_udma._calculate_probability(boolean_space.agents) assert probs.shape == (2, 1)
def test_bmrfo_chain_foraging(): new_bmrfo = bmrfo.BMRFO() boolean_space = boolean.BooleanSpace(n_agents=5, n_iterations=20, n_variables=2) chain = new_bmrfo._chain_foraging(boolean_space.agents, boolean_space.best_agent.position, 1) assert chain[0] == False or chain[0] == True
def test_bpso_evaluate(): def square(x): return np.sum(x**2) new_function = function.Function(pointer=square) boolean_space = boolean.BooleanSpace(n_agents=2, n_variables=5) new_bpso = bpso.BPSO() new_bpso.compile(boolean_space) new_bpso.evaluate(boolean_space, new_function) assert boolean_space.best_agent.fit < sys.float_info.max
def test_bpso_evaluate(): def square(x): return np.sum(x**2) new_function = function.Function(pointer=square) boolean_space = boolean.BooleanSpace(n_agents=2, n_iterations=10, n_variables=2) new_bpso = bpso.BPSO() local_position = np.zeros((2, 2, 1)) new_bpso._evaluate(boolean_space, new_function, local_position) assert boolean_space.best_agent.fit < sys.float_info.max
def test_bpso_compile(): boolean_space = boolean.BooleanSpace(n_agents=2, n_variables=5) new_bpso = bpso.BPSO() new_bpso.compile(boolean_space) try: new_bpso.local_position = 1 except: new_bpso.local_position = np.array([1]) assert new_bpso.local_position == 1 try: new_bpso.velocity = 1 except: new_bpso.velocity = np.array([1]) assert new_bpso.velocity == 1
def test_umda_run(): def hook(optimizer, space, function): return new_function = function.Function(pointer=Knapsack( values=(55, 10, 47, 5, 4), weights=(95, 4, 60, 32, 23), max_capacity=100)) new_umda = umda.UMDA() boolean_space = boolean.BooleanSpace( n_agents=2, n_iterations=10, n_variables=5) history = new_umda.run(boolean_space, new_function, pre_evaluation=hook) assert len(history.agents) > 0 assert len(history.best_agent) > 0 best_fitness = history.best_agent[-1][1] assert best_fitness <= constants.TEST_EPSILON, 'The algorithm umda failed to converge.'
def test_udma_run(): def square(x): return np.sum(x**2) def hook(optimizer, space, function): return new_function = function.Function(pointer=square) new_udma = udma.UDMA() boolean_space = boolean.BooleanSpace(n_agents=5, n_iterations=20, n_variables=2) history = new_udma.run(boolean_space, new_function, pre_evaluation=hook) assert len(history.agents) > 0 assert len(history.best_agent) > 0 best_fitness = history.best_agent[-1][1] assert best_fitness <= constants.TEST_EPSILON, 'The algorithm udma failed to converge.'
def test_umda_update(): new_umda = umda.UMDA() boolean_space = boolean.BooleanSpace(n_agents=2, n_variables=5) new_umda.update(boolean_space)