Skip to content
Snippets Groups Projects
Commit 5fe4c4b1 authored by Muller Sacha's avatar Muller Sacha
Browse files

Merge branch 'master' of...

parents 4f45ed5b 293c6eb1
No related branches found
No related tags found
No related merge requests found
......@@ -24,18 +24,21 @@ 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
......
......@@ -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)])
......
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