예제 #1
0
	def test_ga_optimise(self):
		# simple population processer function 
		# that just assigns fitness based on the sum of
		# a set of parameters
		def cpf(target, pop):
			print "cpf called!"
			fs_and_ps = []
			for ind in range(0, len(pop)):
				# fitness is a sum of the parameter settings
				# so higher parameter values should be selected for...
				f_and_p = {"fitness":sum(pop[ind]), "params":pop[ind]}
				fs_and_ps.append(f_and_p)
			return fs_and_ps

		iterations = 10
		fs = ga.ga_optimise(compute_population_fitnesses = cpf, 
				target = [[0.1], [0.1]], 
				param_count = ga.CONST_DX_PARAM_COUNT, 
				iterations = iterations, 
				pop_size = 1000, 
				crossovers = 3, 
				mutation_rate = 0.5	
				)
		self.assertEquals(len(fs), iterations)
		self.assertTrue(max(fs) <= ga.CONST_DX_PARAM_COUNT)
예제 #2
0
def ga_optimise(synth, param_count, target, output_dir, iterations = 10, pop_size = 500):
	fs = ga.ga_optimise(compute_population_fitnesses = ga.compute_population_fitnesses, 
				target = target, 
				synth = synth, 
				param_count = param_count, 
				iterations = iterations, 
				pop_size = pop_size, 
				crossovers = param_count / 5, 
				mutation_rate = 0.5, 
				log = True, 
				data_folder = output_dir)
	return fs
예제 #3
0
def ga_optimise(synth,
                param_count,
                target,
                output_dir,
                iterations=10,
                pop_size=500):
    fs = ga.ga_optimise(
        compute_population_fitnesses=ga.compute_population_fitnesses,
        target=target,
        synth=synth,
        param_count=param_count,
        iterations=iterations,
        pop_size=pop_size,
        crossovers=param_count / 5,
        mutation_rate=0.5,
        log=True,
        data_folder=output_dir)
    return fs
예제 #4
0
    def test_ga_optimise(self):
        # simple population processer function
        # that just assigns fitness based on the sum of
        # a set of parameters
        def cpf(target, pop):
            print "cpf called!"
            fs_and_ps = []
            for ind in range(0, len(pop)):
                # fitness is a sum of the parameter settings
                # so higher parameter values should be selected for...
                f_and_p = {"fitness": sum(pop[ind]), "params": pop[ind]}
                fs_and_ps.append(f_and_p)
            return fs_and_ps

        iterations = 10
        fs = ga.ga_optimise(compute_population_fitnesses=cpf,
                            target=[[0.1], [0.1]],
                            param_count=ga.CONST_DX_PARAM_COUNT,
                            iterations=iterations,
                            pop_size=1000,
                            crossovers=3,
                            mutation_rate=0.5)
        self.assertEquals(len(fs), iterations)
        self.assertTrue(max(fs) <= ga.CONST_DX_PARAM_COUNT)