######## TableauFourmis ####### TableauFourmis = np.zeros((NbIndividus,), dtype=np.int64) ######## Conditions initiales ######## intervals_init = [1,2,5,10,20,25,50,100] #8 distributions initiales différentes / 8 simulations différentes for i in range(c_moyenne*(NbIndividus/intervals_init[numero-1])): while True: fourmis = randint(0,NbIndividus-1) if TableauFourmis[fourmis]+intervals_init[numero-1] <= capaciteStock: TableauFourmis[fourmis]+= intervals_init[numero-1] break ##### Main ##### data = evolution(TableauFourmis,NbSimul,NbIndividus,capaciteStock,ChargeUnit) ####### Ecriture du tableau dans un fichier ####### table_std = np.array(data).std(axis=1) print data[7]-data[8] #np.savetxt('std_%02ipdt_%02i_charge_%02i.txt' % (NbSimul,numero,c_moyenne), table_std) print "Done!"
import cv2 as cv import numpy as np from random import randint import math as math from evolution import * from population import * from path import * from point import * from main_window import * if __name__ == '__main__': window = mainWindow() n = 5 pop_count = 5 evo = evolution(pop_count, n, window.height, window.width) window.drawPop(evo.pop) while (True): cv.imshow(window.window_name, window.tmp_map) window.key = cv.waitKey(0) if (window.key == esc): break cv.destroyAllWindows()
def ProbaRecevoir(charge, capaciteStock): l = charge * 1. / capaciteStock if 0 < l < 1: return -2 * l**2 + 1.5 * l + 0.5 elif l == 0: return 1 else: return 0 ######## Conditions initiales ######## TableauFourmis = np.loadtxt( 'newData/donneesVague/10000fourmis/snapshot5000_%02i_charge_%02i.txt' % (numero, c_moyenne)) ##### Main ##### datas = evolution(TableauFourmis, NbSimul, NbIndividus, capaciteStock, ChargeUnit) ####### Ecriture du tableau dans un fichier ####### np.savetxt( 'newData/donneesVague/10000fourmis/snapshot5000_%02i_charge_%02i.txt' % ( numero, c_moyenne, ), np.array(datas)[:, -1]) print "Done!"
alf=3 # coefficient of the weighted area term Ag(\phi); # Note: Choose a positive(negative) alf if the # initial contour is outside(inside) the object. nrow, ncol=Img.shape c0=4 initialLSF=c0*np.ones((nrow,ncol)) w=8 initialLSF[w+1:-w-1, w+1:-w-1]=-c0 u=initialLSF #plot_u(u) plt.ion() for n in range(300): u=evolution(u, g ,lam, mu, alf, epsilon, timestep, 1) if np.mod(n,20)==0: #plot_u(u) plt.imshow(Img, cmap='gray') plt.hold(True) CS = plt.contour(u,0, colors='r') plt.draw() time.sleep(1) plt.hold(False)
for idx in range(n_datasets): dataset, cov_mat = create_input_data(num_points, num_dimensions, max_var_input, seed + idx) datasets.append(dataset) initial_weights = initialize_weights(num_dimensions, rng) initial_weights_per_dataset.append(initial_weights) pc0 = calculate_eigenvector_for_largest_eigenvalue(cov_mat) pc0_per_dataset.append(pc0) pc0_empirical = compute_first_pc(dataset) pc0_empirical_per_dataset.append(pc0_empirical) [history, champion] = evolution(datasets, pc0_per_dataset, initial_weights_per_dataset, population_params, genome_params, ea_params, evolve_params, learning_rate, alpha, fitness_mode) rng.seed(seed) champion_learning_rule = cgp.CartesianGraph(champion.genome).to_numpy() champion_fitness, champion_weights_per_dataset = calculate_fitness( champion_learning_rule, datasets, pc0_per_dataset, initial_weights_per_dataset, learning_rate, alpha, fitness_mode) champion_sympy_expression = champion.to_sympy() # evaluate hypothetical fitness of oja rule rng.seed(seed) oja_fitness, oja_weights_per_dataset = calculate_fitness( oja_rule, datasets, pc0_per_dataset, initial_weights_per_dataset, learning_rate, alpha, fitness_mode)
material = [[1000, 0, 2*pi, 0], [20000, 0, 2*pi, 0], [5000, 1e-3, 2*pi, 0], [5000, 1e-3, 2*pi, pi]] # environment = environment(2) # environment.checkerBoard(10) population_info=init_sphere() past_population=population_info data_management=data() for decade in range(1,century): for gen in range(1,generation): print('Generation: {}'.format(gen*decade)) past_population=population_info digiEvol = evolution(population=population_info) digiEvol.mutation_size() digiEvol.mutation_center() population_info=digiEvol.crossover() for people in population_info: print('Robot: {}'.format(people+1)) robot_sim=robot(init_pos=init_pos,nMass=nMass,edge=edge_length) mass=robot_sim.cube() spring=robot_sim.genSpring(spherePos=population_info[people]['sphere']) # robot_sim.showBalls(spherePos=population_info[people]['sphere']) calculate=calculation(mass=mass,spring=spring,material=material) # calculate.init_anime() calculate.sim(time=3,delta=0.001) # calculate.invisible() inst_fitness=calculate.fitness() if inst_fitness > population_info[people]['fitness']:
alf = 3 # coefficient of the weighted area term Ag(\phi); # Note: Choose a positive(negative) alf if the # initial contour is outside(inside) the object. nrow, ncol = Img.shape c0 = 4 initialLSF = c0 * np.ones((nrow, ncol)) w = 8 initialLSF[w + 1:-w - 1, w + 1:-w - 1] = -c0 u = initialLSF #plot_u(u) plt.ion() for n in range(300): u = evolution(u, g, lam, mu, alf, epsilon, timestep, 1) if np.mod(n, 20) == 0: #plot_u(u) plt.imshow(Img, cmap='gray') plt.hold(True) CS = plt.contour(u, 0, colors='r') plt.draw() time.sleep(1) plt.hold(False)