Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Machine_Learning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dellandrea Emmanuel
Machine_Learning
Compare revisions
aa4c6ee8a5d24450a55e771c7e58707fd775480e to 9159ff8c552398b1e28c4acc672187cfec4c6357
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
edelland/machine_learning
Select target project
No results found
9159ff8c552398b1e28c4acc672187cfec4c6357
Select Git revision
Branches
main
1 result
Swap
Target
edelland/machine_learning
Select target project
edelland/machine_learning
1 result
aa4c6ee8a5d24450a55e771c7e58707fd775480e
Select Git revision
Branches
main
1 result
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source
2
Ajout TD5
· 125f00f5
Dellandrea Emmanuel
authored
5 months ago
125f00f5
Ajout cours 6
· 9159ff8c
Dellandrea Emmanuel
authored
5 months ago
9159ff8c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Cours/ML-06-Apprentissage_par_renforcement.pdf
+0
-0
0 additions, 0 deletions
Cours/ML-06-Apprentissage_par_renforcement.pdf
TD/TD5/ML-TD5.pdf
+0
-0
0 additions, 0 deletions
TD/TD5/ML-TD5.pdf
TD/TD5/q_learning.py
+129
-0
129 additions, 0 deletions
TD/TD5/q_learning.py
with
129 additions
and
0 deletions
Cours/ML-06-Apprentissage_par_renforcement.pdf
0 → 100644
View file @
9159ff8c
File added
This diff is collapsed.
Click to expand it.
TD/TD5/ML-TD5.pdf
0 → 100644
View file @
9159ff8c
File added
This diff is collapsed.
Click to expand it.
TD/TD5/q_learning.py
0 → 100644
View file @
9159ff8c
import
numpy
as
np
def
choix_action
(
epsilon
,
s
,
R
,
Q
):
"""
Renvoie l
'
action sélectionnée pour l
'
état s. Epsilon est une valeur seuil entre 0 et 1 permettant
soit de faire de l
'
exploration (si tirage aléatoire supérieur au seuil), soit de faire
de l
'
exploitation (si tirage aléatoire inférieur au seuil)
Parametres
----------
epsilon : seuil (entre 0 et 1) pour choisir entre exploration et exploitation afin de sélectionner une action
s : état courant
R : matrice des récompenses immédiates
Q : matrice représentant la fonction action-valeur
Retour
-------
a : action sélectionnée
"""
#########################################################
##### A compléter (et supprimer l'instruction pass) #####
#########################################################
pass
# return a
def
calcule_q
(
s
,
a
,
alpha
,
gamma
,
R
,
Q
):
"""
Calcule la nouvelle valeur de la fonction action valeur pour l
'
état s et l
'
action a
Parametres
----------
s : état courant
a : action choisie
alpha : vitesse d
'
apprentissage
gamma : facteur d
'
actualisation
R : matrice des récompenses immédiates
Q : matrice représentant la fonction action-valeur
Retour
-------
q : nouvelle valeur de la fonction action valeur pour l
'
état s et l
'
action a
"""
#########################################################
##### A compléter (et supprimer l'instruction pass) #####
#########################################################
pass
# return q
def
politique
(
s
,
Q
):
"""
Détermine la meilleure action connaissant l
'
état S et la fonction action valeur Q
Parametres
----------
s : état courant
Q : matrice représentant la fonction action-valeur
Retour
-------
a : action sélectionnée
"""
#########################################################
##### A compléter (et supprimer l'instruction pass) #####
#########################################################
pass
# return a
# ===================== Partie 1: Initialisation des données =====================
alpha
=
1
gamma
=
0.8
nb_episodes
=
1000
epsilon
=
0.
R
=
[
[
-
1
,
-
1
,
-
1
,
-
1
,
0
,
-
1
],
[
-
1
,
-
1
,
-
1
,
0
,
-
1
,
100
],
[
-
1
,
-
1
,
-
1
,
0
,
-
1
,
-
1
],
[
-
1
,
0
,
0
,
-
1
,
0
,
-
1
],
[
0
,
-
1
,
-
1
,
0
,
-
1
,
100
],
[
-
1
,
0
,
-
1
,
-
1
,
0
,
100
],
]
R
=
np
.
array
(
R
)
# Matrice des récompenses immédiates
etat_final
=
5
Q
=
np
.
zeros
(
R
.
shape
)
# Matrice représentant la fonction action-valeur
nb_etats
=
nb_actions
=
R
.
shape
[
0
]
# ===================== Partie 2: Apprentissage de la fonction action-valeur Q =====================
print
(
"
Apprentissage de la fonction Q
"
)
for
i
in
range
(
nb_episodes
):
print
(
"
Episode :
"
,
i
)
s
=
np
.
random
.
randint
(
0
,
nb_etats
)
print
(
"
Etat initial :
"
,
s
)
while
True
:
a
=
choix_action
(
epsilon
,
s
,
R
,
Q
)
print
(
"
action choisie :
"
,
a
)
Q
[
s
,
a
]
=
calcule_q
(
s
,
a
,
alpha
,
gamma
,
R
,
Q
)
if
s
==
etat_final
:
break
s
=
a
print
(
"
Matrice Q_value :
"
,
Q
)
Q
=
Q
/
np
.
max
(
Q
)
*
100
print
(
"
Matrice Q_value normalisée :
"
,
Q
)
# ===================== Partie 3: Exploitation de la politique d'action apprise =====================
print
(
"
Exploitation
"
)
s
=
2
# choix d'un état initial
print
(
"
Etat initial :
"
,
s
)
while
s
!=
etat_final
:
a
=
politique
(
s
,
Q
)
s
=
a
# nouvel état
print
(
"
nouvel état :
"
,
s
)
This diff is collapsed.
Click to expand it.