def test_invalid_value_of_w_negative(self): psClass.num_of_iterations = 10 psClass.num_of_particles = 10 psClass.value_of_w = -2 return_message = psClass.check_parameters_execute_pso(False) self.assertTrue('Invalid'.lower() in return_message.lower())
def __init__(self, param_bounds): """ Initialize the optimization environment :param param_bounds: Legal parameter bounds """ super(_PSOptimiser, self).__init__() self.param_bounds = param_bounds self.num_params = len(self.param_bounds) self.optimiser = ParticleSwarm.Optimiser() self.optimiser.log = self.__log self.optimiser.omega = 0.9 self.optimiser.max_initial_velocity = 0.02 self.optimiser.particle_count = 50 self.optimiser.max_iterations = 50 self.optimiser.phi_particle = 0.3 self.optimiser.phi_swarm = 0.1 _log('# algorithm = {0}'.format(self.__class__.__name__)) _log('# timeout = {0}'.format(self.optimiser.timeout)) _log('# max_iterations = {0}'.format( self.optimiser.max_iterations)) _log('# particle_count = {0}'.format( self.optimiser.particle_count)) _log('# max_initial_velocity = {0}'.format( self.optimiser.max_initial_velocity)) _log('# omega = {0}'.format(self.optimiser.omega)) _log('# phi_particle = {0}'.format( self.optimiser.phi_particle)) _log('# phi_swarm = {0}'.format(self.optimiser.phi_swarm))
def test_invalid_value_upper_c1(self): psClass.num_of_iterations = 10 psClass.num_of_particles = 10 psClass.value_of_w = 0.3 psClass.value_of_c1 = 4 psClass.value_of_c2 = 0.5 return_message = psClass.check_parameters_execute_pso(False) self.assertTrue('Invalid'.lower() in return_message.lower())
def test_arg_parse(self): result = psClass.parse_arguments(['100', '100', '0.3', '0.2', '0.5']) self.assertEqual(result.num_iteration, 100) self.assertEqual(result.num_particle, 100) self.assertEqual(result.w, 0.3) self.assertEqual(result.c1, 0.2) self.assertEqual(result.c2, 0.5)
def __init__(self, dim, num, swarm, model, time_bound): self.pso = ParticleSwarm(dim, num, swarm, model) self.model = model self.time_bound = time_bound self.new_level = model.J self.control = np.array(np.zeros([1, dim])) self.ph = 0 self.dim = dim self.Num = num
def test_ackley_positive(self): print("start of test_ackley_positive.\n") num_of_particles = 50 result_arr = [] search_in_pso = psClass.PSO(num_of_particles) particles_vector = [ psClass.Particle() for _ in range(search_in_pso.num_of_particles) ] search_in_pso.particles = particles_vector for p in search_in_pso.particles: result = search_in_pso.ackley(p.position) result_arr.append(result) self.assertGreater(min(result_arr), 0) print("Ackley function is positive.") print("end of test_ackley_positive.\n")
def test_pso_parameterOptionThree(self): print("start of test_pso_parameterOptionThree.\n") psClass.num_of_particles = 50 psClass.num_of_iterations = 50 psClass.value_of_w = 0.3 psClass.value_of_c1 = 0.2 psClass.value_of_c2 = 0.5 arr = psClass.execute_pso(False) self.assertGreater(0.1, abs(arr[5])) self.assertGreater(0.1, abs(arr[6])) print("end of test_pso_parameterOptionThree.\n")
def __init__(self, param_bounds): """ Initialize the optimization environment :param param_bounds: Legal parameter bounds """ super(_PSOptimizer, self).__init__() self.param_bounds = param_bounds self.num_params = len(self.param_bounds) self.optimizer = ParticleSwarm.Optimizer() self.optimizer.log = self.__log self.optimizer.omega = 0.9 self.optimizer.max_initial_velocity = 0.02 self.optimizer.population_size = 50 self.optimizer.max_iterations = 50 self.optimizer.phi_particle = 0.3 self.optimizer.phi_swarm = 0.1
def test_invalid_num_of_iterations(self): psClass.num_of_iterations = -1 psClass.num_of_particles = 10 return_message = psClass.check_parameters_execute_pso(False) self.assertTrue('Invalid'.lower() in return_message.lower())