Skip to content
Snippets Groups Projects
Commit c1c1a704 authored by Busson Loic's avatar Busson Loic
Browse files

pull

parents 54af0359 3ff492be
No related branches found
No related tags found
No related merge requests found
...@@ -24,26 +24,29 @@ class RotTable: ...@@ -24,26 +24,29 @@ class RotTable:
"TT": [35.62, 7.2, -154, 0.06, 0.6, 0]\ "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): def __init__(self):
self.rot_table = {} self.rot_table = {}
for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE: for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE:
self.rot_table[dinucleotide] = RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][:3] self.rot_table[dinucleotide] = RotTable.__ORIGINAL_ROT_TABLE[dinucleotide][:3]
self.alea() self.alea()
# get a random deviation, considering the "limits" given in the last 3 columns
# of __ORIGINAL_ROT_TABLE
def alea(self): def alea(self):
for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE: for dinucleotide in RotTable.__ORIGINAL_ROT_TABLE:
for i in range(2): 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]) 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): def orta(self):
return self.__ORIGINAL_ROT_TABLE return self.__ORIGINAL_ROT_TABLE
################### ###################
# WRITING METHODS # # WRITING METHODS #
################### ###################
#table = RotTable() #table = RotTable()
#table.rot_table["AA"] --> [35.62, 7.2, -154] #table.rot_table["AA"] --> [35.62, 7.2, -154]
################### ###################
# READING METHODS # # READING METHODS #
...@@ -63,3 +66,4 @@ class RotTable: ...@@ -63,3 +66,4 @@ class RotTable:
table1 = RotTable() table1 = RotTable()
print(table1.orta()) print(table1.orta())
print(table1.rot_table["AA"])
File added
File added
...@@ -26,10 +26,29 @@ class Individu(): ...@@ -26,10 +26,29 @@ class Individu():
rot_computed = self.table.Rot_Table[last_name+first_name] rot_computed = self.table.Rot_Table[last_name+first_name]
rot_traj = first_nucleotide - last_nucleotide rot_traj = first_nucleotide - last_nucleotide
print(rot_traj) # print(rot_traj)
print(rot_computed) # print(rot_computed)
diff_angle = sum(abs(rot_computed - rot_traj)) diff_angle = sum(abs(rot_computed - rot_traj))
self.score = 1/(distance + diff_angle) 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)
...@@ -6,35 +6,48 @@ class Population: ...@@ -6,35 +6,48 @@ class Population:
self.n = n self.n = n
def selection_duel_pondere(self,p=(self.n)//2): def selection_duel_pondere(self,p=(self.n)//2):
n=self.n newself=[]
newself=[] #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer vu={}
while len(self)>p: m=None
m=random.randrange(0,len(self)) t=None #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer
t=random.randrange(0,len(self)) 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] x=self[m]
y=self[t] y=self[t]
vu.add(t)
vu.add(m)
p=uniform(0,1) p=uniform(0,1)
if p>x.score/(x.score+y.score): if p>x.score/(x.score+y.score):
newself.append(y) newself.append(y)
else: else:
newself.append(x) newself.append(x)
return(newself) return(newself)
def selection_duel(self,p=(self.n)//2): def selection_duel(self,p=(self.n)//2):
n=self.n newself=[]
newself=[] #méthode des duels pondérée: si x=10 et y=1, y a une chance sur 11 de passer vu={}
while len(self)>p: t=None
m=random.randrange(0,len(self)) m=None
t=random.randrange(0,len(self)) 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] x=self[m]
y=self[t] y=self[t]
vu.add(t)
vu.add(m)
if x.score<=y.score: if x.score<=y.score:
newself.append(x) newself.append(x)
else: else:
newself.append(y) newself.append(y)
return(newself) return(newself)
def selection_par_rang(self, p): def selection_par_rang(self, p=(self.n)//2):
liste_individus = self.indiv liste_individus = self.indiv
n = self.n n = self.n
...@@ -80,6 +93,19 @@ class Population: ...@@ -80,6 +93,19 @@ class Population:
return self return self
self = modifier_population(self, individus_selectionnes) 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): def reproduction(self,selection=selection_duel,enfant=mixage,p=n//2):
newself=selection(self,p) newself=selection(self,p)
...@@ -91,7 +117,6 @@ class Population: ...@@ -91,7 +117,6 @@ class Population:
newself.append(enfant(x,y)) newself.append(enfant(x,y))
return(newself) return(newself)
print([random.randrange(1,10) for i in range(5)])
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment