How to use the deap.tools.selTournamentDCD function in deap

To help you get started, we’ve selected a few deap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nilinswap / neuro-evolution / postmidsem / codes / main_folder / pilot / main1.py View on Github external
logbook.record(gen=0, evals=len(invalid_ind), **record)
	print(logbook.stream)
	maxi = 0
	stri = ''
	flag= 0
	# Begin the generational process
	# print(pop.__dir__())
	time4 = time.time()
	for gen in range(1, NGEN):
		
		# Vary the population
		if gen == 1:
			time6 = time.time()
		if gen == NGEN-1:
			time7 = time.time()
		offspring = tools.selTournamentDCD(pop, len(pop))
		offspring = [toolbox.clone(ind) for ind in offspring]
		if gen == 1:
			print("1st gen after clone",time.time() - time6)
		if gen == NGEN-1:
			print("last gen after clone", time.time() - time7)
		if play :
			if play == 1:
				pgen = NGEN*0.1
			elif play == 2 :
				pgen = NGEN*0.9

			if gen == int(pgen):
				print("gen:",gen, "doing clustering")
				to_bp_lis = cluster.give_cluster_head(offspring, int(MU*bp_rate))
				assert (to_bp_lis[0] in offspring )
				print( "doing bp")
github nilinswap / neuro-evolution / main1_nll_mse_misc_com.py View on Github external
# print(pop)
	record = stats.compile(pop_tar)
	logbook.record(gen=0, evals=len(invalid_ind), **record)
	print(logbook.stream)
	maxi = 0
	stri = ''
	flag= 0
	# Begin the generational process
	# print(pop.__dir__())
	NGEN = NGEN
	for gen in range(1, NGEN):

		# Vary the population
		print()
		print("here in gen no.", gen)
		offspring = tools.selTournamentDCD(pop_tar, len(pop_tar))
		offspring = [toolbox.clone(ind) for ind in offspring]
		if play :
			if play == 1:
				pgen = NGEN*0.1
			elif play == 2 :
				pgen = NGEN*0.9

			if gen == int(pgen):
				print("gen:",gen, "doing clustering")
				to_bp_lis = cluster.give_cluster_head(offspring, int(MU*bp_rate))
				assert (to_bp_lis[0] in offspring )
				print( "doing bp")
				[ item.modify_thru_backprop(indim, outdim, network_obj_tar.rest_setx, network_obj_tar.rest_sety, epochs=20, learning_rate=0.1, n_par=10) for item in to_bp_lis]
				# Evaluate the individuals with an invalid fitness
				invalid_ind = [ind for ind in offspring if not ind.fitness.valid]
				fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
github nilinswap / neuro-evolution / main1_perc_nll_mse_misc_com.py View on Github external
# print(pop)
	record = stats.compile(pop_tar)
	logbook.record(gen=0, evals=len(invalid_ind), **record)
	print(logbook.stream)
	maxi = 0
	stri = ''
	flag= 0
	# Begin the generational process
	# print(pop.__dir__())
	NGEN = NGEN
	for gen in range(1, NGEN):

		# Vary the population
		print()
		print("here in gen no.", gen)
		offspring = tools.selTournamentDCD(pop_tar, len(pop_tar))
		offspring = [toolbox.clone(ind) for ind in offspring]
		if play :
			if play == 1:
				pgen = NGEN*0.1
			elif play == 2 :
				pgen = NGEN*0.9

			if gen == int(pgen):
				print("gen:",gen, "doing clustering")
				to_bp_lis = cluster.give_cluster_head(offspring, int(MU*bp_rate))
				assert (to_bp_lis[0] in offspring )
				print( "doing bp")
				[ item.modify_thru_backprop(indim, outdim, network_obj_tar.rest_setx, network_obj_tar.rest_sety, epochs=20, learning_rate=0.1, n_par=10) for item in to_bp_lis]
				# Evaluate the individuals with an invalid fitness
				invalid_ind = [ind for ind in offspring if not ind.fitness.valid]
				fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
