Skip to content
Snippets Groups Projects
Commit 6f6a45c8 authored by Kappes Marques Rodrigo's avatar Kappes Marques Rodrigo
Browse files

changed the algogenetique so it would merge the 2 versions

parent a5eb22c4
Branches
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
No preview for this file type
No preview for this file type
...@@ -4,79 +4,67 @@ import numpy ...@@ -4,79 +4,67 @@ import numpy
import RotTable import RotTable
from individu import Individu from individu import Individu
from population import Population, afficher from population import Population, afficher
from croisement import * import croisement
from Traj3D import * from Traj3D import *
from random import random from random import random
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import time import time
from copy import deepcopy
def main(N,tmax,pmutation, proportion, indice_selection, population_initiale, enfant = croisement_un_point): # Debut du decompte du temps
start_time = time.time()
def main(N,tmax,pmutation, proportion):
L=[]
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:]) brin = ''.join(lineList[1:])
People=deepcopy(population_initiale) People=Population(N)
# S1=[] S1=[]
for individu in People.indiv: for individu in People.indiv:
individu.evaluate() individu.evaluate()
# S1.append(int(individu.score)) S1.append(int(individu.score))
# maximum=int(max(S1)) maximum=int(max(S1))
mini=People.indiv[0].score
for individu in People.indiv:
if individu.score<mini:
mini=individu.score
# L=[mini]
for i in range(tmax): for i in range(tmax):
print(i)
People.reproduction(p = proportion, proba_mutation= pmutation, selection = indice_selection, enfant = enfant)
mini=People.indiv[0].score mini=People.indiv[0].score
best=People.indiv[0] best=People.indiv[0]
People.reproduction(p = proportion, proba_mutation= pmutation)
for individu in People.indiv: for individu in People.indiv:
if individu.score<mini: if individu.score<mini:
best=individu best=individu
mini=individu.score mini=individu.score
# S2=[individu.score for individu in People.indiv] S2=[individu.score for individu in People.indiv]
# avg = sum(S2)/len(S2) avg = sum(S2)/len(S2)
# L.append(mini) L.append(mini)
print(i,"avg:",avg,"best score:", mini)
# plt.subplot(221) plt.subplot(221)
# liste_selections = ["selection_p_best", "selection_duel_pondere", "selection_duel", "selection_par_rang", "selection_proportionnelle"] plt.plot([i for i in range(tmax)], L)
# plt.plot([j for j in range(len(L))], L, label = liste_selections[indice_selection])
# plt.subplot(223) plt.subplot(223)
# plt.hist(S1, range = (0, maximum+10), bins = 20, color = 'red') plt.hist(S1, range = (0, maximum+10), bins = 20, color = 'red')
S2=[individu.score for individu in People.indiv] S2=[individu.score for individu in People.indiv]
print("Score final: ",best.score) print("Score final: ",best.score)
print("Distance finale: ", best.distance)
print("Avg:", sum(S2)/len(S2)) print("Avg:", sum(S2)/len(S2))
print("Distance final: ",best.distance)
# plt.subplot(224) plt.subplot(224)
# plt.hist(S2, range = (0,maximum+10), bins = 20, color = 'blue') plt.hist(S2, range = (0,maximum+10), bins = 20, color = 'blue')
# plt.show() plt.show()
return(best,People) return(best,People)
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:]) brin = ''.join(lineList[1:])
best,People = main(100,10,0.05,10) best,People = main(60,60,0.05,30)
test = Traj3D() test = Traj3D()
test.compute(brin, best.table) test.compute(brin, best.table)
test.draw("first_plot") test.draw("first_plot")
# [['selection_p_best' '22.637820959091187' '116.30569654472626']
# ['selection_duel_pondere' '22.636890172958374' '46.6242321955727']
# ['selection_duel' '22.21168804168701' '234.7640748029787']
# ['selection_par_rang' '22.180259227752686' '190.0163752068961']
# ['selection_proportionnelle' '22.329176902770996' '315.7030719673908']]
# [['selection_p_best' '22.775274991989136' '106.89365704155766'] # Affichage du temps d execution
# ['selection_duel_pondere' '22.716803073883057' '284.11538487097084'] print("Temps d'execution : %s secondes " % (time.time() - start_time))
# ['selection_duel' '23.19036889076233' '155.83887357033393']
# ['selection_par_rang' '22.752396821975708' '118.6068497149259']
# ['selection_proportionnelle' '22.71982979774475' '151.80114914793427']]
\ No newline at end of file
first_plot.png

2.36 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
...@@ -9,8 +9,6 @@ P1 = 0.015 ...@@ -9,8 +9,6 @@ P1 = 0.015
class Individu(): class Individu():
''' Un individu est caractérisé par sa table de rotations (individu.table)''' ''' Un individu est caractérisé par sa table de rotations (individu.table)'''
def __init__(self, table): def __init__(self, table):
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
brin = ''.join(lineList[1:])
self.table = table self.table = table
lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")] lineList = [line.rstrip('\n') for line in open("plasmid_8k.fasta")]
self.brin = ''.join(lineList[1:]) self.brin = ''.join(lineList[1:])
...@@ -24,7 +22,7 @@ class Individu(): ...@@ -24,7 +22,7 @@ class Individu():
traj = Traj3D() traj = Traj3D()
numb_ajout = 100 numb_ajout = 10
fisrt_seq = self.brin[0:numb_ajout] fisrt_seq = self.brin[0:numb_ajout]
last_seq = self.brin[-numb_ajout:] last_seq = self.brin[-numb_ajout:]
...@@ -99,7 +97,7 @@ class Individu(): ...@@ -99,7 +97,7 @@ class Individu():
table_rotation_not_seen.remove(doublet) table_rotation_not_seen.remove(doublet)
for coord in range(3): for coord in range(3):
value = table_rotations[doublet][coord] + np.random.normal(0, self.table.orta()[doublet][coord + 3]/15) value = table_rotations[doublet][coord] + np.random.normal(0, self.table.orta()[doublet][coord + 3]/10)
if value > self.table.orta()[doublet][coord] + self.table.orta()[doublet][coord + 3]: if value > self.table.orta()[doublet][coord] + self.table.orta()[doublet][coord + 3]:
value = self.table.orta()[doublet][coord] + self.table.orta()[doublet][coord + 3] value = self.table.orta()[doublet][coord] + self.table.orta()[doublet][coord + 3]
elif value < self.table.orta()[doublet][coord] - self.table.orta()[doublet][coord + 3]: elif value < self.table.orta()[doublet][coord] - self.table.orta()[doublet][coord + 3]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment