Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EI - Jeux Evolu
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nadin Thibault
EI - Jeux Evolu
Commits
1e4de6fb
Commit
1e4de6fb
authored
2 years ago
by
Nadin Thibault
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of gitlab-student.centralesupelec.fr:yi.zhong/ei
parents
e6454317
226c2ce3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
3dna/Constantes.py
+5
-0
5 additions, 0 deletions
3dna/Constantes.py
3dna/RotTable.py
+17
-9
17 additions, 9 deletions
3dna/RotTable.py
3dna/__main__.py
+60
-23
60 additions, 23 deletions
3dna/__main__.py
with
82 additions
and
32 deletions
3dna/Constantes.py
+
5
−
0
View file @
1e4de6fb
...
...
@@ -7,7 +7,12 @@ AGRANDISSEMENT = 5
nom_selection
=
"
selection_roulette
"
nom_croisement
=
"
croisement_milieu
"
List_of_genes
=
[
"
AA
"
,
"
AC
"
,
"
AG
"
,
"
AT
"
,
<<<<<<<
HEAD
"
TA
"
,
"
CA
"
,
"
CC
"
,
"
CG
"
,
"
GC
"
,
"
CT
"
]
#les gènes à modifier
Symetrique
=
{
"
AA
"
:
"
TT
"
,
"
AC
"
:
"
TG
"
,
"
AG
"
:
"
TC
"
,
"
AT
"
:
None
,
"
TA
"
:
None
,
"
CA
"
:
"
GT
"
,
"
CC
"
:
"
GG
"
,
"
CG
"
:
None
,
"
GC
"
:
None
,
"
CT
"
:
"
GA
"
}
#les symétriques de ces gènes
=======
"
TA
"
,
"
CA
"
,
"
CC
"
,
"
CG
"
,
"
GC
"
,
"
CT
"
]
pas
=
10
>>>>>>>
226
c2ce36132e35dbdd4a7ab4930dc5268002c36
This diff is collapsed.
Click to expand it.
3dna/RotTable.py
+
17
−
9
View file @
1e4de6fb
...
...
@@ -22,7 +22,7 @@ class RotTable:
filename
=
os_path
.
join
(
here
,
'
table.json
'
)
self
.
rot_table
=
json_load
(
open
(
filename
))
if
randomize
:
for
dinuc
in
[
"
AA
"
,
"
AC
"
,
"
AG
"
,
"
AT
"
,
"
TA
"
,
"
CA
"
,
"
CC
"
,
"
CG
"
,
"
GC
"
,
"
CT
"
]
:
for
dinuc
in
List_of_genes
:
baseTwist
=
RotTable
.
base_rot_table
[
dinuc
][
0
]
baseWedge
=
RotTable
.
base_rot_table
[
dinuc
][
1
]
deltaTwist
=
RotTable
.
base_rot_table
[
dinuc
][
3
]
...
...
@@ -87,8 +87,8 @@ class RotTable:
traj
.
compute
(
molecule
+
molecule
[:
AGRANDISSEMENT
],
self
)
res
=
0
n
=
len
(
traj
.
getTraj
())
for
i
in
range
(
AGRANDISSEMENT
):
n
=
len
(
traj
.
getTraj
())
x0
=
traj
.
getTraj
()[
i
][
0
]
y0
=
traj
.
getTraj
()[
i
][
1
]
z0
=
traj
.
getTraj
()[
i
][
2
]
...
...
@@ -107,6 +107,21 @@ class RotTable:
summ
=
summ
+
self
.
evaluate
(
newmol
)
return
summ
def
evaluate_partout
(
self
,
molecule
):
traj
=
Traj3D
(
False
)
double_molecule
=
molecule
+
molecule
traj
.
compute
(
double_molecule
,
self
)
n
=
len
(
traj
.
getTraj
())
//
2
for
i
in
range
(
0
,
n
,
pas
):
x0
=
traj
.
getTraj
()[
i
][
0
]
y0
=
traj
.
getTraj
()[
i
][
1
]
z0
=
traj
.
getTraj
()[
i
][
2
]
xf
=
traj
.
getTraj
()[
n
+
i
][
0
]
yf
=
traj
.
getTraj
()[
n
+
i
][
1
]
zf
=
traj
.
getTraj
()[
n
+
i
][
2
]
res
=
res
+
((
xf
-
x0
)
**
2
+
(
yf
-
y0
)
**
2
+
(
zf
-
z0
)
**
2
)(
1
/
2
)
return
res
/
(
n
//
pas
)
def
copy
(
self
):
copy
=
RotTable
()
for
nuc1
in
(
'
A
'
,
'
G
'
,
'
C
'
,
'
T
'
):
...
...
@@ -124,8 +139,6 @@ class RotTable:
- nouv_personne : une RotTable avec un gene modifié
'''
Pm
=
0.3
List_of_genes
=
[
"
AA
"
,
"
AC
"
,
"
AG
"
,
"
AT
"
,
"
TA
"
,
"
CA
"
,
"
CC
"
,
"
CG
"
,
"
GC
"
,
"
CT
"
]
selected_gene
=
List_of_genes
[
rd
.
randint
(
0
,
len
(
List_of_genes
)
-
1
)]
nb_feature
=
3
# 2 suffiraient dans notre cas mais on généralise
selected_feature
=
np
.
random
.
binomial
(
1
,
Pm
,
nb_feature
)
...
...
@@ -148,9 +161,6 @@ class RotTable:
def
mutate_v2
(
self
,
molecule
):
Pm
=
0.2
# à choisir dans [0,001 ; 0,01]
List_of_genes
=
[
"
AA
"
,
"
AC
"
,
"
AG
"
,
"
AT
"
,
"
TA
"
,
"
CA
"
,
"
CC
"
,
"
CG
"
,
"
GC
"
,
"
CT
"
]
nb_feature
=
3
# 2 suffiraient dans notre cas mais on généralise
parametre_preced
=
self
.
getTable
()
for
selected_gene
in
List_of_genes
:
...
...
@@ -177,8 +187,6 @@ class RotTable:
Pm
=
0.2
# à choisir dans [0,001 ; 0,01]
score
=
max
(
self
.
evaluate
(
molecule
)
/
(
35879836.7637
*
AGRANDISSEMENT
),
1
)
List_of_genes
=
[
"
AA
"
,
"
AC
"
,
"
AG
"
,
"
AT
"
,
"
TA
"
,
"
CA
"
,
"
CC
"
,
"
CG
"
,
"
GC
"
,
"
CT
"
]
parametre_preced
=
self
.
getTable
()
for
selected_gene
in
List_of_genes
:
if
rd
.
random
()
<
Pm
:
...
...
This diff is collapsed.
Click to expand it.
3dna/__main__.py
+
60
−
23
View file @
1e4de6fb
...
...
@@ -29,21 +29,21 @@ def tests_croisements():
popu2
=
Population
(
size
)
popu2
.
troupeau
=
popu1
.
troupeau
.
copy
()
popu3
=
Population
(
size
)
popu3
.
troupeau
=
popu
2
.
troupeau
.
copy
()
popu3
.
troupeau
=
popu
1
.
troupeau
.
copy
()
for
i
in
range
(
nb_iter
):
print
(
i
)
_
,
value
=
popu1
.
meilleur
_distance
(
seq
)
D_un
.
append
(
value
)
_
,
value
=
popu1
.
meilleur
(
seq
)
D_un
.
append
(
math
.
sqrt
(
value
)
)
popu1
.
iteration
(
seq
,
nom_selection
,
"
croisement_en_un_point
"
)
for
i
in
range
(
nb_iter
):
print
(
i
)
_
,
value
=
popu2
.
meilleur
_distance
(
seq
)
D_deux
.
append
(
value
)
_
,
value
=
popu2
.
meilleur
(
seq
)
D_deux
.
append
(
math
.
sqrt
(
value
)
)
popu2
.
iteration
(
seq
,
nom_selection
,
"
croisement_en_deux_points
"
)
for
i
in
range
(
nb_iter
):
print
(
i
)
_
,
value
=
popu3
.
meilleur
_distance
(
seq
)
D_milieu
.
append
(
value
)
_
,
value
=
popu3
.
meilleur
(
seq
)
D_milieu
.
append
(
math
.
sqrt
(
value
)
)
popu3
.
iteration
(
seq
,
nom_selection
,
"
croisement_milieu
"
)
plt
.
clf
()
plt
.
plot
(
N
,
D_un
,
label
=
'
un
'
)
...
...
@@ -56,7 +56,6 @@ def tests_croisements():
plt
.
legend
()
plt
.
show
()
plt
.
savefig
(
"
tests_croisements.png
"
)
# plt.close()
def
tests_selection
():
...
...
@@ -75,21 +74,21 @@ def tests_selection():
popu2
=
Population
(
size
)
popu2
.
troupeau
=
popu1
.
troupeau
.
copy
()
popu3
=
Population
(
size
)
popu3
.
troupeau
=
popu
2
.
troupeau
.
copy
()
popu3
.
troupeau
=
popu
1
.
troupeau
.
copy
()
for
i
in
range
(
nb_iter
):
print
(
i
)
_
,
value
=
popu1
.
meilleur
_distance
(
seq
)
D_un
.
append
(
value
)
_
,
value
=
popu1
.
meilleur
(
seq
)
D_un
.
append
(
math
.
sqrt
(
value
)
)
popu1
.
iteration
(
seq
,
"
selection_roulette
"
,
nom_croisement
)
for
i
in
range
(
nb_iter
):
print
(
i
)
_
,
value
=
popu2
.
meilleur
_distance
(
seq
)
D_deux
.
append
(
value
)
_
,
value
=
popu2
.
meilleur
(
seq
)
D_deux
.
append
(
math
.
sqrt
(
value
)
)
popu2
.
iteration
(
seq
,
"
selection_elitisme
"
,
nom_croisement
)
for
i
in
range
(
nb_iter
):
print
(
i
)
_
,
value
=
popu3
.
meilleur
_distance
(
seq
)
D_milieu
.
append
(
value
)
_
,
value
=
popu3
.
meilleur
(
seq
)
D_milieu
.
append
(
math
.
sqrt
(
value
)
)
popu3
.
iteration
(
seq
,
"
selection_tournoi
"
,
nom_croisement
)
plt
.
clf
()
plt
.
plot
(
N
,
D_un
,
label
=
'
selection_roulette
'
)
...
...
@@ -102,7 +101,6 @@ def tests_selection():
plt
.
legend
()
plt
.
show
()
plt
.
savefig
(
"
selection_methodes.png
"
)
# plt.close()
def
test_opt
():
...
...
@@ -118,9 +116,9 @@ def test_opt():
popu
=
Population
(
size
)
popu
.
make_evolution_opt
(
seq
,
nom_selection
,
nom_croisement
,
eps
=
1
)
final_tab
,
value
=
popu
.
meilleur
_distance
(
seq
)
final_tab
,
value
=
popu
.
meilleur
(
seq
)
final_tab
.
exportation
()
print
(
value
,
"
(distance optimisée)
"
)
print
(
math
.
sqrt
(
value
)
,
"
(distance optimisée)
"
)
rot_init
=
RotTable
(
randomize
=
False
)
print
(
math
.
sqrt
(
rot_init
.
evaluate
(
seq
)),
"
(distance de base)
"
)
...
...
@@ -135,6 +133,46 @@ def test_opt():
print
(
"
time :
"
,
time
.
time
()
-
time0
)
def
generation
():
time0
=
time
.
time
()
gen
=
[
i
for
i
in
range
(
1
,
nb_iter
+
1
)]
moy
=
[]
meilleur
=
[]
rot_table
=
RotTable
()
traj_final
=
Traj3D
()
# Read file
lineList
=
[
line
.
rstrip
(
'
\n
'
)
for
line
in
open
(
args
.
filename
)]
# Formatting
seq
=
''
.
join
(
lineList
[
1
:])
popu
=
Population
(
size
)
for
j
in
range
(
nb_iter
):
popu
.
iteration
(
seq
,
nom_selection
,
nom_croisement
)
final_tab
,
value
=
popu
.
meilleur
(
seq
)
moy
.
append
(
popu
.
evaluate_moyenne
(
seq
))
meilleur
.
append
(
value
)
print
(
final_tab
.
distance
(
seq
),
"
(distance optimisée)
"
)
print
(
rot_table
.
distance
(
seq
),
"
(distance de base)
"
)
traj_final
.
compute
(
seq
,
final_tab
)
traj_final
.
draw
(
str
(
int
(
final_tab
.
distance
(
seq
))))
traj_final
.
write
(
"
data/traj_final.png
"
)
print
(
"
time :
"
,
time
.
time
()
-
time0
)
plt
.
figure
(
5
)
plt
.
plot
(
gen
,
moy
,
label
=
'
moyenne
'
)
plt
.
plot
(
gen
,
meilleur
,
label
=
"
meilleur
"
)
plt
.
xlabel
(
'
génration
'
)
plt
.
ylabel
(
'
distance (log)
'
)
plt
.
yscale
(
'
log
'
)
plt
.
legend
()
plt
.
savefig
(
'
data/evo.png
'
)
def
main
():
time0
=
time
.
time
()
...
...
@@ -150,8 +188,9 @@ def main():
popu
=
Population
(
size
)
popu
.
make_evolution_iter
(
seq
,
nom_selection
,
nom_croisement
,
nb_iter
)
final_tab
,
value
=
popu
.
meilleur_distance
(
seq
)
final_tab
.
exportation
()
final_tab
,
value
=
popu
.
meilleur
(
seq
)
print
(
final_tab
.
distance
(
seq
),
"
(distance optimisée)
"
)
rot_init
=
RotTable
(
randomize
=
False
)
print
(
rot_init
.
distance
(
seq
),
"
(distance de base)
"
)
...
...
@@ -167,10 +206,8 @@ def main():
traj
.
write
(
args
.
filename
+
"
.png
"
)
traj_final
.
draw
(
str
(
int
(
final_tab
.
distance
(
seq
))))
traj_final
.
write
(
"
data/traj_final.png
"
)
traj_final2
.
draw
(
str
(
int
(
math
.
sqrt
(
final_tab
.
evaluate
(
seq2
)))))
traj_final2
.
draw
(
str
(
int
(
math
.
sqrt
(
final_tab
.
distance
(
seq2
)))))
traj_final2
.
write
(
"
data/traj_final2.png
"
)
print
(
"
time :
"
,
time
.
time
()
-
time0
)
def
evolution_fitness
():
#evolution de la fitness au cours de l'évaluation
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment