Example #1
0
def run_test():
	from PyGMO import problem, algorithm, island
	from numpy import mean, std
	number_of_trials = 200
	number_of_individuals = 20
	number_of_generations = 500

	prob_list = [problem.schwefel(10), problem.rastrigin(10), problem.rosenbrock(10), problem.ackley(10), problem.griewank(10)]
	algo_list = [algorithm.pso(number_of_generations), algorithm.de(number_of_generations,0.8,0.8,2),algorithm.sa_corana(number_of_generations*number_of_individuals,1,0.1), algorithm.ihs(number_of_generations*number_of_individuals), algorithm.sga(number_of_generations,0.8,0.1)]

	for prob in prob_list:
		print('\nTesting problem: ' + str(type(prob)) + ', Dimension: ' + str(prob.dimension))
		for algo in algo_list:
			print(' ' + str(algo))
			best = []
			best_x = []
			for i in range(0,number_of_trials):
				isl = island(algo,prob,number_of_individuals)
				isl.evolve(1)
				isl.join()
				best.append(isl.population.champion.f)
				best_x.append(isl.population.champion.x)
			print(' Best:\t' + str(min(best)[0]))
			print(' Mean:\t' + str(mean(best)))
			print(' Std:\t' + str(std(best)))
Example #2
0
def example_2(algo=algorithm.de(1), prob = problem.rosenbrock(10), topo = topology.barabasi_albert(3,3), n_evolve = 100, n_isl = 1024, pop_size = 20, color_code='rank'):
	from PyGMO import problem, algorithm, island, archipelago
	from matplotlib.pyplot import savefig, close
	archi = archipelago(algo,prob,n_isl,pop_size,topology=topo)
	print "Drawing Initial Condition .. "
	pos = archi.draw(scale_by_degree=True,n_size=3,e_alpha=0.03, n_color = color_code)
	savefig('archi000', dpi = 72)
	close()
	for i in range(1,n_evolve):
		archi.evolve(1); 
		archi.join();
		print "Drawing"+ str(i) +  "-th evolution .. "
		pos = archi.draw(layout = pos, scale_by_degree=True,n_size=3,e_alpha=0.03, n_color = color_code)
		savefig('archi%03d' % i, dpi = 72);  
		close()
Example #3
0
def run_test():
    from PyGMO import problem, algorithm, island
    from numpy import mean, std
    number_of_trials = 200
    number_of_individuals = 20
    number_of_generations = 500

    prob_list = [
        problem.schwefel(10),
        problem.rastrigin(10),
        problem.rosenbrock(10),
        problem.ackley(10),
        problem.griewank(10)
    ]
    algo_list = [
        algorithm.pso(number_of_generations),
        algorithm.de(number_of_generations, 0.8, 0.8, 2),
        algorithm.sa_corana(number_of_generations * number_of_individuals, 1,
                            0.1),
        algorithm.ihs(number_of_generations * number_of_individuals),
        algorithm.sga(number_of_generations, 0.8, 0.1)
    ]

    for prob in prob_list:
        print('\nTesting problem: ' + str(type(prob)) + ', Dimension: ' +
              str(prob.dimension))
        for algo in algo_list:
            print(' ' + str(algo))
            best = []
            best_x = []
            for i in range(0, number_of_trials):
                isl = island(algo, prob, number_of_individuals)
                isl.evolve(1)
                isl.join()
                best.append(isl.population.champion.f)
                best_x.append(isl.population.champion.x)
            print(' Best:\t' + str(min(best)[0]))
            print(' Mean:\t' + str(mean(best)))
            print(' Std:\t' + str(std(best)))
Example #4
0
def run_test(n_trials=200, pop_size = 20, n_gen = 500):
	"""
	This function runs some tests on the algorthm. Use it to verify the correct installation
	of PyGMO.

	USAGE: PyGMO.run_test(n_trials=200, pop_size = 20, n_gen = 500)

	* n_trials: each algorithm will be called n_trials times on the same problem to then evaluate best, mean and std
	* pop_size: this determines the population size 
	* n_gen: this regulates the maximim number of function evaluation

	"""
	from PyGMO import problem, algorithm, island
	from numpy import mean, std
	number_of_trials = n_trials
	number_of_individuals = pop_size
	number_of_generations = n_gen

	prob_list = [problem.schwefel(dim = 10), problem.rastrigin(dim = 10), problem.rosenbrock(dim = 10), problem.ackley(dim = 10), problem.griewank(dim = 10), problem.levy5(10)]
	if __extensions__['gtop']:
		prob_list.append(problem.cassini_1())
		prob_list.append(problem.gtoc_1())
		prob_list.append(problem.cassini_2())
		prob_list.append(problem.messenger_full())
		
	algo_list = [algorithm.pso(gen = number_of_generations), algorithm.mde_pbx(gen = number_of_generations, xtol=1e-30, ftol=1e-30), algorithm.de(gen = number_of_generations,xtol=1e-30, ftol=1e-30), algorithm.jde(gen = number_of_generations, memory=False,xtol=1e-30, ftol=1e-30), algorithm.de_1220(gen = number_of_generations, memory=False,xtol=1e-30, ftol=1e-30), algorithm.sa_corana(iter = number_of_generations*number_of_individuals,Ts = 1,Tf = 0.01), algorithm.ihs(iter = number_of_generations*number_of_individuals), algorithm.sga(gen = number_of_generations), algorithm.cmaes(gen = number_of_generations,xtol=1e-30, ftol=1e-30, memory=False), algorithm.bee_colony(gen = number_of_generations/2)]
	print('\nTrials: ' + str(n_trials) + ' - Population size: ' + str(pop_size) + ' - Generations: ' + str(n_gen))
	for prob in prob_list:
		print('\nTesting problem: ' + prob.get_name() + ', Dimension: ' + str(prob.dimension) )
		print('With Population Size: ' +  str(pop_size) )
		for algo in algo_list:
			print(' ' + str(algo))
			best = []
			best_x = []
			for i in range(0,number_of_trials):
				isl = island(algo,prob,number_of_individuals)
				isl.evolve(1)
				isl.join()
				best.append(isl.population.champion.f)
				best_x.append(isl.population.champion.x)
			print(' Best:\t' + str(min(best)[0]))
			print(' Mean:\t' + str(mean(best)))
			print(' Std:\t' + str(std(best)))