From a13196da847f0b7bf8106be24fef97a93d577621 Mon Sep 17 00:00:00 2001 From: Kappes Marques Rodrigo <rodrigo.kappes@student-cs.fr> Date: Thu, 30 Jan 2020 09:19:58 +0100 Subject: [PATCH] cleaned the population --- __pycache__/individu.cpython-37.pyc | Bin 3877 -> 3877 bytes __pycache__/population.cpython-37.pyc | Bin 5882 -> 5102 bytes population.py | 52 +++++++++++--------------- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/__pycache__/individu.cpython-37.pyc b/__pycache__/individu.cpython-37.pyc index b5e349ab4911f800f7576808eaf3ee7522919618..3ef8c96f9616f2b5975f79ca003e59c0324ae6ae 100644 GIT binary patch delta 20 bcmZ1~w^WYXiI<m)fq{YHL$}dJZYh2MF(U+u delta 20 bcmZ1~w^WYXiI<m)fq{V`f4SjCZYh2ME<Xe$ diff --git a/__pycache__/population.cpython-37.pyc b/__pycache__/population.cpython-37.pyc index a2d00a0f413706a094887ce7f0dfe4f1e70ccd5f..f5ff9c148a75706fba3a62595b561aadc6eb2256 100644 GIT binary patch delta 267 zcmeyR`%azLiI<m)fq{YH%LJo1$%(v@j6oCCgIHOE88o>z_U&V2<eu!yl*7n1c^A`9 zM*hiLnBQ?rF)%QE25G6%oh;8SI*E;K@(GqgM(N2`tg{%!HeY33!pNvOxr+T0qx|Mv zjy;TwE|aym4lr76e$AD@$QU`<hvyh$$Yx>Q&5Vqhn~(F|WMu4`yinjKPZVcyYEEi$ zNoIat)Z{k7D#p6Wj6!P}?Iy1mQsZalVC7)v;^dO%lHwBO5}o`+sE93!r69kcbaH}- zs60nvT3TjuMrzSa1_p*=HjwKWc^EmEikul37&N&i*NK@jI!|6NBtH477{3r70|NsG RBM&1FqW~iZ6JI@pFaQSMM6dt= delta 1008 zcmaE-{!5qFiI<m)fq{YH(=x+2y@|Y%j7byKgG9MfxLX*axKemhcv~2vxKmhz88rDe z*6m|t<eY5Fl*7m|c@@)7MxMz_nBQ@WF)%QE1{qPMJDHzbbn*vQw#hqK3K_*GYq8E^ z6xw{0bqOP*>f|i;PmI!=V>$LPGTKj;;yS=+y7@L&0wZJSWE-Aii~*aOc{ejMrflBM zcaxE^dGbVon>@ETi&Jw_lS?x5^KMNp6Rct^pZrm9Eu+Ka`9f;^j2tW+Y+RgNQe4tp zB3#0guLu<}-kR(#tXw~dfq|iz4dft39!3tPA~yyGhGY;Igqau^7?>Ft7@R?hf*2SW zN*GcYn;B~vN*Gg^ni&}xD#U6SvY1>LVtHyAYZw<WFJxe3D3l0iC}F8#0Lj-dWU<yT zWU-|%_cAhqbg_U$VX`R<!SxK9tbQ+97#J9;#JLm#`~yOL978<){S-X?JVQJkeOwi| zG#QI*LGl7z3PG*`LH;hG&R`W>n(RgF3=9lKE+B#rL|B6ekPnI+KrDR*1_n*0B3BSw z97J%y32p`khFdHpsrAJrGeDjb0C|^@gOP)g2NVvBe2g57MIOju0dgZKoWNmGfD{%L zRy7P+j4lkZ2DOYSOexGQ3?)n{EX|BA49$$SOew4jm}{6)*isl;nIst&GS)KJFfL#L zhm$}!Ly0463OhJR*kA#+fE^@R!kWT?ES|y;%%I8X_Y#!)k{LmcWnf?cMGx!bg^VHr zHH-@wQWzF8PGl-%31-k_yv4|+$#{#csJNskvp|!nh!gDHoXot`BGfP_;$dK5SPlvS zkYQ{LRgxvC#U)0Q16f7ts{{&i5{q*)Q{pYM_0kfHOA>D}6d8e{LYhkfM`S5*Rf%wM zIR*r|1}g-+`nW=)ic6CN5?7#Ty2X-TkeYXkB`ZHOuLvAv;1~qQn;9s|Sin){Uj&M? zTO1%)`(zfE++s;8%FIJ^|1DOqdzXNGAOZ>&a107D3V~x06rUW7MWB?c$uqe@*pwS= l2`FBRf+o)w5}$llm|skYfq?-M?*fb*OnmhWJREEsJOF}c&h7vJ diff --git a/population.py b/population.py index 618126d..fbb42ef 100644 --- a/population.py +++ b/population.py @@ -5,16 +5,20 @@ from croisement import croisement_un_point, croisement_deux_points import copy class Population: + + #Class initialization def __init__(self,n): self.indiv=[Individu(RotTable()) for k in range (n)] self.n = n - + + #Updates the current individuals in the population def modifier_population(self, liste_individus): """Fonction qui renvoie une nouvelle instance de population a partir d'une liste d'individus""" self.n = len(liste_individus) self.indiv = liste_individus return self + #Select a fixed number of individuals in a population def selection_p_best(self,p=None): if p==None: p=(self.n)//2 @@ -23,7 +27,7 @@ class Population: individus_selectionnes = [element for element in liste_individus[:p]] self = self.modifier_population(individus_selectionnes) - + #Select via comparing two random individuals with some randomness involved and compared def selection_duel_pondere(self,p=None): if p == None : p = (self.n)//2 @@ -33,7 +37,8 @@ class Population: meilleur = individu newself=[meilleur] m=randrange(0,self.n) - t=randrange(0,self.n) #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer + t=randrange(0,self.n) + #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer non_vu = [i for i in range(0, self.n)] while len(newself)<p: m = choice(non_vu) @@ -50,6 +55,7 @@ class Population: self = self.modifier_population(newself) + #Selection via comparing the player`s score randomly def selection_duel(self,p=None): if p == None : p = (self.n)//2 @@ -75,8 +81,7 @@ class Population: newself.append(y) self = self.modifier_population(newself) - - + #Selection using a random method to select players based on their rank in score def selection_par_rang(self,p = None): if p == None : p = (self.n)//2 @@ -97,6 +102,7 @@ class Population: self = self.modifier_population(individus_selectionnes) + #Selecting using a random method that takes the score into ponderation def selection_proportionnelle(self,p= None): if p == None : p = (self.n)//2 @@ -116,8 +122,12 @@ class Population: newself.append(x) self = self.modifier_population(newself) + #The Function that makes the selection and reduces the quantity of players + #and after reproduces and mutates the remaining ones into a new population def reproduction(self,proba_mutation = None, selection=None,enfant=croisement_un_point, p = None): liste_selections = [self.selection_p_best, self.selection_duel_pondere, self.selection_duel, self.selection_par_rang, self.selection_proportionnelle] + + #Values of variables if there are no initial conditions if proba_mutation == None : proba_mutation = 0.001 if selection == None : @@ -126,14 +136,19 @@ class Population: selection = liste_selections[selection] if p == None : p = (self.n)//2 + + vieille_taille = self.n selection(p) newself = [element for element in self.indiv] while len(newself)<vieille_taille: m=randrange(0,self.n) t=randrange(0,self.n) + #We have to make a deep copy so we dont lose the values of the parents x=copy.deepcopy(newself[m]) y=copy.deepcopy(newself[t]) + + #Creation of the childs couple_enfant = enfant(x,y) for child in couple_enfant : child.mutation_close_values(proba_mutation, number_of_mutations = 2) @@ -142,40 +157,15 @@ class Population: newself.append(couple_enfant[1]) self = self.modifier_population(newself) - +#Prints the current population(used for debugging) def afficher(popu): for individu in popu.indiv : print("\n individu \n") # print(individu.table.rot_table) print ("score", individu.score) - -def test(): - popu = Population(4) - print("\n POPULATION INITIALE \n") - for individu in popu.indiv : - individu.evaluate() - afficher(popu) - popu.reproduction(selection = popu.selection_duel) - print("\n REPRODUCTION \n") - afficher(popu) - -#test() -def test2(): - popu = Population(10) - for individu in popu.indiv : - lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] - brin = ''.join(lineList[1:]) - individu.evaluate() - print("\n \n POPULATION INITIALE \n \n") - afficher(popu) - popu.selection_proportionnelle() - print("\n\nAPRES SELECTION \n\n") - afficher(popu) - -# test2() -- GitLab