Vous êtes sur la page 1sur 9

10/12/2022

Apprentissage par renforcement

Youcef CHIBANI, Prof., Dr.


ychibani.chibani@usthb.edu.dz

Laboratoire d’Ingénierie des Systèmes Intelligents et Communicants

Faculté de Génie Electrique


Université des Sciences et de la Technologie
“Houari Boumediene”
Alger, Algérie

Prof. Youcef CHIBANI 1

Plan du cours

1. Introduction
2. Principe de l’apprentissage par renforcement
3. Algorithme Q-Learning
4. Applications

Prof. Youcef CHIBANI 2

Prof. Youcef CHIBANI 1


10/12/2022

1. Introduction
Apprentissage supervisé versus apprentissage par renforcement

Système d’apprentissage
supervisé

Entrée : Vecteur Sortie estimée Sortie désirée


de données (Label)

Objectif de l’apprentissage supervisé : Elaboration


d’un modèle pour réduire l’erreur entre la sortie
estimée et la sortie désirée.

Système d’apprentissage
Entrée : Etat Sortie : Action
par renforcement
Objectif de l’apprentissage par renforcement :
Evaluation de la qualité de l’action.

Prof. Youcef CHIBANI 3

1. Introduction

Entrée : Etat Système d’apprentissage Sortie : Action


par renforcement

Action sur
l’environnement

Agent Environnement

Observation de l’Etat
Agent : de l’environnement Environnement :
• Robot • Magasin
• Enfant • Maison
• Voiture • Parking
• etc • etc

Prof. Youcef CHIBANI 4

Prof. Youcef CHIBANI 2


10/12/2022

3. Algorithme Q-Learning
, = , + + max [ , ,

1: Algorithm parameters : terminal_state, learning_rate ( ), discount_factor ( ), epsilon ( ), n_states, n_actions,


n_episodes
2: Define the environment
3: Initialize the Q-Table , , = 1, … , n_states and = 1, … , n_actions
4: Define the list of actions

5: Define the reward R-Table , , = 1, … , n_states and = 1, … , n_actions


6: For episode To n_episodes Do
7: Select randomly a state from the environment
8: While ( != _ ) Do
9: Select an action at the state according to the -greedy algorithm
10: Execute the selected action and observe the environment at the state
11: Compute the temporal difference: , = + max [ , ,
12: Update: , , + ,
13: Initialize the new state:
14: End While
15: End For

Prof. Youcef CHIBANI 5

3. Algorithme Q-Learning
Algorithm parameters :
• terminal_state = 5
• learning_rate: = 0.5
0 1 2
• discount_factor: = 0.5
• epsilon: = 1.0
• n_states = 6 3 4 5
• n_actions = 4
• n_episodes = 2
, = , + + max [ , ,

, Actions , Actions

State 0 1 3 State 0 1 3

0 -1 -1 -10 +20 0 0.00 0.00 0.00 0.00

1 -10 -1 +20 0 1 0.00 0.00 0.00 0.00

2 0 -1 -1 +100 2 0.00 0.00 0.00 0.00

3 -1 0 +20 -1 3 0.00 0.00 0.00 0.00

4 0 +20 -10 -1 4 0.00 0.00 0.00 0.00

5 -10 0 -1 -1 5 0.00 0.00 0.00 0.00

Prof. Youcef CHIBANI 6

Prof. Youcef CHIBANI 3


10/12/2022

3. Algorithme Q-Learning
Algorithm parameters : Un épisode définit le parcours que
• learning_rate: = 0.5 fait l’agent pour aller d’un état initial
• discount_factor: = 0.5
0 1 2 vers l’état terminal.
• episode = 1
Un step définit le pas de déplacement
• step = 1
de l’agent pour passer d’un état à un
• state = 3 3 4 5 autre.
• action =

, = , + + max [ , ,

3,2 = 3,2 + 0.5 × [3,2] + 0.5 × max 4,0 ; 4,1 ; 4,2 ; 4,3 ] 3,2

, Actions , Actions

State 0 1 3 State 0 1 3

0 -1 -1 -10 +20 0 0.00 0.00 0.00 0.00

1 -10 -1 +20 0 1 0.00 0.00 0.00 0.00

2 0 -1 -1 +100 2 0.00 0.00 0.00 0.00

3 -1 0 +20 -1 3 0.00 0.00 0.00 0.00

4 0 +20 -10 -1 4 0.00 0.00 0.00 0.00

5 -10 0 -1 -1 5 0.00 0.00 0.00 0.00

Prof. Youcef CHIBANI 7

3. Algorithme Q-Learning
Algorithm parameters :
• learning_rate: = 0.5
• discount_factor: = 0.5
0 1 2
• episode = 1
• step = 1
• state = 3 3 4 5
• action =

3,2 = 3,2 + 0.5 × [3,2] + 0.5 × max 4,0 ; 4,1 ; 4,2 ; 4,3 ] 3,2

3,2 = 0 + 0.5 × 20 + 0.5 × 0 0 = 10.00

, Actions , Actions

State 0 1 3 State 0 1 3

0 -1 -1 -10 +20 0 0.00 0.00 0.00 0.00

1 -10 -1 +20 0 1 0.00 0.00 0.00 0.00

2 0 -1 -1 +100 2 0.00 0.00 0.00 0.00

3 -1 0 +20 -1 3 0.00 0.00 10.00 0.00

4 0 +20 -10 -1 4 0.00 0.00 0.00 0.00

5 -10 0 -1 -1 5 0.00 0.00 0.00 0.00

Prof. Youcef CHIBANI 8

Prof. Youcef CHIBANI 4


10/12/2022

3. Algorithme Q-Learning
Algorithm parameters :
• learning_rate: = 0.5
• discount_factor: = 0.5
0 1 2
• episode = 1
• step = 2
• state = 3 3 4 5
• action = 0

, = , + + max [ , ,

4,0 = 4,0 + 0.5 × [4,0] + 0.5 × max 3,0 ; 3,1 ; 3,2 ; 3,3 ] 4,0 = 2.50

, Actions , Actions

State 0 1 3 State 0 1 3

0 -1 -1 -10 +20 0 0.00 0.00 0.00 0.00

1 -10 -1 +20 0 1 0.00 0.00 0.00 0.00

2 0 -1 -1 +100 2 0.00 0.00 0.00 0.00

3 -1 0 +20 -1 3 0.00 0.00 10.00 0.00

4 0 +20 -10 -1 4 2.50 0.00 0.00 0.00

5 -10 0 -1 -1 5 0.00 0.00 0.00 0.00

Prof. Youcef CHIBANI 9

3. Algorithme Q-Learning
Algorithm parameters :
• learning_rate: = 0.5
• discount_factor: = 0.5
0 1 2
• episode = 1
• step = 3
• state = 3 3 4 5
• action = 0

, = , + + max [ , ,

3,0 = 3,0 + 0.5 × [3,0] + 0.5 × max 3,0 ; 3,1 ; 3,2 ; 3,3 ] 3,0

, Actions , Actions

State 0 1 3 State 0 1 3

0 -1 -1 -10 +20 0 0.00 0.00 0.00 0.00

1 -10 -1 +20 0 1 0.00 0.00 0.00 0.00

2 0 -1 -1 +100 2 0.00 0.00 0.00 0.00

3 -1 0 +20 -1 3 0.00 0.00 10.00 0.00

4 0 +20 -10 -1 4 2.50 0.00 0.00 0.00

5 -10 0 -1 -1 5 0.00 0.00 0.00 0.00

Prof. Youcef CHIBANI 10

Prof. Youcef CHIBANI 5


10/12/2022

3. Algorithme Q-Learning
Algorithm parameters :
• learning_rate: = 0.5
• discount_factor: = 0.5
0 1 2
• episode = 1
• step = 3
• state = 3 3 4 5
• action = 0

3,0 = 3,0 + 0.5 × [3,0] + 0.5 × max 3,0 ; 3,1 ; 3,2 ; 3,3 ] 3,0

3,0 = 0 + 0.5 × 1 + 0.5 × max 0; 0; 10.0; 0] 0 = 2.00

, Actions , Actions

State 0 1 3 State 0 1 3

0 -1 -1 -10 +20 0 0.00 0.00 0.00 0.00

1 -10 -1 +20 0 1 0.00 0.00 0.00 0.00

2 0 -1 -1 +100 2 0.00 0.00 0.00 0.00

3 -1 0 +20 -1 3 2.00 0.00 10.00 0.00

4 0 +20 -10 -1 4 2.50 0.00 0.00 0.00

5 -10 0 -1 -1 5 0.00 0.00 0.00 0.00

Prof. Youcef CHIBANI 11

3. Algorithme Q-Learning
Algorithm parameters :
• learning_rate: = 0.5
• discount_factor: = 0.5
0 1 2
• episode = 1
• step = 3
• state = 3 3 4 5
• action =

3,2 = 3,2 + 0.5 × [3,2] + 0.5 × max 4,0 ; 4,1 ; 4,2 ; 4,3 ] 3,2

3,2 = 10.00 + 0.5 × 20 + 0.5 × 2.50 10.00 = 15.625

, Actions , Actions

State 0 1 3 State 0 1 3

0 -1 -1 -10 +20 0 0.00 0.00 0.00 0.00

1 -10 -1 +20 0 1 0.00 0.00 0.00 0.00

2 0 -1 -1 +100 2 0.00 0.00 0.00 0.00

3 -1 0 +20 -1 3 2.00 0.00 10.00 0.00

4 0 +20 -10 -1 4 2.50 0.00 0.00 0.00

5 -10 0 -1 -1 5 0.00 0.00 0.00 0.00

Prof. Youcef CHIBANI 12

Prof. Youcef CHIBANI 6


10/12/2022

3. Algorithme Q-Learning
Algorithm parameters :
• learning_rate: = 0.5
• discount_factor: = 0.5
0 1 2
• episode = 1
• step = 5
• state = 4 3 4 5
• action =

4,2 = 4,2 + 0.5 × [4,2] + 0.5 × max 5,0 ; 5,1 ; 5,2 ; 5,3 ] 4,2

4,2 = 0.00 + 0.5 × 10 + 0.5 × 0 0.00 = 5.00

, Actions , Actions

State 0 1 3 State 0 1 3

0 -1 -1 -10 +20 0 0.00 0.00 0.00 0.00

1 -10 -1 +20 0 1 0.00 0.00 0.00 0.00

2 0 -1 -1 +100 2 0.00 0.00 0.00 0.00

3 -1 0 +20 -1 3 2.00 0.00 15.625 0.00

4 0 +20 -10 -1 4 2.50 0.00 -5.00 0.00

5 -10 0 -1 -1 5 0.00 0.00 0.00 0.00

Prof. Youcef CHIBANI 13

3. Algorithme Q-Learning
Algorithm parameters :
• learning_rate: = 0.5
• discount_factor: = 0.5
0 1 2
• episode = 2
• step = 1
• state = 0 3 4 5
• action =

0,2 = 0,2 + 0.5 × [0,2] + 0.5 × max 1,0 ; 1,1 ; 1,2 ; 1,3 ] 0,2

0,2 = 0.00 + 0.5 × 10 + 0.5 × 0 0.00 = 5.00

, Actions , Actions

State 0 1 3 State 0 1 3

0 -1 -1 -10 +20 0 0.00 0.00 0.00 0.00

1 -10 -1 +20 0 1 0.00 0.00 0.00 0.00

2 0 -1 -1 +100 2 0.00 0.00 0.00 0.00

3 -1 0 +20 -1 3 2.00 0.00 15.625 0.00

4 0 +20 -10 -1 4 2.50 0.00 -5.00 0.00

5 -10 0 -1 -1 5 0.00 0.00 0.00 0.00

Prof. Youcef CHIBANI 14

Prof. Youcef CHIBANI 7


10/12/2022

3. Algorithme Q-Learning
Algorithm parameters :
• learning_rate: = 0.5
• discount_factor: = 0.5
0 1 2
• episode = 2
• step = 1
• state = 0 3 4 5
• action =

0,2 = 0,2 + 0.5 × [0,2] + 0.5 × max 1,0 ; 1,1 ; 1,2 ; 1,3 ] 0,2

0,2 = 0.00 + 0.5 × 10 + 0.5 × 0 0.00 = 5.00

, Actions , Actions

State 0 1 3 State 0 1 3

0 -1 -1 -10 +20 0 0.00 0.00 -5.00 0.00

1 -10 -1 +20 0 1 0.00 0.00 0.00 0.00

2 0 -1 -1 +100 2 0.00 0.00 0.00 0.00

3 -1 0 +20 -1 3 2.00 0.00 15.625 0.00

4 0 +20 -10 -1 4 2.50 0.00 -5.00 0.00

5 -10 0 -1 -1 5 0.00 0.00 0.00 0.00

Prof. Youcef CHIBANI 15

3. Algorithme Q-Learning

L’apprentissage de l’agent se termine lorsque la différence temporelle tend vers


zéro ou lorsque les valeurs de Q ne changent plus. Pour cela, on peut tracer la
valeur moyenne de Q en fonction de l’épisode pour vérifier la convergence de
l’apprentissage.

Prof. Youcef CHIBANI 16

Prof. Youcef CHIBANI 8


10/12/2022

3. Algorithme Q-Learning

Parcours de l’agent déterminé à


partir des valeurs progressives de 43.75 70.00 100.00
Q lorsqu’il passe d’un état à un
autre.
47.50 55.00 Terminal

, Actions , Actions

State 0 1 3 State 0 1 3

0 -1 -1 -10 +20 0 20.87 20.87 25.00 43.75

1 -10 -1 +20 0 1 11.87 34.00 70.00 27.50

2 0 -1 -1 +100 2 35.00 49.00 49.00 100.00

3 -1 0 +20 -1 3 22.75 21.87 47.50 22.75

4 0 +20 -10 -1 4 23.75 55.00 -10.00 26.50

5 -10 0 -1 -1 5 0.00 0.00 0.00 0.00

Prof. Youcef CHIBANI 17

Prof. Youcef CHIBANI 9

Vous aimerez peut-être aussi