Commits (5)
 ... ... @@ -127,9 +127,21 @@ Most exercises consists in adding a single function in an existing module 2. Implement an evolutionary algorithm. You can use `num_genetic` or `bit_genetic` 3. Implement an expected run time empirical cumulative density function. You can call `draw_ert.py` with -N option for the number of run and -v option to choose a target value You can execute `ert.py` which will plot 3 ert for two algorithms. You can also use `draw_ert.py` with -N option for the number of run and optionally -v option to choose a target value (if not use will draw a surface for all target) 4. Implement a simple design of experiment to determine the best solver. You can use `try_solver.py` to list the different parameter you want to try and get the best parameter You can use `try_solver.py` to list the different parameter you want to try and get the best parameter (parameter inside the script) 5. Provide a solver for a competition. For the competion, symply use my `num_greedy` For the competion, symply use my `snp.py`. I have had the following penalisation to `num.py` : ```python3 if len(sol) > dim: s *= 0.5 for v in sol: if v < 0: s += v/domain_width if v >= domain_width: s -= (v-domain_width)/domain_width ```
 ... ... @@ -97,13 +97,6 @@ if __name__=="__main__": X, Y = np.meshgrid(temps, values) Z = probability(data,X,Y) print(Z) """ fig, ax = plt.subplots() cs = ax.contourf(X, Y, Z, 20) cbar = fig.colorbar(cs) """ proba = np.linspace(0.0, 1.0, 11) cs = plt.contourf(X, Y, Z, levels=proba) ... ...
 ... ... @@ -3,11 +3,11 @@ import json import numpy as np import matplotlib.pyplot as plt Nb_run = 3 Nb_run = 50 solvers = [ '-m num_greedy -n 45 -i 5 -r 0.08 -t 10000 -w 100 -a 0.01', '-m bit_greedy -n 45 -i 5 -r 0.08 -t 10000 -w 100 -a 0.01' '-m num_greedy', '-m bit_greedy' ] datas = [] ... ... @@ -50,7 +50,7 @@ def probability(data,time,value): probability = np.vectorize(probability, excluded=[0]) j = 1 for v in [8379,8380,8400]: for v in [640,660,670]: for i in range(len(solvers)): plt.subplot(320+j) P = probability(datas[i],range(1,temps_max+1),v) ... ...
 ... ... @@ -140,7 +140,7 @@ def neighb_square(sol, scale, domain_width): # Crossover ######################################################################## def crossover(sol1, sol2): def rand_crossover(sol1, sol2): x = [] y = [] sol = sol1 + sol2 ... ... @@ -157,3 +157,37 @@ def crossover(sol1, sol2): domain[y[i]][x[i]] = 1 return domain def split_crossover(sol1, sol2): p1 = np.array(to_sensors(sol1)) p2 = np.array(to_sensors(sol2)) sol = np.concatenate((p1,p2)) x = sol[::2] m = np.median(x) r = [] for p in p1: if p[0] <= m: r.append(p) for p in p2: if p[0] > m: r.append(p) if len(r) < len(p1): q = [] for p in p1: if p[0] > m: q.append(p) for p in p2: if p[0] <= m: q.append(p) for i in np.random.randint(0,len(p),(len(p1)-len(r))): r.append(q[i]) while len(r) > len(p1): r.pop(np.random.randint(0,len(r))) rmatrix = np.zeros((len(sol1),len(sol1))) for p in r: rmatrix[p[0],p[1]] = 1 return rmatrix
 ... ... @@ -123,7 +123,7 @@ def neighb_square(sol, scale, domain_width): # Crossover ######################################################################## def crossover(sol1, sol2): def rand_crossover(sol1, sol2): sol = np.concatenate((sol1, sol2)) v = np.random.randint(0, len(sol) // 2, len(sol1) // 2) r = [] ... ... @@ -132,3 +132,39 @@ def crossover(sol1, sol2): r.append(sol[2*i+1]) return r def split_crossover(sol1, sol2): sol = np.concatenate((sol1,sol2)) x = sol[::2] m = np.median(x) r = [] for i in range(len(sol1)//2): if sol1[2*i] <= m: r.append(sol1[2*i]) r.append(sol1[2*i+1]) for i in range(len(sol2)//2): if sol2[2*i] > m: r.append(sol2[2*i]) r.append(sol2[2*i+1]) if len(r) < len(sol1): q = [] for i in range(len(sol1)//2): if sol1[2*i] > m: q.append(sol1[2*i]) q.append(sol1[2*i+1]) for i in range(len(sol2)//2): if sol2[2*i] <= m: q.append(sol2[2*i]) q.append(sol2[2*i+1]) for i in np.random.randint(0,len(q)//2,(len(sol1)-len(r))//2): r.append(q[2*i]) r.append(q[2*i+1]) while len(r) > len(sol1): i = np.random.randint(0,len(r)//2) r.pop(2*i) r.pop(2*i) return r
 ... ... @@ -177,7 +177,7 @@ if __name__=="__main__": make.init(num.rand, dim = d * the.nb_sensors, scale = the.domain_width), num.crossover, num.split_crossover, make.neig(num.neighb_square, scale = the.variation_scale, domain_width = the.domain_width), ... ... @@ -195,7 +195,7 @@ if __name__=="__main__": make.init(bit.unif, domain_width = the.domain_width, nb_sensors = the.nb_sensors), bit.crossover, bit.split_crossover, make.neig(bit.neighb_square, scale = the.variation_scale, domain_width = the.domain_width), ... ...