diff --git a/RotTable.py b/RotTable.py index eae09ce1cd9a1b36484f43c62794e629d0653542..efdebce4cf42480c3be6c111f39fcce5c4cfa90e 100644 --- a/RotTable.py +++ b/RotTable.py @@ -24,26 +24,29 @@ class RotTable: "TT": [35.62, 7.2, -154, 0.06, 0.6, 0]\ } + # get the angles in each axis (x, y, z), considering the deviation def __init__(self): self.rot_table = {} for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE: self.rot_table[dinucleotide] = RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][:3] self.alea() - + # get a random deviation, considering the "limits" given in the last 3 columns + # of __ORIGINAL_ROT_TABLE def alea(self): for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE: for i in range(2): self.rot_table[dinucleotide][i] += numpy.random.uniform(low = -RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3], high= RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][i+3]) + # return __ORIGINAL_ROT_TABLE def orta(self): return self.__ORIGINAL_ROT_TABLE ################### # WRITING METHODS # ################### -#table = RotTable() -#table.rot_table["AA"] --> [35.62, 7.2, -154] + #table = RotTable() + #table.rot_table["AA"] --> [35.62, 7.2, -154] ################### # READING METHODS # @@ -63,3 +66,4 @@ class RotTable: table1 = RotTable() print(table1.orta()) +print(table1.rot_table["AA"]) diff --git a/__pycache__/Initialisation.cpython-37.pyc b/__pycache__/Initialisation.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e986e03a10e3574402c013796cf8296d4a58eb32 Binary files /dev/null and b/__pycache__/Initialisation.cpython-37.pyc differ diff --git a/__pycache__/Traj3D.cpython-37.pyc b/__pycache__/Traj3D.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9089d353fd2661eb0e1c444fe75a6b707a6ecd10 Binary files /dev/null and b/__pycache__/Traj3D.cpython-37.pyc differ diff --git a/individu.py b/individu.py index 72710fcb0df66ca8df5a2fa2cb3fe924df25c72f..88b9dc13f204b0ff18f866208e40ed8b8e3eab31 100644 --- a/individu.py +++ b/individu.py @@ -26,10 +26,29 @@ class Individu(): rot_computed = self.table.Rot_Table[last_name+first_name] rot_traj = first_nucleotide - last_nucleotide - print(rot_traj) - print(rot_computed) + # print(rot_traj) + # print(rot_computed) diff_angle = sum(abs(rot_computed - rot_traj)) self.score = 1/(distance + diff_angle) - - + + + def mutation(self, proba = P1): + table_rotations = self.table.rot_table + for doublet in table_rotations : + for coord in range(3): + tir = random() + if tir < proba : + # print("mutation", doublet, coord) + # print("table", table_rotations[doublet][coord]) + table_rotations[doublet][coord] =np.random.uniform(low = self.table.orta()[doublet][coord] - self.table.orta()[doublet][coord + 3], high = self.table.orta()[doublet][coord] + self.table.orta()[doublet][coord + 3]) + # print("table", table_rotations[doublet][coord]) + +# individu1 = Individu(RotTable()) +# print(individu1.table.rot_table) +# individu1.mutation() + +# table = RotTable() +# test = Individu(table) +# test.evaluate("AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA") +# print(test.score) diff --git a/test.py b/population.py similarity index 70% rename from test.py rename to population.py index 46e0c0bdc6eb0bf8e5803d0bb83a9a70652fff61..c1a1a413240574732ee27affacd13bb894d49c11 100644 --- a/test.py +++ b/population.py @@ -6,35 +6,48 @@ class Population: self.n = n def selection_duel_pondere(self,p=(self.n)//2): - n=self.n - newself=[] #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer - while len(self)>p: - m=random.randrange(0,len(self)) - t=random.randrange(0,len(self)) + newself=[] + vu={} + m=None + t=None #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer + while len(newself)<p: + while m in vu: + m=random.randrange(0,len(self)) + while t in vu: + t=random.randrange(0,len(self)) x=self[m] y=self[t] + vu.add(t) + vu.add(m) p=uniform(0,1) if p>x.score/(x.score+y.score): newself.append(y) else: newself.append(x) + return(newself) def selection_duel(self,p=(self.n)//2): - n=self.n - newself=[] #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer - while len(self)>p: - m=random.randrange(0,len(self)) - t=random.randrange(0,len(self)) + newself=[] + vu={} + t=None + m=None + while len(newself)<p: + while m in vu: + m=random.randrange(0,len(self)) + while t in vu: + t=random.randrange(0,len(self)) x=self[m] y=self[t] + vu.add(t) + vu.add(m) if x.score<=y.score: newself.append(x) else: newself.append(y) return(newself) - def selection_par_rang(self, p): + def selection_par_rang(self, p=(self.n)//2): liste_individus = self.indiv n = self.n @@ -80,6 +93,19 @@ class Population: return self self = modifier_population(self, individus_selectionnes) + + def selection_proportionelle(self,p=(self.n)//2): + newself=[] + somme=0 + for indiv in self: + somme=somme+indiv.score + while len(newself)<p: + m=m=random.randrange(0,len(self)) + x=self[m] + p=uniform(0,1) + if p<=x.score/somme: + newself.append(x) + return(newself) def reproduction(self,selection=selection_duel,enfant=mixage,p=n//2): newself=selection(self,p) @@ -91,7 +117,6 @@ class Population: newself.append(enfant(x,y)) return(newself) -print([random.randrange(1,10) for i in range(5)]) diff --git a/selection_par_rang.py b/selection_par_rang.py new file mode 100644 index 0000000000000000000000000000000000000000..ded5567fe7094249e4e3f1e0222031f0010a0164 --- /dev/null +++ b/selection_par_rang.py @@ -0,0 +1,45 @@ +from random import random + +def creer_population(self, liste_individus): + self.n = len(liste_individus) + self.indiv = set(liste_individus) + return self + +def selection_par_rang(self, p = n//2): + set_individus = self.indiv + n = self.n + + def partitionner(tableau,debut,fin): + echanger(tableau,debut,random.randint(debut,fin-1)) + partition=debut + for i in range(debut+1,fin): + if tableau[i].score<tableau[debut].score: + partition+=1 + echanger(tableau,i,partition) + echanger(tableau,debut,partition) + return partition + + def tri_rapide_aux(tableau,debut,fin): + if debut < fin-1: + positionPivot=partitionner(tableau,debut,fin) + tri_rapide_aux(tableau,debut,positionPivot) + tri_rapide_aux(tableau,positionPivot+1,fin) + + def tri_rapide(tableau): + tri_rapide_aux(tableau,0,len(tableau)) + + liste = list(set_individus) + tri_rapide(liste) + individus_selectionnes = [] + + for _ in range(p): + curseur = random()*n*(n+1)/2 + j = 1 + while j*(j+1)/2 < curseur : + j+=1 + #on doit prendre l'individu avec le jème score + individus_selectionnes.append(liste[j]) + self = creer_population(self, liste_individus) + + + \ No newline at end of file