We propose a Reinforcement Learning (RL) based control design framework for handling complex tasks. The approach extends the concept of Reward Machines (RM) with Signal Temporal Logic (STL) formulas that can be used for event generation. The use of STL allows not only a more efficient representation of rewards for complex tasks but also guiding the training process to converge towards behaviors satisfying specified requirements. We also propose an implementation of the framework that leverages the STL online monitoring algorithms. We illustrate the framework with three case studies (minigrid, cart-pole and high-way environments) with non-trivial tasks.
Figures & tables
Figure 1
Fig. 1 : The minigrid environment Unlockenv with bigger grid size.
Fig. 2 : Reward machine of the Minigrid agent
Fig. 3 : Results from training an agent in the Unlock environment from a extended grid size 12x12 in MiniGrid. Blue: vanilla; orange: RM state in observation with STL specification during training.
Grid Size
Algorithm
Mean Reward ± Std
Mean Len Episode ± Std
6
Specs
0.9494±0.0221
16.2±7.09
6
Vanilla
0.1756±0.3927
238.2±111.36
7
Specs
0.9720±0.0062
12.2±2.68
7
Vanilla
0.9715±0.0060
12.4±2.61
8
Specs
0.9631±0.0128
21.0±7.28
8
Vanilla
0.7670±0.4290
121.2±218.63
TABLE I : Performance comparison per grid size of RM+STL vs Vanilla
Fig. 4 : Results achieved by the trained models when evaluated on larger grid sizes.
Fig. 5 : The cart-pole environment, augmented with target regions A and B defined as STL predicates μA and μB .
Fig. 6 : Reward machines of the cart pole: R1 encodes the task to go to region A and then to region B and stay there. R2 enforces episode termination when the formula φstuck defined in formula ( 1 ) is true.
Fig. 7 : Test results of a single episode using the sub-optimal trained model (i) and using a successfully trained one (ii).
Fig. 8 : Results for 10 training instances with (green) and without (gray) R2 encoding STL formula φstuck as terminal condition. With R2 , the performance of the policy consistently reaches an accumulated reward of 3.000, indicating that the task is successfully completed, whereas with only R1 , the performance of some policies remains around 800, indicating that only the region A is reached in most episodes.
Formula
hz
Interpretation
μdangeri=∣xi∣<.1∧∣yi∣<.1
0
car i is in front and too close
μdanger=∨i=14μdangeri
0
A car is in front and too close
φtail=□[0,10]μdanger
10
Too close for too long
μfast=vxego>25
0
ego vehicle goes fast
φlazy=□[0,10]¬μfast
10
safe for 10 steps
φfast = ◊[0,85]□[0,15]μfast
100
always accelerates eventually
TABLE II : Formulas characterizing driving behaviors and used in the RM in Figure 9 . Short horizon formula ( hz≤10 ) are used as event formulas. Long horizon formulas ( hz=100 ) are for agent evaluation past training.
Fig. 9 : Reward machine and formulas for the highway-env environment.
Fig. 10 : Training results for different values of rewards and penalties. Every 1e5 steps, the agent is tested for 100 episodes and all formulas are evaluated to give a complete picture of the current performance. All values lead to improving performance, lower values of pleft increase the rate of satisfaction of φright , which is consistent with the formulas and RM.