def test_opytimizer_build(): def square(x): return np.sum(x**2) assert square(2) == 4 new_function = function.Function(pointer=square) lb = [0, 0] ub = [10, 10] new_space = search.SearchSpace(lower_bound=lb, upper_bound=ub) new_pso = pso.PSO() try: new_pso.built = False new_opytimizer = opytimizer.Opytimizer(space=new_space, optimizer=new_pso, function=new_function) except: new_pso.built = True new_opytimizer = opytimizer.Opytimizer(space=new_space, optimizer=new_pso, function=new_function)
def test_opytimizer_start(): space = search.SearchSpace(1, 1, 0, 1) func = function.Function(callable) optimizer = pso.PSO() new_opytimizer = opytimizer.Opytimizer(space, optimizer, func) new_opytimizer.start(n_iterations=1)
def test_opytimizer_history(): space = search.SearchSpace(1, 1, 0, 1) func = function.Function(callable) optimizer = pso.PSO() new_opytimizer = opytimizer.Opytimizer(space, optimizer, func) assert type(new_opytimizer.history).__name__ == 'History'
def test_opytimizer_save(): space = search.SearchSpace(1, 1, 0, 1) func = function.Function(callable) optimizer = pso.PSO() new_opytimizer = opytimizer.Opytimizer(space, optimizer, func) new_opytimizer.save('out.pkl')
def test_opytimizer_update_args(): space = search.SearchSpace(1, 1, 0, 1) func = function.Function(callable) optimizer = pso.PSO() new_opytimizer = opytimizer.Opytimizer(space, optimizer, func) assert len(new_opytimizer.update_args) == 1
def test_opytimizer_total_iterations(): space = search.SearchSpace(1, 1, 0, 1) func = function.Function(callable) optimizer = pso.PSO() new_opytimizer = opytimizer.Opytimizer(space, optimizer, func) assert new_opytimizer.total_iterations == 0
def test_opytimizer_update(): space = search.SearchSpace(1, 1, 0, 1) func = function.Function(callable) optimizer = pso.PSO() callbacks = callback.CallbackVessel([]) new_opytimizer = opytimizer.Opytimizer(space, optimizer, func) new_opytimizer.update(callbacks)
def test_opytimizer_history_setter(): space = search.SearchSpace(1, 1, 0, 1) func = function.Function(callable) optimizer = pso.PSO() hist = history.History() new_opytimizer = opytimizer.Opytimizer(space, optimizer, func) try: new_opytimizer.history = 1 except: new_opytimizer.history = hist assert type(new_opytimizer.history).__name__ == 'History'
def test_opytimizer_function_setter(): space = search.SearchSpace(1, 1, 0, 1) func = function.Function(callable) optimizer = pso.PSO() new_opytimizer = opytimizer.Opytimizer(space, optimizer, func) try: func.built = False new_opytimizer.function = func except: func.built = True new_opytimizer.function = func assert type(new_opytimizer.function).__name__ == 'Function'
def test_opytimizer_space_setter(): space = search.SearchSpace(1, 1, 0, 1) func = function.Function(callable) optimizer = pso.PSO() new_opytimizer = opytimizer.Opytimizer(space, optimizer, func) try: space.built = False new_opytimizer.space = space except: space.built = True new_opytimizer.space = space assert type(new_opytimizer.space).__name__ == 'SearchSpace'
def test_opytimizer_start(): def square(x): return np.sum(x**2) new_function = function.Function(pointer=square) lb = [0, 0] ub = [10, 10] new_space = search.SearchSpace(lower_bound=lb, upper_bound=ub) new_pso = pso.PSO() new_opytimizer = opytimizer.Opytimizer(space=new_space, optimizer=new_pso, function=new_function) new_opytimizer.start(history=True)
def test_opytimizer_start(): def square(x): return np.sum(x**2) new_function = function.Function(pointer=square) lb = [0] ub = [10] new_space = search.SearchSpace(lower_bound=lb, upper_bound=ub) new_pso = pso.PSO() new_opytimizer = opytimizer.Opytimizer(space=new_space, optimizer=new_pso, function=new_function) history = new_opytimizer.start() assert isinstance(history, opytimizer.utils.history.History)
def test_opytimizer_total_iterations_setter(): space = search.SearchSpace(1, 1, 0, 1) func = function.Function(callable) optimizer = pso.PSO() new_opytimizer = opytimizer.Opytimizer(space, optimizer, func) try: new_opytimizer.total_iterations = 'a' except: new_opytimizer.total_iterations = 0 assert new_opytimizer.total_iterations == 0 try: new_opytimizer.total_iterations = -1 except: new_opytimizer.total_iterations = 0 assert new_opytimizer.total_iterations == 0