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

Non optimalité corrigé dans individu evaluate

parent fa64667a
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -13,6 +13,7 @@ import time
# Debut du decompte du temps
start_time = time.time()
#Les tests de temps ont été effectué avec 200 personnes, 50 survivant, 0.01 prob muté, 10 gen
def main(N,tmax,pmutation, proportion):
......@@ -21,21 +22,20 @@ def main(N,tmax,pmutation, proportion):
brin = ''.join(lineList[1:])
People=Population(N)
S1=[]
for individu in People.indiv:
individu.evaluate()
for individu in People.indiv: #la boucle prend 8 secondes à faire en tout
individu.evaluate() #chaque appel coute 0.05 secondes
S1.append(int(individu.score))
maximum=int(max(S1))
for i in range(tmax):
mini=People.indiv[0].score
best=People.indiv[0]
People.reproduction(p = proportion, proba_mutation= pmutation)
People.reproduction(p = proportion, proba_mutation= pmutation) #La reproduction prend 7 secondes
for individu in People.indiv:
if individu.score<mini:
best=individu
mini=individu.score
L.append(mini)
print(i,":",mini)
plt.subplot(221)
plt.plot([i for i in range(tmax)], L)
......@@ -56,7 +56,7 @@ def main(N,tmax,pmutation, proportion):
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:])
best,People = main(200,10,0.01,100)
best,People = main(200,10,0.01,50)
test = Traj3D()
test.compute(brin, best.table)
test.draw("first_plot")
......
first_plot.png

2.35 KiB | W: | H:

first_plot.png

2.35 KiB | W: | H:

first_plot.png
first_plot.png
first_plot.png
first_plot.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -3,6 +3,7 @@ from Traj3D import Traj3D
import numpy as np
from math import sqrt, inf
from random import random, randrange
import time
P1 = 0.015
......@@ -15,33 +16,33 @@ class Individu():
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
self.brin = ''.join(lineList[1:])
#self.brin = "AAAGGATCTTCTTGAGATCCTTTTTTTCTGCGCGTAATCTGCTGCCAGTAAACGAAAAAACCGCCTGGGGAGGCGGTTTAGTCGAA"
self.score = self.evaluate()
def evaluate(self):
self.score = None
def evaluate(self): #0.05 sec par individu
traj = Traj3D()
numb_ajout = 6
fisrt_seq = self.brin[0:numb_ajout]
last_seq = self.brin[-numb_ajout:]
traj.compute(last_seq + self.brin + fisrt_seq, self.table) #0.015
traj.compute(last_seq + self.brin + fisrt_seq, self.table)
traj_array = np.array(traj.getTraj())
test_start = time.time()
traj_array = traj.getTraj() #Instantannée
test_end = time.time()
print(test_end - test_start)
list_distance = []
begining = traj_array[0:2*numb_ajout, 0:3]
end = traj_array[-2*numb_ajout:, 0:3]
for i in range(numb_ajout):
begining = traj_array[0:2*numb_ajout]
end = traj_array[-2*numb_ajout:]
for i in range(numb_ajout): #Instantannée
nuc_coordonate_beg = begining[i]
nuc_coordonate_end = end[i]
distance_nuc = np.linalg.norm(nuc_coordonate_beg - nuc_coordonate_end, ord=2)
list_distance += [distance_nuc]
self.score = max(list_distance)
#return max(list_distance)
......@@ -79,24 +80,6 @@ class Individu():
else :
#sur l'axe z il y a un moins
table_rotations[doublet2][coord] = - table_rotations[doublet][coord]
table_rotations = self.table.rot_table
for i in range(0,number_of_mutations):
tir = random()
if tir < proba :
doubletNumber = randrange(0,8)
counter = 0
for doublet in table_rotations:
if counter==doubletNumber:
break
counter+=1
for coord in range(3):
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])
doublet2 = self.table.corr()[doublet]
if coord == 0 or coord == 1 :
table_rotations[doublet2][coord] = table_rotations[doublet][coord]
else :
#sur l'axe z il y a un moins
table_rotations[doublet2][coord] = - table_rotations[doublet][coord]
# individu1 = Individu(RotTable())
# print(individu1.table.rot_table)
......
......@@ -3,6 +3,7 @@ from individu import Individu
from RotTable import RotTable
from croisement import croisement_un_point, croisement_deux_points
import copy
import time
class Population:
def __init__(self,n):
......@@ -154,19 +155,19 @@ class Population:
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:
selection(p) #Instantannée
newself = [element for element in self.indiv]
while len(newself)<vieille_taille: #Cette boucle prend 6-7 sec
m=randrange(0,self.n)
t=randrange(0,self.n)
x=copy.deepcopy(newself[m])
y=copy.deepcopy(newself[t])
couple_enfant = enfant(x,y)
for child in couple_enfant :
for child in couple_enfant : #Cette boucle prend 0.1 sec
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:])
child.mutation(proba_mutation)
child.evaluate()
child.mutation(proba_mutation) #Instannée
child.evaluate() # 0.05 par child <-- C'est ce qui ralenti le tout
newself.append(couple_enfant[0])
newself.append(couple_enfant[1])
self = self.modifier_population(newself)
......
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