github ContinuumIO / elm / elm / model_selection / evolve.py View on Github external
assign_names(pop)
    fitnesses = (yield (pop, invalid_ind, param_history))
    assign_check_fitness(invalid_ind, fitnesses,
                     param_history, deap_params['choices'],
                     evo_params['score_weights'])
    # Forces assignment of crowding distance for
    # NSGA2 - no selection is done here
    pop = toolbox.select(pop, len(pop))
    # Find the best in original population for
    # comparison on stop conditions
    temp_pop = copy.deepcopy(pop)
    original_fitness = toolbox.select(temp_pop, 1)[0].fitness.values
    del temp_pop
    eval_stop = eval_stop_wrapper(evo_params, original_fitness)
    for gen in range(1, ngen):
        offspring1 = tools.selTournamentDCD(pop, len(pop))

        offspring2 = [toolbox.clone(ind) for ind in offspring1]
        offspring3 = []
        for off1, off2 in zip(offspring1, offspring2):
            off2.name = off1.name
            offspring3.append(off2)
        offspring = offspring3
        try:
            for ind1, ind2 in zip(offspring[::2], offspring[1::2]):
                if random.random() <= cxpb:
                    toolbox.mate(ind1, ind2)
                if random.random() < mutpb:
                    toolbox.mutate(ind1)
                if random.random() < mutpb:
                    toolbox.mutate(ind2)
                del ind1.fitness.values, ind2.fitness.values
github nilinswap / neuro-evolution / main1_perc_nll_mse_misc_com.py View on Github external
maxi = 0
	stri = ''
	flag= 0
	# Begin the generational process
	# print(pop.__dir__())
	time4 = time.time()
	for gen in range(1, NGEN):

		# Vary the population
		if gen == 1:
			time6 = time.time()
		if gen == NGEN-1:
			time7 = time.time()
		print()
		print("here in gen no.", gen)
		offspring = tools.selTournamentDCD(pop_src, len(pop_src))
		offspring = [toolbox.clone(ind) for ind in offspring]
		if play :
			if play == 1:
				pgen = NGEN*0.1
			elif play == 2 :
				pgen = NGEN*0.9

			if gen == int(pgen):
				print("gen:",gen, "doing clustering")
				to_bp_lis = cluster.give_cluster_head(offspring, int(MU*bp_rate))
				assert (to_bp_lis[0] in offspring )
				print( "doing bp")
				[ item.modify_thru_backprop(indim, outdim, network_obj_src.rest_setx, network_obj_src.rest_sety, epochs=20, learning_rate=0.1, n_par=10) for item in to_bp_lis]

				# Evaluate the individuals with an invalid fitness
				invalid_ind = [ind for ind in offspring if not ind.fitness.valid]
github DEAP / deap / examples / ga / nsga2.py View on Github external
fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
    for ind, fit in zip(invalid_ind, fitnesses):
        ind.fitness.values = fit

    # This is just to assign the crowding distance to the individuals
    # no actual selection is done
    pop = toolbox.select(pop, len(pop))
    
    record = stats.compile(pop)
    logbook.record(gen=0, evals=len(invalid_ind), **record)
    print(logbook.stream)

    # Begin the generational process
    for gen in range(1, NGEN):
        # Vary the population
        offspring = tools.selTournamentDCD(pop, len(pop))
        offspring = [toolbox.clone(ind) for ind in offspring]
        
        for ind1, ind2 in zip(offspring[::2], offspring[1::2]):
            if random.random() <= CXPB:
                toolbox.mate(ind1, ind2)
            
            toolbox.mutate(ind1)
            toolbox.mutate(ind2)
            del ind1.fitness.values, ind2.fitness.values
        
        # Evaluate the individuals with an invalid fitness
        invalid_ind = [ind for ind in offspring if not ind.fitness.valid]
        fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
        for ind, fit in zip(invalid_ind, fitnesses):
            ind.fitness.values = fit
github nilinswap / neuro-evolution / main / codes / others / pilot2 / main1.py View on Github external
# This is just to assign the crowding distance to the individuals
    # no actual selection is done
    pop = toolbox.select(pop, len(pop))
    # print(pop)
    record = stats.compile(pop)
    logbook.record(gen=0, evals=len(invalid_ind), **record)
    print(logbook.stream)
    maxi = 0
    stri = ''
    flag= 0
    # Begin the generational process
    # print(pop.__dir__())
    for gen in range(1, NGEN):

        # Vary the population
        offspring = tools.selTournamentDCD(pop, len(pop))
        offspring = [toolbox.clone(ind) for ind in offspring]
        if play :
            if play == 1:
                pgen = NGEN*0.1
            elif play == 2 :
                pgen = NGEN*0.9

            if gen == int(pgen):
                print("gen:",gen, "doing clustering")
                to_bp_lis = cluster.give_cluster_head(offspring, int(MU*bp_rate))
                assert (to_bp_lis[0] in offspring )
                print( "doing bp")
                [ item.modify_thru_backprop(indim, outdim, network_obj.rest_setx, network_obj.rest_sety, epochs=10, learning_rate=0.1, n_par=10) for item in to_bp_lis]

        for ind1, ind2 in zip(offspring[::2], offspring[1::2]):
            # print(ind1.fitness.values)