scieee AI-readable full text Open interactive document viewer

Deep reinforcement learning for robot navigation systems

Ribeiro, Tiago Alcântara

Abstract

Reinforcement Learning in robotics has been a challenging topic for the past few years. The ability to equip a robot with a tool powerful enough to allow an autonomous discovery of optimal behaviour through trial-and-error interactions with the environment, has been a motive for numerous in-depth research projects. This dissertation presents a thorough theoretical foundation that supports different reinforcement learning algorithms. Three different algorithms namely Q-Learning, Monte Carlo Policy Gradient and Deep Deterministic Policy Gradient were selected and implemented on OpenAI Gym control environments. The selected environments were MountainCar, CartPole and Pendulum. These granted a wide variety of applicable algorithms for different action-space and state-space. For each implemented algorithm, a detailed hyperparameter configuration is analysed and compared. A simulated agent was also created in V-REP and configured via ROS and a Python control node. The agent is a Bot’n Roll ONE A robot, which is a differential robot with embedded distance sensors. The goal of the robot/agent is to surpass three levels of increasing complexity mazes using its distance sensors. Tests with different sensor topologies using the embedded distance sensors and additional Time-of-Flight sensors were carried out. Q-Learning and Monte Carlo Policy Gradient algorithms were implemented in the simulated robot. Q-Learning allowed a comparison between two different methods regarding different action selection timings. One of the methods was able to solve the three mazes using the embedded discrete distance sensors. With the Monte Carlo Policy Gradient algorithm, a thorough analysis of how reward functions influence the robot learned policies is presented. The Deep Deterministic Policy Gradient, even though not implemented on the simulated robot, demonstrated a significant potential with several essential advantages such as the stochastic behaviour policy associated with a deterministic target policy, the Actor-Critic method and continuous control.

Full text

Universidade do Minho Escola de Engenharia Tiago Alcântara Ribeiro Deep Reinforcement Learning for Robot Navigation Systems Dissertação de Mestrado Mestrado Integrado em Engenharia Eletrónica Industrial e Computadores Trabalho efetuado sob a orientação do Professor Doutor Agostinho Gil Teixeira Lopes julho de 2019 Deep Reinforcement Learning for Robot Navigation Systems ii DIREITOS DE AUTOR E CONDIÇÕES DE UTILIZAÇÃO DO TRABALHO POR TERCEIROS Este é um trabalho académico que pode ser utilizado por terceiros desde que respeitadas as regras e boas práticas internacionalmente aceites, no que concerne aos direitos de autor e direitos conexos. Assim, o presente trabalho pode ser utilizado nos termos previstos na licença abaixo indicada. Caso o utilizador necessite de permissão para poder fazer um uso do trabalho em condições não previstas no licenciamento indicado, deverá contactar o autor, através do RepositóriUM da Universidade do Minho. Licença concedida aos utilizadores deste trabalho Atribuição-CompartilhaIgual CC BY-SA https://creativecommons.org/licenses/by-sa/4.0/ Deep Reinforcement Learning for Robot Navigation Systems iii Acknowledgements This dissertation is the culmination of five years of study, which were only possible with the essential support and incentive of several people, to whom I cannot forget to thank. A special thanks to my parents Marisa Alcântara and Fernando Ribeiro for all the love, support, and always believing in me. My sister and brothers, Inês, António and Francisco Ribeiro for all the joy and affection, but mostly for being my main source of motivation. Also, to my two grandmothers São and Dina for always helping me in my studies. A big thanks to my supervisor, Professor Gil Lopes, for the opportunity, the valuable guidance, and tireless support. To the Laboratory of Automation and Robotics members for the experiences and shared knowledge, in particular to Pedro Osório for helping with the simulators and to Fernando Gonçalves for being my dissertation partner. To all my classmates, with whom I had the pleasure to share great adventures, especially to my close friends, Ana Correia, Alexandre Martins, Dylan Pereira, João Martins, João Passos, João Ribeiro, José Martins, Marcelo Andrade, Pedro Lopes, Romão Castro and Tiago Ferreira. To my hometown friends, especially to Carlos Areias, Joana Trigueiros, Michael Oliveira and Paulo Monteiro, for all the help and always being there for me. To all the members of botnroll.com, for the knowledge and friendship, especially to José Cruz and Nino Pereira for all the teaching and years working together in robotics. A special thanks to PhD Martin Riedmiller from Google DeepMind for broadening my view over reinforcement learning, thus providing inestimable advice and direction. A very special thanks from the bottom of my heart, to Inês Garcia for all the help, the constant support, continuous encouragement, and for being my source of inspiration. To João Silva, our eternal astronaut, for being the source of so many amazing memories that I will cherish for the rest of my life. Wherever you are, thank you my friend. “Nothing beats an Astronaut…” – “Nada bate um Astronauta…” Lastly, a very special thanks to my grandfather António Ribeiro, you were, are and always will be my greatest example that through hard work and perseverance one can achieve anything one sets his mind to. Thank you for always taking care of us and the incredible example that I will take for the rest of my life. Deep Reinforcement Learning for Robot Navigation Systems iv STATEMENT OF INTEGRITY I hereby declare having conducted this academic work with integrity. I confirm that I have not used plagiarism or any form of undue use of information or falsification of results along the process leading to its elaboration. I further declare that I have fully acknowledged the Code of Ethical Conduct of the University of Minho. Aprendizagem Profunda Por Reforço Em Sistemas De Navegação Robóticos v Resumo A aprendizagem por reforço na robótica tem sido um tema desafiante dos últimos anos. A capacidade de equipar um robô com uma ferramenta tão poderosa, como permitir a descoberta, de forma autónoma, de um comportamento optimizador a partir de tentativa-erro, tem gerado inúmeros projetos de investigação. Esta dissertação apresenta os fundamentos teóricos de diferentes algoritmos de aprendizagem por reforço. Destes, três algoritmos distintos, nomeadamente Q-Learning, Monte Carlo Policy Gradient e Deep Deterministic Policy Gradient foram implementados em ambientes de controlo do OpenAI Gym. Os ambientes selecionados são MountainCar, CartPole e Pendulum, que garantem uma variedade de algoritmos implementáveis para diferentes espaços de estados e espaços de ações. De seguida, um agente simulado foi criado no V-REP e configurado via ROS e um nó de controlo em Python. O agente, Bot’n Roll ONE A, é um robô diferencial com sensores de distância embebidos. O objetivo do robô/agente é resolver três labirintos que aumentam de dificuldade utilizando os sensores de distância. Foram desenvolvidos testes com diferentes posições e orientações dos sensores e adicionados sensores Time- of-Flight. Dois algoritmos, Q-Learning e Monte Carlo Policy Gradient foram implementados no robô simulado. O Q- Learning permitiu a comparação entre dois métodos distintos no que toca a tempos de seleção das ações, em que um dos métodos conseguiu resolver os três labirintos utilizando os sensores embebidos. O método Monte Carlo Policy Gradient permitiu uma análise detalhada de como o sistema de recompensas influencia a política de ações aprendida. O Deep Deterministic Policy Gradient, ainda que não implementado no robô simulado, demonstrou um enorme potencial e vantagens essenciais, tais como a política de comportamento estocástica aliada a uma política alvo determinística, o método Actor- Crítico e a controlo de ações continuo. Palavras-Chave: Aprendizagem Máquina, Aprendizagem por reforço, Aprendizagem Profunda, Robótica, Sistemas de Navegação Deep Reinforcement Learning for Robot Navigation Systems vi Abstract Reinforcement Learning in robotics has been a challenging topic for the past few years. The ability to equip a robot with a tool powerful enough to allow an autonomous discovery of optimal behaviour through trial-and-error interactions with the environment, has been a motive for numerous in-depth research projects. This dissertation presents a thorough theoretical foundation that supports different reinforcement learning algorithms. Three different algorithms namely Q-Learning, Monte Carlo Policy Gradient and Deep Deterministic Policy Gradient were selected and implemented on OpenAI Gym control environments. The selected environments were MountainCar, CartPole and Pendulum. These granted a wide variety of applicable algorithms for different action-space and state-space. For each implemented algorithm, a detailed hyperparameter configuration is analysed and compared. A simulated agent was also created in V-REP and configured via ROS and a Python control node. The agent is a Bot’n Roll ONE A robot, which is a differential robot with embedded distance sensors. The goal of the robot/agent is to surpass three levels of increasing complexity mazes using its distance sensors. Tests with different sensor topologies using the embedded distance sensors and additional Time-of-Flight sensors were carried out. Q-Learning and Monte Carlo Policy Gradient algorithms were implemented in the simulated robot. Q- Learning allowed a comparison between two different methods regarding different action selection timings. One of the methods was able to solve the three mazes using the embedded discrete distance sensors. With the Monte Carlo Policy Gradient algorithm, a thorough analysis of how reward functions influence the robot learned policies is presented. The Deep Deterministic Policy Gradient, even though not implemented on the simulated robot, demonstrated a significant potential with several essential advantages such as the stochastic behaviour policy associated with a deterministic target policy, the Actor- Critic method and continuous control. Keywords: Machine Learning, Reinforcement Learning, Deep Learning, Robotics, Navigations Systems Deep Reinforcement Learning for Robot Navigation Systems vii Table of Contents Acknowledgements ........................................................................................................... iii Resumo ............................................................................................................................... v Abstract ............................................................................................................................. vi Table of Contents .............................................................................................................. vii List of Figures .................................................................................................................... xi List of Tables .................................................................................................................. xvii List of Algorithms ........................................................................................................... xviii Acronyms ......................................................................................................................... xix Notation ........................................................................................................................... xxi 1 Introduction ................................................................................................................ 1 1.1 Motivation ................................................................................................................................. 2 1.2 Objectives.................................................................................................................................. 4 1.3 Scientific Contributions .............................................................................................................. 5 1.4 Document Structure .................................................................................................................. 7 2 Literature Review ........................................................................................................ 8 2.1 Machine Learning ...................................................................................................................... 8 2.1.1 Supervised Learning ............................................................................................... 9 2.1.2 Unsupervised Learning ......................................................................................... 10 2.1.3 Reinforcement Learning ........................................................................................ 10 2.2 Reinforcement Learning in Robotics ........................................................................................ 18 2.3 Simulators and Frameworks .................................................................................................... 21 2.4 Conclusions............................................................................................................................. 23 Deep Reinforcement Learning for Robot Navigation Systems viii 3 Algorithm-Architecture: Theoretical Foundations ...................................................... 24 3.1 From Nothing to Q-Learning .................................................................................................... 24 3.1.1 Introductory Terminology ...................................................................................... 24 3.1.2 Explore-Exploit Dilemma ....................................................................................... 26 3.1.3 Markov Decision Processes .................................................................................. 31 3.1.4 Dynamic Programming ......................................................................................... 36 3.1.5 Monte Carlo Method ............................................................................................. 39 3.1.6 Temporal Difference Learning ............................................................................... 42 3.2 Approximation Methods ........................................................................................................... 47 3.2.1 Nonlinear Function Approximator: Artificial Neural Networks ................................ 48 3.2.2 Radial Basis Function ........................................................................................... 50 3.3 Policy Gradient Methods .......................................................................................................... 50 3.3.1 Policy Approximation and its Advantages .............................................................. 51 3.3.2 Policy Gradient Theorem....................................................................................... 53 3.3.3 Actor-Critic Methods ............................................................................................. 54 3.4 Deep Deterministic Policy Gradient ......................................................................................... 55 3.5 Conclusions............................................................................................................................. 58 4 Simulation Framework: Development ........................................................................ 59 4.1 Simulation Environments: V-REP and Gazebo .......................................................................... 59 4.2 The Agent: Bot'n Roll ONE A.................................................................................................... 62 4.3 The Environment: RoboParty Obstacle Maze ........................................................................... 66 4.4 ROS Framework ...................................................................................................................... 68 4.5 Embedded Script Configuration ............................................................................................... 70 4.6 Supplementary Simulation Environments ................................................................................ 71 4.6.1 MountainCar ......................................................................................................... 72 Deep Reinforcement Learning for Robot Navigation Systems ix 4.6.2 CartPole ................................................................................................................ 74 4.6.3 Pendulum ............................................................................................................. 76 4.7 Conclusions............................................................................................................................. 78 5 Q-Learning ................................................................................................................. 79 5.1 Implementation and Testing on Gym’s Environments .............................................................. 79 5.1.1 MountainCar ......................................................................................................... 81 5.1.2 CartPole ................................................................................................................ 88 5.2 Bot’n Roll ONE A ..................................................................................................................... 92 5.2.1 Reinforcement Learning Components ................................................................... 93 5.2.2 Method A: New Action Every Time Step ................................................................ 95 5.2.3 Method B: New Action Whenever the Observation Changes .................................. 97 5.2.4 Results Discussion .............................................................................................. 100 5.3 Conclusions........................................................................................................................... 102 6 Policy Gradient ........................................................................................................ 103 6.1 Implementation and Testing on Gym’s Environments ............................................................ 103 6.1.1 MountainCar ....................................................................................................... 104 6.1.2 CartPole .............................................................................................................. 109 6.2 Bot’n Roll ONE A ................................................................................................................... 114 6.2.1 Reinforcement Learning Components ................................................................. 114 6.2.2 Reward Functions Comparison ........................................................................... 116 6.2.3 Results Discussion .............................................................................................. 121 6.3 Conclusions........................................................................................................................... 121 7 Deep Deterministic Policy Gradient ......................................................................... 123 7.1 Implementation and Testing .................................................................................................. 123 7.1.1 Pendulum ........................................................................................................... 124 Deep Reinforcement Learning for Robot Navigation Systems xvi Figure 6.19 - Policy Gradient Bot’n Roll ONE A, total and running average rewards for distance travelled to the end of the maze compared to the last time step positive reward function. ....... 119 Figure 6.20 - Policy Gradient Bot’n Roll ONE A, total and running average rewards for the lowest sensor measurement compared to the last time step positive reward function ........................ 120 Figure 7.1 - Diagram of the implemented Actor-Critic method with the specific actor-network and critic-network............................................................................................................................ 124 Figure 7.2 - DDPG Pendulum total reward comparison between different actor learning rates. .......... 125 Figure 7.3 - DDPG Pendulum running average reward comparison between different actor learning rates. ....................................................................................................................................... 126 Figure 7.4 - DDPG Pendulum total reward comparison between different critic learning rates. .......... 127 Figure 7.5 - DDPG Pendulum running average reward comparison between different critic learning rates. ....................................................................................................................................... 127 Figure 7.6 - DDPG Pendulum total reward comparison between different discount factors. ............... 128 Figure 7.7 - DDPG Pendulum running average reward comparison between different discount factors. ..................................................................................................................................... 128 Figure 7.8 - DDPG Pendulum total reward comparison between different exploration noises. ............ 129 Figure 7.9 - DDPG Pendulum running average reward comparison between different exploration noises. ..................................................................................................................................... 130 Figure 7.10 - DDPG Pendulum total and running average reward long-term simulation. .................... 131 Deep Reinforcement Learning for Robot Navigation Systems xvii List of Tables Table 4.1 - Comparison between V-REP and Gazebo. ........................................................................... 61 Table 4.2 - Specifications regarding the simplistic created simulated agent. ........................................ 64 Table 4.3 - MountainCar observation. .................................................................................................. 73 Table 4.4 - MountainCar actions. ......................................................................................................... 73 Table 4.5 - CartPole observation. ......................................................................................................... 74 Table 4.6 - CartPole actions. ................................................................................................................ 75 Table 4.7 - Pendulum observation. ....................................................................................................... 77 Table 4.8 - Pendulum actions. ............................................................................................................. 77 Table 5.1 - Hyperparameter configuration for Q-Learning method A. .................................................... 96 Table 5.2 - Hyperparameter configuration for Q-Learning method B. ................................................... 98 Deep Reinforcement Learning for Robot Navigation Systems xviii List of Algorithms Algorithm 3.1 – K-armed bandit using ε-greedy and incremental average samples .............................. 29 Algorithm 3.2 – Monte Carlo with Exploring Starts, for estimating 𝝅≈𝝅∗ ........................................ 41 Algorithm 3.3 – Monte Carlo without Exploring Starts, for estimating 𝝅≈𝝅∗ ................................... 42 Algorithm 3.4 – Temporal Difference (0) for estimating 𝒗𝝅 ................................................................. 44 Algorithm 3.5 – SARSA (on-policy Temporal Difference Control) .......................................................... 46 Algorithm 3.6 – Q-Learning (off-policy Temporal Difference Control) .................................................... 47 Algorithm 3.7 – One-step Actor-Critic (episodic), for estimating 𝝅𝜽≈𝝅∗ ......................................... 55 Algorithm 3.8 – Deep Deterministic Policy Gradient Algorithm ............................................................. 57 Deep Reinforcement Learning for Robot Navigation Systems xix Acronyms AC – Actor-Critic A2C –Advantage Actor-Critic A3C – Asynchronous Advantage Actor-Critic AGI – Artificial General Intelligence ANN – Artificial Neural Network CHARMIE – Collaborative Home Assistant Robot by Minho Industrial Electronics CPU – Central Processing Unit DDPG – Deep Deterministic Policy Gradient DPG – Deterministic Policy Gradient ES – Exploring Starts GPI – generalised policy iteration GPU – Graphics Processing Unit HDD – Hard Disk Drive LAR – Laboratory of Automation and Robotics LIDAR – Light Detection And Ranging MC – Monte Carlo ML – Machine Learning MNIST – Mixed National Institute of Standards and Technology MSL – Middle Size League PG – Policy Gradient PPO – Proximal Policy Optimization RBF - Radial Basis Function RAM – Random-Access Memory RL – Reinforcement Learning Deep Reinforcement Learning for Robot Navigation Systems xx ROS – Robot Operating System SAC – Soft Actor-Critic SAR – State-Action-Reward SARSA – State-Action-Reward-State’-Action’ SGD – Stochastic Gradient Descent SSD – Solid-State Drive TD – Temporal Difference ToF – Time-of-Flight V-REP – Virtual Robot Experimentation Platform Deep Reinforcement Learning for Robot Navigation Systems xxi Notation 𝐴 – Action-space 𝐺 – Return 𝐽 – Gradient of a scalar performance measure 𝑁 – Noise process 𝑄 – Action-value function 𝑄∗ – Optimal action-value function 𝑅 – Reward Signal 𝑆 – State-space 𝑉 – Value function 𝑉∗ – Optimal value function 𝑎 and 𝐴𝑡 – Action 𝑐 – Centre state ℎ – Linear feature 𝑝 – Dynamics function 𝑠 and 𝑆𝑡 – State 𝑡 – Time step 𝑤 – State-value weights 𝔼 – Expected value 𝛼 – Learning rate 𝛾 – Discount Factor. 𝛿 – Temporal difference error 𝜀 – Exploration variable 𝜃 – Policy parameter vector 𝜇 - Parameterised actor function Deep Reinforcement Learning for Robot Navigation Systems xxii 𝜋 – Policy 𝜌𝛽 – Discounting in the state-visitation distribution 𝜎 – Deviation 𝜏 – Learned network influence Deep Reinforcement Learning for Robot Navigation Systems 1 1 Introduction Machine Learning (ML) is a data science subject that teaches machines to do what comes naturally to humans and animals: learn from experience. Learning by interacting with the environment is probably the first idea about the nature of learning that comes to mind. When an infant plays, looks around, waves its arms or even smells its surroundings, he has no explicit teacher, but a direct sensor-motor connection to its environment. This connection, when exercised, can produce information about cause and effect, actions consequences, and which actions to perform, to achieve a specific goal. Throughout one’s life, such interactions, are a great source of knowledge about both the environment as well as one’s self. An agent interacts with an environment performing actions that alter its state, whereas, the environment responds with a numeric value for the action taken (Figure 1.1). An agent is deeply aware of the environment’s responses to its actions, regardless of whether it is learning how to walk, how to keep a conversation or how to drive a car. Learning from interaction is an elementary idea underlying a significant number of learning and intelligence theories. Figure 1.1 - Reinforcement learning interactions between an agent and its specific environment. By using computational methods, it is possible to “learn” directly from data without relying on a predetermined equation as a model. Machine learning algorithms create mathematical models based on Deep Reinforcement Learning for Robot Navigation Systems 2 sample data to perform decisions or predictions without being directly programmed to perform a specific task. These algorithms find patterns in data that generate insights and help to make better decisions and predictions. The approach explored throughout this dissertation, named reinforcement learning (RL), is significantly more focused on goal-oriented learning than other machine learning approaches. 1.1 Motivation Reinforcement learning refers to goal-oriented algorithms, which learn how to achieve a complex goal or to maximise along a particular dimension over many steps. It learns how to plot situations to actions to maximise a reward signal. The actions to take, are not stated to the learner, but instead, it must discover which actions profit higher reward by trying them out. This trial-and-error strategy offers a different approach where the agent alone must develop ways to solve a problem without human intervention. An agent can start from a null intelligence state, and under the right conditions, develop innovative strategies, achieving superhuman performance. One of the greatest achievements in reinforcement learning history is AlphaGo Zero [1]. This algorithm was designed to play the strategy board game Go. Go is a highly-complex game since it is estimated that the lower bound on the number of legal board positions is 2×10170. The game of Go consists of a 19 by 19 board, and it is played by placing the playing pieces, trying to surround the opposing stones. AlphaGo Zero is a purely reinforcement learning algorithm that outperformed all previous versions of AlphaGo. Specifically, it defeated by a hundred to none the previous version of AlphaGo that won against the world champion. The essential idea in AlphaGo Zero is that it learns completely tabula rasa 1 which means, it starts entirely from a blank knowledge slate and figures out for itself, only from self-playing, without any human knowledge, data, examples, features, or interventions from humans. By achieving this learning process, it is possible to transplant an agent from the board game of Go to almost any other domain. It was noticed, during the training, that AlphaGo Zero not only rediscovered the common patterns and openings that human players tend to play, it also learned, discovered and ultimately discarded them in preference for its own variances, which humans never managed to discover (Figure 1.2). The fact that this algorithm can achieve a significantly high-performance level in a domain as complicated and challenging as Go should mean that now the most challenging and impactful problems for humanity can start to be tackled, such as robotics. 1 Epistemological theory that individuals are born without built-in mental content and therefore all knowledge comes from experience or perception. Deep Reinforcement Learning for Robot Navigation Systems 3 Figure 1.2 - Three Go games, that represent the first eighty moves of three self-play games at different training stages. At three hours, the game focuses on greedily capturing stones. At nineteen hours, the game exhibits the fundamentals of life-and-death, influence and territory. At seventy hours, the game is beautifully balanced, involving multiple battles and a complicated KO fight (image adapted from [1], with permission from David Silver and Springer Nature). Reinforcement learning offers to robotics a framework and set of tools for the design of sophisticated and hard-to-engineer behaviours. As described in [2], reinforcement learning enables a robot to discover optimal behaviours through trial-and-error interactions with its environment autonomously. Instead of clearly specifying the solution to a problem, in reinforcement learning, the developer of the control task must only provide feedback in terms of a scalar objective function that measures the one-step performance of the robot. This strategy allows robots to learn on their own, developing new and unbiased tactics to solve problems. Many times, these robots develop never seen solutions, thus achieving a performance level impossible for humans. Google’s Deepmind [3] has been developing crucial work on this topic. In [4], the principle of locomotion on a diverse set of simulated bodies is studied. Virtual bodies are trained on a diverse set of complex terrains and obstacles. In Figure 1.3, some examples of simulated agents like quadrupeds (a), humanoids (b) and planar walkers (c) must overcome hurdles, gaps, variable terrains, moving walls and even platforms. (a) (b) (c) Figure 1.3 – Quadruped (a), humanoid (b) and planar walker (c) bodies overcoming different obstacles. Deep Reinforcement Learning for Robot Navigation Systems 10 (a) (b) (c) (d) (e) (f) Figure 2.2 - Example of a solution to the MNIST classification problem. 2.1.2 Unsupervised Learning The Unsupervised learning [20] algorithm is associated with the idea of learning without a teacher. It is also known as self-organisation and a method of modelling the probability density of inputs. Cluster analysis is a sub-branch of unsupervised Learning that groups unlabelled, unclassified or uncategorised data. Instead of responding to feedback, cluster analysis identifies similarities in the provided data and responds based on the existence or absence of such similarities in each new sample of data. The core purpose of these types of algorithms is the study of data’s intrinsic and hidden structures, to get meaningful insights, segment datasets in similar groups, or even to simplify them. The other sub-branch of unsupervised learning is dimensionality reduction. Input data may have an abundant number of dimensions, as a result of a rich or overcomplex input data. Representing data with fewer dimensions allows a more accessible learning in subsequent tasks, a more straightforward visualisation and a more natural discovery of intrinsic data patterns. 2.1.3 Reinforcement Learning The early history of reinforcement learning [21] has two extensive main threads that were independently pursued before linking in present-day reinforcement learning. The first thread concerns trial-and-error learning and emerges from the psychology of animal learning. The second thread concerns the optimal control problem and its solution using value functions and dynamic programming. Even though both Deep Reinforcement Learning for Robot Navigation Systems 11 threads have been mostly independent, the exception is a third thread concerning temporal-difference methods. The three threads were linked together in the late 1980s to create the current field of reinforcement learning. The “optimal control” term is used to describe the controller design problem to minimise a measure of a dynamical system’s behaviour over time. In the 1950s, an approach to this problem was developed by Richard Bellman as an extension of the previous control theory of Hamilton and Jacobi. By using concepts of a dynamical system’s state and a value function, to define a functional equation, the Bellman equations were created. The series of methods to solve the optimal control problems by solving the Bellman equations are known as Dynamic Programming. Bellman also introduced a discrete stochastic version of the optimal control problem known as the Markov Decision Processes (MDPs), and Ron Howard developed the policy iteration method for MDPs. These are all central fundamentals underlying the theory and algorithms of modern reinforcement learning. A thorough explanation is presented in sub-chapter, From Nothing to Q-Learning. The first thread concerns trial and error learning and has its origin in the psychology of animal learning. Aristoteles was the first known ambassador of the reinforcement learning concept. The term tabula rasa means empty book, meaning that consciousness is devoid of any innate knowledge. It is the epistemological theory that an individual is born without any built-in mental content, and therefore, all knowledge comes either from experience or from perception. The first person to succinctly express the trial-and-error as a principle of learning was Edward Thorndike with the “Law of Effect” [22]. “Of several responses made to the same situation, those which are accompanied or closely followed by satisfaction to the animal will, other things being equal, be more firmly connected with the situation, so that, when it recurs, they will be more likely to recur; those which are accompanied or closely followed by discomfort to the animal will, other things being equal, have their connections with that situation weakened, so that, when it recurs, they will be less likely to occur. The greater the satisfaction or discomfort, the greater the strengthening or weakening of the bond.” - Edward Thorndike in [23], p. 244 Thorndike tested his theory by devising a classic experiment in which he used a puzzle box, to test the laws of learning empirically. He would place a cat in the puzzle box, which was encouraged to escape to reach a fish placed outside of the cage. The time it took for the cat to escape would be registered and compared to the next iterations. In the beginning, the cats would experiment with different strategies to escape the puzzle box and thus reaching the fish. Ultimately, they would stumble upon the lever which Deep Reinforcement Learning for Robot Navigation Systems 12 would open the cage. After the escape, the cats were put again in the puzzle box, and the time it took to escape was noted. In consecutive trials, the cats would develop the knowledge that pressing the lever would have positive consequences, and would rapidly adopt this behaviour, becoming increasingly quick at pressing the lever. The term “Reinforcement” in the context of animal learning came into use well after Thorndike’s expression of the “Law of Effect”, first appearing in this context in the 1927 english translation of Pavlov’s monograph on conditioned reflexes. Pavlov described reinforcement as the firming of a pattern of behaviour due to an animal receiving a stimulus. The idea of implementing trial-and-error learning in a computer appeared among the earliest thoughts about the possibility of artificial intelligence. In a 1948 report [24] named: “Machinery Intelligence”, Alan Turing described a design for a “pleasure-pain system” that worked along the lines of the “Law of Effect”: “When a configuration is reached, for which the action is undetermined, a random choice for the missing data is made and the appropriate entry is made in the description, tentatively, and is applied. When a pain stimulus occurs all tentative entries are cancelled, and when a pleasure stimulus occurs they are all made permanent.” - Alan Turing in [24], p. 13 Andrew G. Barto and Richard S. Sutton are considered to be founding fathers of modern computational reinforcement learning. Both developed several breakthrough algorithms and strategies. The book [21] is considered the best introductory book on reinforcement learning. Andrew Barto considers that reinforcement learning is a complement of both search and memory. Search can be characterised as trial-and-error, generate-and-test and variation-and-selection. However, reinforcement learning must also be capable of recalling what worked best for each situation. Trial and error learning did not have an intensive study from an AI point of view in the next decades. Opposing to error correction learning algorithms, such as performed in supervised learning, Trial and error, does not have such in-depth research. It was only in 1981 that Barto and Sutton in [25], developed an associative network where the outputs were not specified by examples. The system had to try things and had them evaluated in order to come up with the output that produced the highest reward, without that ever being presented to the system. In this particular system, the sole purpose of the network’s action was to create the reward signal. Deep Reinforcement Learning for Robot Navigation Systems 13 In 1983, a new algorithm was created where the network’s action did not just create the reward signal but would also return the new state the agent was. The control problem presented was a pole balancing system, also known as the inverted pendulum problem, Figure 2.3, which led to the conception of an Actor-Critic (AC) algorithm [26]. The Actor-Critic architecture consists of two different networks. The actor decides which action to perform according to the actual state, and the critic helps the agent’s process of decision as well as the network configuration as an external viewer. The AC algorithms are still used to date as an attempt to solve control problems in reinforcement learning. Figure 2.3 - Inverted pendulum control problem. In parallel with the actor-critic algorithms, Richard Sutton created in his PhD [27] the temporal difference (TD) algorithms. The Temporal Difference error correction technique was different from supervised learning because it not only predicts the reward as an external signal but also predicts its future predictions. One of the most significant achievements was in an artificial checkers player. In [28], Arthur Samuel describes that the TD algorithm outperformed his evaluation function. His evaluation function relied only on the current state of the board, in contrast with Temporal Difference, which predicted future states until it reached a terminal state. “… we are attempting to make the score, calculated for the current board position, look like that calculated for the terminal board positions of the chain of moves which most probably occur during actual play.” – Arthur Samuel in [28] Temporal Difference Learning also led to an essential connection between Optimal Control and Dynamic Programming. Richard Bellman introduced Dynamic Programming in 1953, which was an algorithm very similar to the checker's solution. TD Learning made it possible to adapt this technique with Optimal Control Problem. In the early 1990s, the first Temporal Difference Learning board game, named TD Gammon outperformed human experts. This project introduced several new techniques that surprised the scientific community Deep Reinforcement Learning for Robot Navigation Systems 14 for its innovation and success. In addition to using Temporal Difference Learning, it used a multilayer artificial neural network (ANN) trained with backpropagation and Monte Carlo (MC) Learning. At the time, reinforcement learning had the reputation of being a significantly slow algorithm. Monte Carlo simulation based optimisation was being studied in other fields, and its success was a revelation due to reinforcement learning reputation. Monte Carlo method consists of learning through multiple simulated games. In Backgammon the different configurations of the playing board, the states, are about 1020. Strategies like Dynamic Programming would take an unfeasible amount of time to sweep all these states, resulting in years and years of continuous simulation. This problem is called the Curse of Dimensionality. With such a big state-space, it turned out that many states were irrelevant. Through multiple Monte Carlo games, the reinforcement learning computation could be focused only on the relevant parts of the statespace. Monte Carlo brought a great time-efficiency to reinforcement learning algorithms by looking down on irrelevant or semi-irrelevant states. Neuroscience is also an essential contributor to reinforcement learning. Many ideas to reinforcement learning come from biology and the human’s brains study. In neuroscience, some comparisons with how the human brain processes information were made to Temporal Difference error. Dopamine, as displayed in Figure 2.4, is one of several neural modulators sent via nerve fibres, like the mesolimbic pathway, whose essential purposes are reward and reinforcement. Many studies discuss the comparison between TD error and the way dopamine works on the brain. Figure 2.4 - Neuroscience representation of how dopamine travels through the human brain (from [29]). Due to the work of Wolfram Schultz, it was discovered that some aspects of the signal are identical to the temporal difference error. Schultz research consisted of recording dopamine activity, among other chemical processes, in awake behaving monkeys, while they were performing specific tasks. In Figure 2.5 is shown an adapted display of a famous collection of pictures from Schultz’s research [30], on Deep Reinforcement Learning for Robot Navigation Systems 15 predictive reward signal of dopamine neurons. Bursts of activity of dopamine cells are initially triggered by a reward (a), i.e. monkey putting food in his mouth, as a consequence of effectively performing a task. However, with continuous trials, if the monkey develops a predict stimulus (b), the response of the dopamine rewards seizes at the time of reward and moves back to the time of the reward predictor, even when the reward does not occur (c). Moreover, If the animals develop what is known as a “predictor of a predictor” or an earlier predictor, the activity of dopamine cells will take place on the initial predictor. (a) (b) (c) Figure 2.5 - Schultz experiment demonstrates that after learning a task, the monkeys started having dopamine bursts when predicting a positive situation, R denotes the time a reward is awarded, and P denoted the time a prediction is made (adapted from [30]). This reaction is precisely the Temporal Difference error’s purpose. Additionally, this realisation has revolutionised neuroscience view on the brain's reward system. These cells are not the reward themselves; they are the reinforcement signal that corresponds very closely to the Temporal Difference error. Nowadays, reinforcement learning is widely used in numerous areas. One of the most significant achievements for reinforcement learning algorithms is AlphaGo Zero. From the AlphaGo family, AlphaGo Zero is the most recent algorithm, which has learned entirely from scratch without any human data. The essential idea of AlphaGo Zero is to learn entirely from tabula rasa . Thus, starting with a clean knowledge and learning just from self-playing, without any human knowledge, data, examples, features, or interventions. In Figure 2.6, AlphaGO Zero self-play (a) and neural network training (b) are demonstrated. It uses a Monte Carlo Tree Search when it is playing and a deep convolutional neural network for its training. AlphaGo Zero uses an innovative form of reinforcement learning, in which it becomes its own teacher. The system starts with an artificial neural network that does not know anything about the game of Go. It plays against itself, combining the neural network with the Monte Carlo tree search. As it plays, the network is tuned and updated to predict, both the moves and the eventual winner of the game. At each game, the system’s performance improves by a small amount, and consequently, the quality of the selfplay games increases. This leads to a constant improvement of the system, creating ever more robust versions of AlphaGo Zero. Deep Reinforcement Learning for Robot Navigation Systems 16 (a) (b) Figure 2.6 - AlphaGo Zero architecture diagrams, (a) represents the self-play tree searches, and (b) represents the afterwards training using the episode information (image adapted from [1], with permission from David Silver and Springer Nature). This system outperforms the previous versions of AlphaGo because it learns from tabula rasa , no longer constrained by the limits of human knowledge, from the strongest player in the world: AlphaGo Zero itself. The low time-costing AlphaGo Zero learning process is also a significant technological advancement. The technique is defined by the following timeline milestones (Figure 2.7): • 3 hours: AlphaGo Zero plays like a human beginner, abdicating of long-term strategies to focus on greedier policies capturing as many stones as possible. • 19 hours: AlphaGo Zero has learnt the fundamentals of more advanced Go strategies such as life-and-death, influence and territory. • 70 hours: Alpha GoZero plays at a super-human level. The game is disciplined and involves multiple challenges across the board • 3 days: AlphaGo Zero surpasses the abilities of AlphaGo Lee, the version that beat world champion Lee Sedol in four out of five games. • 21 days: AlphaGo Zero reaches the level of AlphaGo Master, the version that defeated 60 top professionals online and world champion Ke Jie in three out of three games in 2017 • 40 days: AlphaGo Zero surpasses all other versions of Alpha Go and, arguably, becomes the best Go player in the world. It does this entirely from self-play, with no human intervention and using no historical data Figure 2.7 - AlphaGo Zero day-to-day learning evolution. Deep Reinforcement Learning for Robot Navigation Systems 17 At the moment, a significant number of scientific teams are studying Artificial General Intelligence (AGI). The idea behind this concept is to create an algorithm that can learn multiple different tasks. Atari Games are well-known to the reinforcement learning community as they provide different environments which require different approaches from the traditional control problems. These games are also used for benchmarking reinforcement learning algorithms as well as AGI systems. In [31], a reinforcement learning algorithm is presented that solves six different Atari games (Figure 2.8) and surpasses human experts on three of them. (a) (b) (c) (d) Figure 2.8 - Atari environments solved using deep reinforcement learning in [31], (a) Pong, (b) Breakout, (c) SpaceInvaders, (d) SeaQuest. Another significant milestone for reinforcement learning was the success of OpenAI Dota 2 player [32]. OpenAI Five is an RL algorithm that plays Dota 2, a multiplayer online battle arena game. This game requires long-term strategy planning. OpenAI initial version was able to play one versus one set of games with only one hero and was able to beat the world champion player reliably. Even though this was a significant achievement, it was only a stepping stone towards playing the real five versus five Dota 2 game. In 2018, it was unveiled an improved version of OpenAI Five, a five versus five players with a limited hero pool, that was able to defeat competent players. In April 2019, OpenAI Five challenged the reigning world champions to a five versus five set of games, with a pool of seventeen heroes. This algorithm, like AlphaGo Zero, started from tabula rasa and learned only from millions of self-played games. It developed unorthodox strategies that surprised the world champion team. Also, the confidence value during the games was always noticeably high, reaffirming the algorithm confidence. This algorithm defeated two games to none the best team of humans in the world and the second game is known as a completely one-sided game. In Figure 2.9, a screenshot from one of the decisive moments in game one, right after this stand-off the RL algorithm predicted a 95% chance of winning. Even though it is a videogame, the decision complexity and planning of many real-time situations is a notable improvement. Their victory required teamwork and collaboration between algorithms. Deep Reinforcement Learning for Robot Navigation Systems 18 Figure 2.9 - Decisive moment on Dota 2 OpenAI Five game two against world champions, in this confrontation the human team lost three out of five players. 2.2 Reinforcement Learning in Robotics For a robot to operate efficiently in an environment, it must make some sense of it, be able to plan its actions and execute them while using feedback to ensure everything is proceeding according to plan. These components, contrary to human, are not trivial for a robot to perform. Tasks like recognising objects, dialoguing, predicting, to some extent, human’s intentions, multiple object manipulation are very challenging for a machine to perform. In recent years, the rise of Deep Learning has prominence in multiple computer vision tasks [33]. However, the broad spectrum of skills required for a typical pedestrian street scene is still not entirely within the grasp of current technology. The recent successes of reinforcement learning and deep learning led many researchers to develop new methods to control robots using reinforcement learning. The capability of automating the sensing, planning and control algorithms via a self-learning strategy by autonomous trial-and-error would solve numerous nowadays robotics problems. After the surprising successes in several video games, board games and simulated control problems, deep reinforcement learning scientific researches started to focus on robotics. On the previously specified tasks, the environments on which the agent must learn are the same on which it must operate, and the simulation’s efficiency allows the agent to learn in fewer episodes. Deep reinforcement learning systems are notoriously data inefficient, and often require millions of episodes before successfully learning how to solve a task such as playing an Atari game. If the same systems were to be applied to a real-world robot’s learning, it would take an unfeasible amount of time as well as physical damages to the robot. An alternative is to use a simulated training environment and posteriorly deploy the trained policy into the real robot. However, a real-world completely thorough simulation of all the details are both problematic Deep Reinforcement Learning for Robot Navigation Systems 19 and costly to achieve, and such policies do not generally perform well on the physical robots. The challenges of implementing reinforcement learning into physical robots can be divided into four categories: • Sample Efficiency; • Simulation to Real-World Transition; • Reward Specification; • Safety. Two different approaches regarding the sample efficiency are commonly used, model-based and modelfree RL. Model-free learning refers to the process of learning a policy based only on rewards obtained by interaction with the environment. Model-based learning refers to the process of an agent trying to discover an environment’s model and use it to plan and improve the policy. This method often results in a lower performance compared to model-free learning, and occasionally fails due to errors in the learned model. Model-based RL shows significant success in problems where the dynamics can be represented by simpler models, such as a linear one. However, in more complex environments like non-linear models (artificial neural networks), model-free learning tends to have better success. In [34], to solve this modelbased problem, it is proposed the system to learn several different models of the environment and to uniformly sample from the different learned models, regularising the learning process. A recent paper [35], regarding a model-free learning algorithm, has demonstrated a significant sample efficiency. In the paper, a description of an off-policy actor-critic algorithm called Soft Actor-Critic (SAC) demonstrates that it was possible to train a robot to walk in about four hours of environment interaction, among other implementations. The simulation to the real-world gap is another problem of reinforcement learning in robotics. The simulation of an environment a robot is likely to encounter realistically is a common challenge. Reinforcement learning is a valuable solution to problems where simulation can sufficiently capture the dynamics. In [36], a policy was trained to learn recovery manoeuvres for a quadrupedal robot using a simulation environment. The deployment to the real robot resulted in a 97% success rate. However, the state-space was significantly low dimensional, contrasting with robotic visual representations. A solution to cope with robotic visual inputs such as cameras was also developed in [37]. By randomising the environment’s visual inputs (Figure 2.10) and training the policy to be robust to these changes, this system implied the real world to be just like a simulation variation. The algorithm created multiple variations of the same environment, where the real-world would be tested as just another variation. Deep Reinforcement Learning for Robot Navigation Systems 26 Figure 3.1 - Diagram of the different reinforcement learning components, the interaction between the action and the environment and the state-action-reward (SAR) triple. 3.1.2 Explore-Exploit Dilemma An essential feature that distinguishes reinforcement learning from other kinds of learning is that it uses training information to evaluate the chosen actions, instead of receiving instructions with the correct answers. This evaluation process creates the need for active exploration to achieve an explicit search for beneficial behaviour. In this subchapter, the evaluation aspect study of reinforcement learning is presented in a simplified setting. The feedback evaluation problem explored is a simplified version of the k-armed bandit problem. I 𝐾-Armed Bandit Problem The 𝑘-armed bandit problem is named by analogy to a slot machine or one-armed bandit, but with k levers instead of one. Each action is similar to pulling a slot machine lever, and the reward is the outcome of the action, the total payoff. Consider the following problem. A choice among k different actions, levers, must be repeatedly made. Afterwards, a numerical reward chosen from a stationary probability distribution is received, depending on which action from 𝑘 was selected. The goal is to maximise the total reward over a certain period, for example, 𝑁 action selections. For each of the 𝑘 actions, given that a specific action is selected, an expected or mean reward is given, named the value of that action. The selected action on time step t is denoted as 𝐴𝑡 moreover, its corresponding reward 𝑅𝑡. The arbitrary action value is 𝑎, additionally, 𝑞∗(𝑎) is the expected reward, when 𝑎 is selected: 𝑞∗(𝑎)= 𝔼[𝑅𝑡| 𝐴𝑡=𝑎] (3.1) If the value of each action were known beforehand, the solution to the k-armed bandit problem would be trivial, always selecting the action with the most significant value. However, it is assumed that the action Deep Reinforcement Learning for Robot Navigation Systems 27 values are unknown, but can be estimated. The estimated value of an action 𝑎 at time step 𝑡 is denoted as 𝑄𝑡(𝑎). The goal is to have 𝑄𝑡(𝑎) as close as possible to 𝑞∗(𝑎). By maintaining an estimate of the action values, at any time step, there is always an action whose estimated value is the highest. These are called greedy actions and selecting these results on the exploitation of the current action value knowledge. If instead a non greedy action is selected, it is considered to be exploration since it enables a non greedy action value estimate improvement. To maximise the instant expected reward, the exploitation method is the best solution, since it chooses the known action capable of returning the higher reward. However exploration may produce a greater total reward in the long run. The following sub-chapters describe some solutions to the exploration-exploitation dilemma. II Action-Value Methods A study parcel of methods for estimating the values of actions and using the estimates to make action selections decisions is called action-value methods. One way to estimate the value of an action is to average the received rewards: 𝑄𝑡(𝑎)=𝑠𝑢𝑚 𝑜𝑓 𝑟𝑒𝑤𝑎𝑟𝑑𝑠 𝑤ℎ𝑒𝑛 𝑎 𝑡𝑎𝑘𝑒𝑛 𝑝𝑟𝑖𝑜𝑟 𝑡𝑜 𝑡 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑡𝑖𝑚𝑒𝑠 𝑎 𝑡𝑎𝑘𝑒𝑛 𝑝𝑟𝑖𝑜𝑟 𝑡𝑜 𝑡 =∑𝑅𝑖 𝑡−1 𝑖=1 𝟙 𝐴𝑖=𝑎 ∑𝟙 𝐴𝑖=𝑎 𝑡−1 𝑖=1 (3.2) Where 𝟙 𝑝𝑟𝑒𝑑𝑖𝑐𝑎𝑡𝑒 denotes the random variable that is one if the predicate is true, and zero if it is not. As the denominator tends to infinity, 𝑄𝑡(𝑎) is expected to converge to 𝑞∗(𝑎). For this method, all 𝑄0(𝑎) are assumed to be zero. A simple action selection rule is to select one of the actions with the highest estimated value, performing a greedy action selection, that can be written as: 𝐴𝑡=𝑎𝑟𝑔𝑚𝑎𝑥𝑎 𝑄𝑡(𝑎) (3.3) Greedy action selection always exploits current knowledge for immediate reward maximisation. A simple alternative is to act greedier a significant percentage of the time, but every once in a while, with a small probability 𝜀, select a random action among every action with equal probability, independently of the action-value estimates. These methods that use near-greedy action selection rules are named 𝜀-greedy. This method grants that with time, every action is sampled an infinite number of times while still having a mostly greedy action selection. A variant of the 𝜀-greedy named decreasing 𝜀-greedy consists of an exponential decrease of the greedy selection actions. By starting with a broad exploration value, it explores all the different possibilities at a Deep Reinforcement Learning for Robot Navigation Systems 28 higher frequency. However, with time, and as the purpose of exploration decreases, an exponential decay function deviates the interest of this method to exploitation, resisting just a residual value for exploration. III Incremental Implementation Even though the action-value method previously presented is a great estimation strategy, it still has its disadvantages regarding computational efficiency. The incremental implementation offers a new strategy with constant memory and constant computation per time step. As a representation simplification, the following demonstration focus on a single action. As notation, 𝑅𝑡 denotes the reward received after the 𝑡 iteration and 𝑄𝑛 denotes the action value estimate after being selected 𝑛 − 1 times, which can be written as: 𝑄𝑛=𝑅1+𝑅2+⋯+𝑅𝑛−1 𝑛−1 (3.4) In the previous method, it is needed to maintain a record of all the previously seen rewards. However, the memory and computational requirements would grow over time as more actions are executed. For each additional reward, additional memory storage and computation are necessary to calculate 𝑄𝑛. The developing of an incremental formula to update averages with small and constant computation is required to process each new reward. With just given 𝑄𝑛−1 moreover, the 𝑛th reward 𝑅𝑛, the current average can be calculated by: 𝑄𝑛=1𝑛∑𝑅𝑖 𝑛 𝑖=1 (3.5) 𝑄𝑛=1𝑛(𝑅𝑛+∑𝑅𝑖 𝑛−1 𝑖=1 ) 𝑄𝑛=1𝑛(𝑅𝑛+(𝑛−1) 1 𝑛−1∑𝑅𝑖 𝑛−1 𝑖=1 ) 𝑄𝑛=1𝑛(𝑅𝑛+(𝑛+1)𝑄𝑛−1) 𝑄𝑛=1𝑛(𝑅𝑛+𝑛𝑄𝑛−1+𝑄𝑛−1) 𝑄𝑛=(1−1𝑛 )𝑄𝑛−1+1𝑛𝑅𝑛 Deep Reinforcement Learning for Robot Navigation Systems 29 The memory required by this implementation is only for 𝑄𝑛 and 𝑛 and only a small computation. The update rule (3.5) can also be written in the general update form: 𝑁𝑒𝑤𝐸𝑠𝑡𝑖𝑚𝑎𝑡𝑒 →𝑂𝑙𝑑𝐸𝑠𝑡𝑖𝑚𝑎𝑡𝑒+𝑆𝑡𝑒𝑝𝑆𝑖𝑧𝑒[𝑇𝑎𝑟𝑔𝑒𝑡−𝑂𝑙𝑑𝐸𝑠𝑡𝑖𝑚𝑎𝑡𝑒] (3.6) 𝑄𝑛=𝑄𝑛−1+1𝑛[𝑅𝑛−𝑄𝑛−1] (3.7) The following pseudocode demonstrates a solution to a complete bandit algorithm using incrementally calculated sample averages and 𝜀-greedy. Algorithm 3.1 – K-armed bandit using ε -greedy and incremental average samples 1: 𝐼𝑛𝑖𝑡,𝑓𝑜𝑟 𝑎=1 𝑡𝑜 𝑘: 2: 𝑄(𝑎)←0 3: 𝑁(𝑎)←0 4: 𝐿𝑜𝑜𝑝 (𝑓𝑜𝑟 𝑒𝑎𝑐ℎ 𝑒𝑝𝑖𝑠𝑜𝑑𝑒): 5: 𝐴←{ 𝑎𝑟𝑔𝑚𝑎𝑥𝑎𝑄(𝑎), 𝑤𝑖𝑡ℎ 𝑝𝑟𝑜𝑏𝑎𝑎𝑏𝑖𝑙𝑖𝑡𝑦 1−𝜀 𝑎 𝑟𝑎𝑛𝑑𝑜𝑚 𝑎𝑐𝑡𝑖𝑜𝑛, 𝑤𝑖𝑡ℎ 𝑝𝑟𝑜𝑏𝑎𝑎𝑏𝑖𝑙𝑖𝑡𝑦 𝜀 6: 𝑅←𝑒𝑥𝑒𝑐𝑢𝑡𝑒(𝐴) 7: 𝑁(𝐴)←𝑁(𝐴)+1 8: 𝑄(𝐴)←𝑄(𝐴)+1 𝑁(𝐴)(𝑅−𝑄(𝐴)) IV Optimistic Initial Values The previous method is dependent on the initial action-value estimate, 𝑄0(𝑎), considered to be biased by its initial value. Initial action values can be used to encourage exploration. As an alternative of manually setting the initial action value estimate to zero, it is set to a value significantly above the one it is estimated to be around. This optimistic value for the estimate forces the action-value methods to explore. For every action initially selected, the reward received is always less than the initial estimate. Thus the algorithm must switch to other actions since the received rewards will always lower the estimates. All actions are tried a sizable number of times before the estimate values converge. V Upper Confidence Bound A particularity of 𝜀-greedy is that the action selection chooses which non-greedy action is tried with no preference regarding non-greediness degree. While exploring, the action selection process is based on the potential for optimality. By taking into consideration, both how close the estimates are to being optimal and the uncertainties of the estimates. An effective way of performing this action selection method is: 𝐴𝑡=𝑎𝑟𝑔𝑚𝑎𝑥𝑎[𝑄𝑡(𝑎)+𝑐√ln𝑡 𝑁𝑡(𝑎)] (3.8) Deep Reinforcement Learning for Robot Navigation Systems 30 As notation, 𝑁𝑡(𝑎) denotes the number of times action 𝑎 has been selected before time step 𝑡. If 𝑁𝑡(𝑎), is zero then 𝑎 is interpreted as a maximising action. The parameter 𝑐 that must be higher than zero controls the exploration degree. The concept of this upper confidence bound action selection is that the square root term works as an uncertainty measure or variance in the action value estimates. For every selection of action 𝑎 the uncertainty is reduced: as 𝑁𝑡(𝑎) increments thus decreasing the uncertainty term. However, every time 𝑎 is not chosen, 𝑡 increases, but 𝑁𝑡(𝑎) does not, therefore the uncertainty estimate increases. The usage of this algorithm results on the following outcomes: a) the increases get smaller over time, b) all actions are eventually selected and actions with lesser value estimates, or recently chosen, are selected with a decreasing frequency over time. VI Nonstationary Problem Some reinforcement learning problems have reward probabilities that change over time, meaning they are nonstationary. In such cases, recent rewards should have a more significant weight in comparison to rewards from a long time ago. A solution to this problem is the use of a constant step size parameter. Equation (3.7) can be rewritten as: 𝑄𝑛=𝑄𝑛−1+𝛼[𝑅𝑛−𝑄𝑛−1] (3.9) The step size 𝛼∈[0,1] is a constant value. 𝑄𝑛 is a weighted average of past rewards and the initial estimate 𝑄0: 𝑄𝑛=𝑄𝑛−1+𝛼[𝑅𝑛−𝑄𝑛−1] (3.10) 𝑄𝑛=𝛼𝑅𝑛+(1−𝛼)𝑄𝑛−1 𝑄𝑛=𝛼𝑅𝑛+(1−𝛼)[𝛼𝑅𝑛−1+(1−𝛼)𝑄𝑛−2] 𝑄𝑛=𝛼𝑅𝑛+(1−𝛼)𝛼𝑅𝑛−1+(1−𝛼)2𝑄𝑛−2 𝑄𝑛=𝛼𝑅𝑛+(1−𝛼)𝛼𝑅𝑛−1+(1−𝛼)2𝛼𝑅𝑛−2+⋯ +(1−𝛼)𝑛−1𝛼𝑅1+(1−𝛼)𝑛𝑄0 𝑄𝑛=(1−𝛼)𝑛𝑄0+∑𝛼(1−𝛼)𝑛−𝑖𝑅𝑖 𝑛 𝑖=1 Deep Reinforcement Learning for Robot Navigation Systems 31 The weight 𝛼(1−𝛼)𝑛−𝑖 given to the reward 𝑅𝑖, depends on how many rewards ago 𝑛 −𝑖, was observed. The quantity 1−𝛼 is less than one, thus the weight given to 𝑅𝑖 decreases as the number of rewards increases. The weight decays exponentially according to the exponent on 1−𝛼. It is usually suitable to vary the step size parameter from step to step. 𝛼𝑛(𝑎) denotes the step size parameter used to calculate the received reward after the 𝑛th selection of action 𝑎. As previously demonstrated 𝛼𝑛(𝑎)=1 𝑛 is the sample average method, that is guaranteed to converge because of the true action values by the law of large numbers. However, convergence is not certain for every choice of 𝛼𝑛(𝑎). The conditions to guarantee convergence that results from a stochastic approximation theory are both: ∑𝛼𝑛(𝑎)=∞ ∞ 𝑛−1 (3.11) ∑𝛼𝑛 2(𝑎)<∞ ∞ 𝑛−1 (3.12) Condition (3.11) is required to overcome any initial conditions or random fluctuations eventually, through large steps. Condition (3.12) guarantees that eventually, the steps become small enough to assure convergence. 3.1.3 Markov Decision Processes In this subchapter, a formal problem of finite Markov Decision Processes is described. This formal problem, evaluates feedback, similar to the bandits, previously described, but with a new feature: the capability of choosing different actions in different situations. MDPs are a conventional formalisation of sequential decision making, where actions impact not only on immediate rewards but also on long-time rewards. Therefore, a crucial part of the MDPs is the trade-off between instant and delayed rewards. Opposing to the bandit problem, in this subchapter, the 𝑞∗(𝑎) of each action 𝑎 in each state 𝑠, will be estimated, or the value 𝑣∗(𝑠) of each state, given optimal action is selected. These state-dependent quantities are crucial to assign credit for long-term outcomes to a specific action selection. Also, in this subchapter, a mathematical reinforcement learning introduction to elements, such as returns, value functions and the Bellman equations, is presented. Deep Reinforcement Learning for Robot Navigation Systems 32 I Agent-Environment Interaction and Markov Property The agent and the environment interact with each other on a sequence of discrete time steps, 𝑡= 0,1,2,… . At each time step 𝑡 the agent receives from the environment a state, 𝑆𝑡∈𝑆, and selects an action 𝐴𝑡∈𝐴. On the following time step, as a consequence of the previous time step action, the agent receives a numerical reward, 𝑅𝑡+1∈𝑅∈ℝ and the current and updated state 𝑆𝑡+1.The agent with the MDP creates a sequence of states, actions and rewards similar to: 𝑆0,𝐴0,𝑅1,𝑆1,𝐴1,𝑅2,𝑆2,𝐴2,𝑅3,𝑆3,𝐴4,… (3.13) When working with a finite MDP, the sets of states, actions and rewards (𝑆𝐴𝑅) have a finite number of elements. The random variables 𝑅𝑡 and 𝑆𝑡, have a discrete probability distribution dependent on the next state and action. Thus, for specific values of these variables, 𝑠′∈𝑆 and 𝑟∈𝑅, the probability of occurring at time step 𝑡, given previous state and action specific values. The following function, 𝑝 defines MDP’s dynamics: 𝑝(𝑠′,𝑟 | 𝑠,𝑎)=𝑝{𝑆𝑡+1=𝑠′,𝑅𝑡+1=𝑟 | 𝑆𝑡=𝑠,𝐴𝑡=𝑎 } (3.14) In an MDP, the probabilities characterise the environment dynamics entirely. Thus, the probabilities of each possible value for 𝑆𝑡 and 𝑅𝑡 only depends on the directly preceding state and action 𝑆𝑡−1 and 𝐴𝑡−1. This property is better viewed as a state restriction, not on the decision process. To surpass the property, the current state must now include information on all the noteworthy interactions between the agent and the environment. If the state possesses this past information, it is known to have the Markov property. From the MDPs dynamics function 𝑝, it is possible to calculate all the other information about the environment, for example, the state-transition probabilities: 𝑝(𝑠′| 𝑠,𝑎)=𝑝{𝑆𝑡=𝑠′| 𝑆𝑡−1=𝑠,𝐴𝑡−1=𝑎 }= ∑𝑝(𝑠′,𝑟 | 𝑠,𝑎) 𝑟∈𝑅 (3.15) The expected rewards for state-action pairs as a two-argument function can also be calculated as: 𝑟(𝑠,𝑎)=𝔼[𝑅𝑡 | 𝑆𝑡−1=𝑠,𝐴𝑡−1=𝑎]=∑𝑟 𝑟∈𝑅 ∑𝑝(𝑠′,𝑟 | 𝑠,𝑎) 𝑠′∈𝑆 (3.16) Also, the expected rewards for the (𝑠,𝑎,𝑠′) triplet is a three-argument function calculated as: 𝑟(𝑠,𝑎,𝑠′)=𝔼[𝑅𝑡 | 𝑆𝑡−1=𝑠,𝐴𝑡−1=𝑎,𝑆𝑡=𝑠]=∑𝑟 𝑟∈𝑅 𝑝(𝑠′,𝑟 | 𝑠,𝑎) 𝑝(𝑠′| 𝑠,𝑎) (3.17) Deep Reinforcement Learning for Robot Navigation Systems 33 In Figure 3.2, an example of a state transition diagram is presented. The larger circles, denoted as 𝑆 represent the possible states, the smaller circles marked as 𝑎 denote the possible actions, the large arrows denote the terminal states and respective reward, and the smaller arrows represent the state probabilities. Figure 3.2 - State transition diagram, with three states, two actions, two terminal states and the state transition probabilities. II Goals and Rewards At each time step, a reward signal 𝑅𝑟∈ℝ is sent from the environment to the agent. The agent’s primary goal is to maximise the overall amount of reward it receives. Not only maximises the immediate reward but also the cumulative reward in the long run. Reward signals used as a goal formalisation are a distinctive feature of reinforcement learning. The design of goals is not trivial, and even though it usually demands a rigorous study, it is proved to be considerably flexible and widely applicable. Some hypothetical examples of how it can be used are presented for a more fundamental understanding: 1. For a robot to learn how to move, rewards on each time step can be provided reliant on the task at hand, for example, proportional to the robot’s motion. 2. For a robot to escape a periodic maze, the reward can be a negative constant value for every time step needed to escape. This method encourages the agent to perform the task on minimal steps for a minor negative reward. 3. For a robot to collect garbage for recycling, another strategy might be to present null rewards except when successfully picking up garbage. 4. Negative rewards are also an essential part as they present strategies to avoid situations that the agent must avoid. For example: when a navigation robot hits a wall or breaks some part. In the previous examples and many other reward implementations, it is crucial that the agent always learns how to maximise its rewards. The system that provides the rewards must be programmed in such a way to maximise the overall reward results on achieving the goal. The problem with reward specification is that many times the agent gets stuck in sub-optimal situations instead of focusing on the ultimate goal. Deep Reinforcement Learning for Robot Navigation Systems 34 For example, in a game of chess, an agent should not be rewarded for destroying opponents pieces but for winning a game. These are different things and may compromise the agent’s overall performance. III Returns and Episodes As previously discussed, the agent's goal is to maximise the cumulative reward it receives in the long run. The interest of an agent must reside on total future reward, everything from the current time step onwards. For the agent to learn, it needs to maximise the expected return, where 𝐺𝑡 is the return. A simple return definition can be the sum of future rewards: 𝐺𝑡=𝑅𝑡+1+𝑅𝑡+2+⋯+𝑅𝑇 (3.18) Time step 𝑇 represents a terminal state. Each episode must end in a specific state, known as a terminal state, which leads to the end of the episode and consequently the start of the next episode. Episodes are entirely independent of each other. The end of an episode does not affect in any way the start of the next episode. Thus the episodes can all be considered to finish in the same terminal state, but with different rewards for different outcomes. This kind of task is known as an episodic task. However, in many cases, such as control tasks, the agent-environment interaction cannot be broken logically into identifiable episodes but goes on continually. These are called continuous tasks. Some examples of continuous tasks are process-control and robotics tasks. It is infeasible to apply (3.18) to continuous tasks since time step 𝑇 is unkown and could result in 𝑇=∞ and consequently 𝐺𝑡=±∞. The use of a discount factor introduces the concept of discounting rewards. As a return in discounting rewards, the agent must select an action so that the future discounted rewards sum received is maximised: 𝐺𝑡=𝑅𝑡+1+𝛾𝑅𝑡+2+𝛾2𝑅𝑡+3+⋯=∑𝛾𝑘𝑅𝑡+𝑘+1 ∞ 𝑘=0 (3.19) 𝛾 denotes the discount factor, 0≤𝛾≤1. The discount factor determines the value that future rewards are worth on the current time step. A reward obtained 𝑘 time steps in the future is worth 𝛾𝑘−1 times what would be worth if it were to be received in the present time step. Returns at successive time steps are related in an essential way for reinforcement learning algorithms to be able to learn: 𝐺𝑡=𝑅𝑡+1+𝛾𝑅𝑡+2+𝛾2𝑅𝑡+3+⋯ 𝐺𝑡=𝑅𝑡+1+𝛾(𝑅𝑡+2+𝛾2𝑅𝑡+3+⋯) 𝐺𝑡=𝑅𝑡+1+𝛾𝐺𝑡+1 (3.20) Deep Reinforcement Learning for Robot Navigation Systems 35 IV Policies and Value Functions Value functions are used in reinforcement learning algorithms to estimate either the value of the agent to be in a given state or the value to perform a specific action in a given state. The concept of value or how good, is defined in terms of expected returns. The rewards an agent may expect are a consequence of the actions it will perform. Value functions are defined by specific ways of acting, named policies. A policy 𝜋 is a map from states to probabilities of selecting each possible action. If an agent follows a policy 𝜋 at time step 𝑡, then 𝜋(𝑎|𝑠) is the probability that 𝐴𝑡=𝑎 if 𝑆𝑡=𝑠. The value function 𝑣𝜋(𝑠), of a state 𝑠 under a policy 𝜋, is the expected reward when starting in 𝑠 and following 𝜋. For MDPs, 𝑣𝜋 can be formalised by: 𝑣𝜋(𝑠)=𝔼𝜋[𝐺𝑡 | 𝑆𝑡=𝑠]=𝔼𝜋[∑𝛾𝑘𝑅𝑡+𝑘+1 ∞ 𝑘=0 | 𝑆𝑡=𝑠] (3.21) In the same way, the action-value 𝑞𝜋(𝑠,𝑎) can also be defined by taking an action 𝑎 in state 𝑠 under a policy 𝜋: 𝑞𝜋(𝑠,𝑎)=𝔼𝜋[𝐺𝑡|𝑆𝑡=𝑠,𝐴𝑡=𝑎]=𝔼𝜋[∑𝛾𝑘𝑅𝑡+𝑘+1 ∞ 𝑘=0 |𝑆𝑡=𝑠,𝐴𝑡=𝑎] (3.22) A central value function has a recursive property. For any policy 𝜋 and state 𝑠, it is possible to iteratively calculate the 𝑠 value from the value of its possible previous states: 𝑣𝜋(𝑠)=𝔼𝜋[𝐺𝑡 | 𝑆𝑡=𝑠] 𝑣𝜋(𝑠)=𝔼𝜋[𝑅𝑡+1+𝛾𝐺𝑡+1 | 𝑆𝑡=𝑠] 𝑣𝜋(𝑠)=∑𝜋(𝑎|𝑠) 𝑎∑∑𝑝(𝑠′,𝑟|𝑠,𝑎)[𝑟+𝛾𝔼𝜋[𝐺𝑡+1|𝑆𝑡=𝑠′]] 𝑟𝑠′ 𝑣𝜋(𝑠)=∑𝜋(𝑎|𝑠) 𝑎∑𝑝(𝑠′,𝑟|𝑠,𝑎)[𝑟+𝛾𝑣𝜋(𝑠′)] 𝑠′,𝑟 (3.23) Equation (3.23) is the Bellman equation for 𝑣𝜋. The Bellman equation states the association between the value of a specific state and the values of its successor states. Figure 3.3 shows a 𝑣𝜋 visual representation diagram, where the white circles represent a state 𝑠 and the blue circles represent the possible actions 𝑎. Based on the policy 𝜋, from state 𝑠, the agent can take an action 𝑎. The environment would respond with a reward 𝑟 and the next state 𝑠′, depending on the dynamics given by 𝑝. Deep Reinforcement Learning for Robot Navigation Systems 42 require an utter greedy policy, but only that it follows a greedy policy such as 𝜀-greedy. The complete algorithm is demonstrated in the following pseudocode. Algorithm 3.3 – Monte Carlo without Exploring Starts, for estimating 𝝅≈𝝅∗ 1: 𝐴𝑙𝑔𝑜𝑟𝑖𝑡ℎ𝑚 𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟:𝑠𝑚𝑎𝑙𝑙 𝜀>0 2: 𝐼𝑛𝑖𝑡: 3: 𝜋←𝑎 𝑟𝑎𝑛𝑑𝑜𝑚 𝜀 𝑠𝑜𝑓𝑡 𝑝𝑜𝑙𝑖𝑐𝑦 4: 𝑄(𝑠,𝑎)∈ℝ (𝑟𝑎𝑛𝑑𝑜𝑚𝑙𝑦),𝑓𝑜𝑟 𝑎𝑙𝑙 𝑠∈𝑆,𝑎∈𝐴(𝑠) 5: 𝑅𝑒𝑡𝑢𝑟𝑛𝑠(𝑠,𝑎)←𝑒𝑚𝑝𝑡𝑦 𝑙𝑖𝑠𝑡,𝑓𝑜𝑟 𝑎𝑙𝑙 𝑠∈𝑆,𝑎∈𝐴(𝑠) 6: 𝐿𝑜𝑜𝑝 (𝑓𝑜𝑟 𝑒𝑎𝑐ℎ 𝑒𝑝𝑖𝑠𝑜𝑑𝑒): 7: 𝐺𝑒𝑛𝑒𝑟𝑎𝑡𝑒 𝑎𝑛 𝑒𝑝𝑖𝑠𝑜𝑑𝑒 𝑓𝑜𝑙𝑙𝑜𝑤𝑖𝑛𝑔 𝜋:𝑠0,𝑎0,𝑟1,… ,𝑠𝑇−1,𝑎𝑇−1,𝑟𝑇 8: 𝐺←0 9: 𝐿𝑜𝑜𝑝 (𝑓𝑜𝑟 𝑒𝑎𝑐ℎ 𝑒𝑝𝑖𝑠𝑜𝑑𝑒′𝑠 𝑡𝑖𝑚𝑒 𝑠𝑡𝑒𝑝),𝑡=𝑇−1,𝑇−2,…,0: 10: 𝐺←𝛾𝐺+𝑟𝑡+1 11: 𝑈𝑛𝑙𝑒𝑠𝑠 𝑡ℎ𝑒 𝑝𝑎𝑖𝑟 𝑠𝑡,𝑎𝑡 𝑎𝑝𝑝𝑒𝑎𝑟𝑠 𝑖𝑛 𝑠0,𝑎0,𝑠1,𝑎1,… ,𝑠𝑇−1,𝑎𝑇−1 12: 𝐴𝑝𝑝𝑒𝑛𝑑 𝐺 𝑡𝑜 𝑅𝑒𝑡𝑢𝑟𝑛𝑠(𝑠𝑡,𝑎𝑡) 13: 𝑄(𝑠𝑡,𝑎𝑡)←𝑎𝑣𝑒𝑟𝑎𝑔𝑒(𝑅𝑒𝑡𝑢𝑟𝑛𝑠(𝑠𝑡,𝑎𝑡)) 14: 𝑎∗←𝑎𝑟𝑔𝑚𝑎𝑥𝑎𝑄(𝑠𝑡,𝑎) 15: 𝐹𝑜𝑟 𝑎𝑙𝑙 𝑎 ∈𝐴(𝑠𝑡) 16: 𝜋(𝑎|𝑠𝑡)←{ 1−𝜀+𝜀 |𝐴(𝑠𝑡)|,𝑖𝑓 𝑎=𝑎∗ ⁄ 𝜀 |𝐴(𝑠𝑡)| ⁄,𝑖𝑓 𝑎≠𝑎∗ The Policy Improvement Theorem guarantees that a 𝜀-greedy policy 𝜋′ concerning 𝑞𝜋 is an improvement over any 𝜀-soft policy. The Policy Improvement Theorem conditions apply because for any 𝑠∈𝑆: 𝑞𝜋(𝑠,𝜋′(𝑠))=∑𝜋′(𝑎|𝑠) 𝑎𝑞𝜋(𝑠,𝑎) 𝑞𝜋(𝑠,𝜋′(𝑠))=𝜀 |𝐴(𝑠)|∑𝑞𝜋(𝑠,𝑎) 𝑎+(1−𝜀)𝑚𝑎𝑥𝑎𝑞𝜋(𝑠,𝑎) 𝑞𝜋(𝑠,𝜋′(𝑠))≥𝜀 |𝐴(𝑠)|∑𝑞𝜋(𝑠,𝑎) 𝑎+(1−𝜀)∑𝜋(𝑎|𝑠)−𝜀 |𝐴(𝑠)| 1−𝜀 𝑎𝑞𝜋(𝑠,𝑎) 𝑞𝜋(𝑠,𝜋′(𝑠))=𝜀 |𝐴(𝑠)|∑𝑞𝜋(𝑠,𝑎) 𝑎−𝜀 |𝐴(𝑠)|∑𝑞𝜋(𝑠,𝑎) 𝑎+∑𝜋(𝑠|𝑎) 𝑎𝑞𝜋(𝑠,𝑎) 𝑞𝜋(𝑠,𝜋′(𝑠))=𝑣𝜋(𝑠) (3.37) 3.1.6 Temporal Difference Learning Temporal Difference Learning is considered by the reinforcement learning scientific community as a central and novel strategy of reinforcement learning. TD learning combines ideas from both Dynamic Programming and Monte Carlo methods. From MC methods, TD takes advantage of the learning from Deep Reinforcement Learning for Robot Navigation Systems 43 raw experience strategy, without the need of an environment dynamics model. From DP methods, TD update estimates based on the learned estimates, without waiting for an outcome. This process is known as bootstrapping. These three methods can be combined in many ways and are a recurrent theme in reinforcement learning theory. This subchapter will initially present the theoretical foundations on the policy evaluation or prediction problem, which is the problem of estimating the value function 𝑣𝜋 for a policy 𝜋. Secondly, for the control problem or finding the optimal policy, the three methods use some variant forms from generalised policy iteration. The alternatives of GPI are mainly variations on trying to solve the prediction problem. I Temporal Difference Prediction Both TD and MC methods use the agent’s experience in the environment to solve the prediction problem. By experiencing following a policy 𝜋, these methods update their estimate 𝑉 of 𝑣𝜋 for every nonterminal experienced state 𝑆𝑡. The main difference between both methods is that MC must wait until the return 𝐺𝑡 after a visit is known, at the end of an episode, then use that return as a target for 𝑉(𝑆𝑡), as demonstrated in the following equation: 𝑉(𝑆𝑡)←𝑉(𝑆𝑡)+𝛼[𝐺𝑡−𝑉(𝑆𝑡)] (3.38) Whereas TD methods must only wait for the following time step 𝑡+1 and can already make a suitable update using both the observed reward 𝑅𝑡+1 and the estimate 𝑉(𝑆𝑡+1): 𝑉(𝑆𝑡)←𝑉(𝑆𝑡)+𝛼[𝑅𝑡+1+𝛾𝑉(𝑆𝑡+1)−𝑉(𝑆𝑡)] (3.39) The target for the MC update is 𝐺𝑡, while the target for the TD update is 𝑅𝑡+1 + 𝛾𝑉(𝑆𝑡+1). This target update is known as TD(0). In Figure 3.5, a display of the differences in how MC methods (a) and TD methods (b) solve the prediction problem. (a) (b) Figure 3.5 - Differences regarding the prediction problem for Monte Carlo methods (a) and Temporal Difference methods (b). The following algorithm provides the pseudocode for a tabular TD(0) to estimate 𝑣𝜋. Deep Reinforcement Learning for Robot Navigation Systems 44 Algorithm 3.4 – Temporal Difference (0) for estimating 𝒗𝝅 1: 𝐼𝑛𝑝𝑢𝑡:𝑡ℎ𝑒 𝑝𝑜𝑙𝑖𝑐𝑦 𝜋 𝑡𝑜 𝑏𝑒 𝑒𝑣𝑎𝑙𝑢𝑎𝑡𝑒𝑑 2: 𝐴𝑙𝑔𝑜𝑟𝑖𝑡ℎ𝑚 𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟:𝑠𝑡𝑒𝑝 𝑠𝑖𝑧𝑒 𝛼∈[0,1] 3: 𝐼𝑛𝑖𝑡 𝑉(𝑠),𝑓𝑜𝑟 𝑎𝑙𝑙 𝑠∈𝑆,𝑟𝑎𝑛𝑑𝑜𝑚𝑙𝑦 𝑒𝑥𝑐𝑒𝑝𝑡 𝑓𝑜𝑟 𝑉(𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑙)=0: 4: 𝐿𝑜𝑜𝑝 (𝑓𝑜𝑟 𝑒𝑎𝑐ℎ 𝑒𝑝𝑖𝑠𝑜𝑑𝑒): 5: 𝐼𝑛𝑖𝑡𝑖 𝑠 6: 𝐿𝑜𝑜𝑝 (𝑓𝑜𝑟 𝑒𝑎𝑐ℎ 𝑒𝑝𝑖𝑠𝑜𝑑𝑒′𝑠 𝑡𝑖𝑚𝑒 𝑠𝑡𝑒𝑝): 7: 𝑎←𝑎𝑐𝑡𝑖𝑜𝑛 𝑔𝑖𝑣𝑒𝑛 𝑏𝑦 𝜋 𝑓𝑜𝑟 𝑠 8: 𝑇𝑎𝑘𝑒 𝑎𝑐𝑡𝑖𝑜𝑛 𝑎,𝑜𝑏𝑠𝑒𝑟𝑣𝑒 𝑟,𝑠′ 9: 𝑉(𝑠)←𝑉(𝑠)+𝛼[𝑟+𝛾𝑉(𝑠′)−𝑉(𝑠)] 10: 𝑠←𝑠′ 11: 𝑢𝑛𝑡𝑖𝑙 𝑠 𝑖𝑠 𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑙 The part in brackets in the TD(0) update, equation (3.39), is known as the TD error, that is the difference between the estimated value of 𝑆𝑡 and the improved estimate 𝑅𝑡+1+𝛾𝑉(𝑆𝑡+1), denoted as 𝛿𝑡: 𝛿𝑡=𝑅𝑡+1+𝛾𝑉(𝑆𝑡+1)−𝑉(𝑆𝑡) (3.40) At each time step, the TD error is the error in the estimate made at that time. Since the TD error depends on the next state and the next reward, it is not available until the following time step. This means 𝛿𝑡 is the error in 𝑉(𝑆𝑡) available at time step 𝑡+1. II Advantages of TD Prediction Methods Temporal Difference methods have an advantage over DP methods, as neither it requires an environment model nor the reward and next-state probability distributions. TD methods diverge from DP as a modelfree method whose updates are based on other estimates. From the process of guessing from a guess, the correct terminology used is the method bootstraps. The advantage over MC methods is that in TD learning the methods are naturally implemented as an online fully incremental strategy. In Monte Carlo methods, the algorithm can only correctly update the value function when the episode finishes, as only then receives the full return function. In TD Learning this process can be performed every time step. This is a critical consideration as some applications have considerably long episodes, and suspending all the learning until the episode’s end substantially slows down the process. A different range of applications, named continuing tasks must also be solved with TD methods as there are no episodes at all. This is in some cases the instance for robotics reinforcement learning. The TD methods are less susceptible to these problems as they learn every time step regardless of the following actions taken. In Figure 3.6, the differences between DP (a), MC (b) and TD (c) can be Deep Reinforcement Learning for Robot Navigation Systems 45 visualised in the diagram. The white circles denote the states and the blue circles denote the actions. The blue cloud over the circles denotes the required information to adjust 𝑆𝑡. When studying and comparing TD Learning to DP and MC methods, two questions tend to arise. Firstly for TD Learning method, if the convergence to the correct answer is guaranteed just by learning from estimates of estimates without waiting for an actual outcome. (a) (b) (c) Figure 3.6 - Differences between Dynamic Programming (a), Monte Carlo (b), and Temporal Difference (c) learning. For a fixed policy 𝜋, TD(0) has been proved to converge to 𝑣𝜋 for an adequately small constant step-size parameter, and with a full probability, if the step-size parameter decreases as the previously mentioned stochastic approximation conditions (3.11) and (3.12). Secondly, since both TD and MC methods converge asymptotically to the correct predictions, the issue lays on if there is a way to discover which learns faster by making more efficient use of the same limited data. At the time, this is considered to be an openquestion since it has not been proven mathematically that one of the methods converges faster. However, in practice TD methods tend to converge faster than regular MC methods on stochastic tasks. III Solutions to TD Control Problem After a TD prediction methods analysis, the present and the following sections will demonstrate two different solutions to the control problem. The goal, as in previous subchapters is to follow the outline of GPI but using TD methods for the estimation or prediction part. As MC methods, the trade-off between exploration and exploitation must be considered. The two discussed approaches consist of on-policy and off-policy approaches. The main difference between the two algorithms is that in an on-policy solution, like SARSA, the learned policy value is carried out by the agent, including the exploration steps, whereas in an off-policy solution like Q-Learning, the action chosen is independent of the policy being followed. In TD Learning methods, contrary to MC, the state-value function 𝑉(𝑆𝑡) is replaced by the action-value function 𝑄(𝑆𝑡,𝐴𝑡). For on-policy methods, 𝑞𝜋(𝑠,𝑎) must be estimated for the current behaviour policy 𝜋, all states 𝑠 and all actions 𝑎. As previously described, an episode consists of an alternating sequence of states and state-action pairs, like the one presented in Figure 3.7. Deep Reinforcement Learning for Robot Navigation Systems 46 Figure 3.7 - Sequence of alternating states and state-action pairs. IV SARSA: On-Policy TD Control In TD Learning, the transitions considered are from one state-action pair to another and learned the values of state-action pairs. These cases, for state-action instead of action-value, are identical since both are Markov chains with a rewarding process. The deductions which assure the convergence of state-values under TD(0) may also apply to the corresponding algorithm for action-values: 𝑄(𝑆𝑡,𝐴𝑡)←𝑄(𝑆𝑡,𝐴𝑡)+𝛼[𝑅𝑡+1+𝛾𝑄(𝑆𝑡+1,𝐴𝑡+1)−𝑄(𝑆𝑡,𝐴𝑡)] (3.41) The update equation (3.41) is performed after every transition from a nonterminal state 𝑆𝑡. In case a terminal state is presented in 𝑆𝑡+1 then 𝑄(𝑆𝑡+1,𝐴𝑡+1) is zero. This rule employs every element from the events quintuple (𝑆𝑡,𝐴𝑡,𝑅𝑡+1,𝑆𝑡+1,𝐴𝑡+1) that comprises the transitions from one state-action pair to the following one. The need to use quintuple’s five components rises the name SARSA. As it is typical in on-policy methods, to solve the control problem, 𝑞𝜋is continually estimated for the behaviour policy 𝜋 and simultaneously change 𝜋 towards greediness concerning 𝑞𝜋. SARSA control algorithm pseudocode is presented next. Algorithm 3.5 – SARSA (on-policy Temporal Difference Control) 1: 𝐴𝑙𝑔𝑜𝑟𝑖𝑡ℎ𝑚 𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟:𝑠𝑡𝑒𝑝 𝑠𝑖𝑧𝑒 𝛼∈[0,1],𝑠𝑚𝑎𝑙𝑙 𝜀>0 2: 𝐼𝑛𝑖𝑡 𝑄(𝑠,𝑎),𝑓𝑜𝑟 𝑎𝑙𝑙 𝑠∈𝑆,𝑎∈𝐴,𝑟𝑎𝑛𝑑𝑜𝑚𝑙𝑦 𝑒𝑥𝑐𝑒𝑝𝑡 𝑓𝑜𝑟 𝑄(𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑙,.)=0 3: 𝐿𝑜𝑜𝑝 (𝑓𝑜𝑟 𝑒𝑎𝑐ℎ 𝑒𝑝𝑖𝑠𝑜𝑑𝑒): 4: 𝐼𝑛𝑖𝑡 𝑠 5: 𝐶ℎ𝑜𝑜𝑠𝑒 𝑎 𝑓𝑟𝑜𝑚 𝑠 𝑢𝑠𝑖𝑛𝑔 𝑝𝑜𝑙𝑖𝑐𝑦 𝑑𝑒𝑟𝑖𝑣𝑒𝑑 𝑓𝑟𝑜𝑚 𝑄 6: 𝐿𝑜𝑜𝑝 (𝑓𝑜𝑟 𝑒𝑎𝑐ℎ 𝑒𝑝𝑖𝑠𝑜𝑑𝑒′𝑠 𝑡𝑖𝑚𝑒 𝑠𝑡𝑒𝑝): 7: 𝑇𝑎𝑘𝑒 𝑎𝑐𝑡𝑖𝑜𝑛 𝑎,𝑜𝑏𝑠𝑒𝑟𝑣𝑒 𝑟,𝑠′ 8: 𝐶ℎ𝑜𝑜𝑠𝑒 𝑎′ 𝑓𝑟𝑜𝑚 𝑠′ 𝑢𝑠𝑖𝑛𝑔 𝑝𝑜𝑙𝑖𝑐𝑦 𝑑𝑒𝑟𝑖𝑣𝑒𝑑 𝑓𝑟𝑜𝑚 𝑄 9: 𝑄(𝑠,𝑎)←𝑄(𝑠,𝑎)+𝛼[𝑟+𝛾𝑄(𝑠′,𝑎′)−𝑄(𝑠,𝑎)] 10: 𝑠←𝑠′,𝑎←𝑎′ 11: 𝑢𝑛𝑡𝑖𝑙 𝑠 𝑖𝑠 𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑙 SARSA convergence properties depend on how the policy depends on 𝑄, as 𝜀-greedy or 𝜀-soft policies can be used as exploration methods. SARSA converges to an optimal policy and action-value function if all the state-action pairs are experienced an infinite amount of times and the policy converges to the greedy policy. Deep Reinforcement Learning for Robot Navigation Systems 47 V Q-Learning: Off-Policy TD Control Q-Learning [45], is one of the early breakthroughs in reinforcement learning. It was a significant discovery as it introduced an off-policy Temporal Difference control algorithm, defined by: 𝑄(𝑆𝑡,𝐴𝑡)←𝑄(𝑆𝑡,𝐴𝑡)+𝛼[𝑅𝑡+1+𝛾𝑚𝑎𝑥𝑎𝑄(𝑆𝑡+1,𝑎)−𝑄(𝑆𝑡,𝐴𝑡)] (3.42) In Q-Learning, the learned action-value function, 𝑄, directly approximates to the optimal action-value function 𝑞∗, independently of the policy being followed. This process simplifies the algorithm analysis, and it is proven to enable early convergence to the optimal action-value function. However, the policy still affects this algorithm as it determines which state-action pairs are both visited and updated. Moreover, the only requirement for natural convergence is that all action-value pairs are continuously updated. The Q-learning control algorithm pseudocode is shown next. Algorithm 3.6 – Q-Learning (off-policy Temporal Difference Control) 1: 𝐴𝑙𝑔𝑜𝑟𝑖𝑡ℎ𝑚 𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟:𝑠𝑡𝑒𝑝 𝑠𝑖𝑧𝑒 𝛼∈[0,1],𝑠𝑚𝑎𝑙𝑙 𝜀>0 2: 𝐼𝑛𝑖𝑡 𝑄(𝑠,𝑎),𝑓𝑜𝑟 𝑎𝑙𝑙 𝑠∈𝑆,𝑎∈𝐴,𝑟𝑎𝑛𝑑𝑜𝑚𝑙𝑦 𝑒𝑥𝑐𝑒𝑝𝑡 𝑓𝑜𝑟 𝑄(𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑙,.)=0 3: 𝐿𝑜𝑜𝑝 (𝑓𝑜𝑟 𝑒𝑎𝑐ℎ 𝑒𝑝𝑖𝑠𝑜𝑑𝑒): 4: 𝐼𝑛𝑖𝑡 𝑠 5: 𝐿𝑜𝑜𝑝 (𝑓𝑜𝑟 𝑒𝑎𝑐ℎ 𝑒𝑝𝑖𝑠𝑜𝑑𝑒′𝑠 𝑡𝑖𝑚𝑒 𝑠𝑡𝑒𝑝): 6: 𝐶ℎ𝑜𝑜𝑠𝑒 𝑎 𝑓𝑟𝑜𝑚 𝑠 𝑢𝑠𝑖𝑛𝑔 𝑝𝑜𝑙𝑖𝑐𝑦 𝑑𝑒𝑟𝑖𝑣𝑒𝑑 𝑓𝑟𝑜𝑚 𝑄 7: 𝑇𝑎𝑘𝑒 𝑎𝑐𝑡𝑖𝑜𝑛 𝑎,𝑜𝑏𝑠𝑒𝑟𝑣𝑒 𝑟,𝑠′ 8: 𝑄(𝑠,𝑎)←𝑄(𝑠,𝑎)+𝛼[𝑟+𝛾𝑚𝑎𝑥𝑎𝑄(𝑠′,𝑎′)−𝑄(𝑠,𝑎)] 9: 𝑠←𝑠′ 10: 𝑢𝑛𝑡𝑖𝑙 𝑠 𝑖𝑠 𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑙 Since it is an off-policy algorithm, it allows the agent to perform any action rather than the one best suited by the policy 𝜋. Instead, it updates the state-action function regarding the most valuable action, despite following a different policy. This algorithm allows the agent to learn while experiencing or performing an episode and despite the which, actions are taken during the episode. 3.2 Approximation Methods Linear models provide convergence guarantees and are in practice very efficient in terms of data as well as computation wise. The efficiency critically depends on how the states are represented in terms of features. Feature selection is an essential task as it adds a prior domain knowledge to reinforcement learning systems. The features should correspond to the state-space aspects where a generalisation process may be appropriate. For examples when valuing geometric objects, some useful information would be to set different features for each shape, colour, size or function. When valuing states of a mobile Deep Reinforcement Learning for Robot Navigation Systems 48 robot, some examples of a natural set of features are locations, sensor readings, internal processes and battery power. A linear form limitation is that it can not consider any interactions between features, such as the occurrence of feature 𝑖 is only a positive case in the absence of feature 𝑗. In this dissertation, the only two presented approximation method is a nonlinear function approximator named artificial neural networks and a radial basis function (RBF), since these are the only used methods in the reinforcement learning algorithms implemented. 3.2.1 Nonlinear Function Approximator: Artificial Neural Networks Artificial Neural Networks (ANNs) are broadly used for nonlinear function approximation. An ANN is a network of interconnected units that has some neuron’s properties reproducing the nervous systems main components. ANNs have a long history, with the latest advances in training deeply-layered ANNs, named as Deep Learning, being responsible for some of the most impressive abilities across all machine learning algorithms, including reinforcement learning. In Figure 3.8, a visual diagram of a generic feedforward ANN, meaning a network with no loops within the network by which a unit’s outputs can influence its input. The network presented in Figure 3.8 has an output layer, made of two output units, one input layer with three input units and two hidden layers, which are intermediate layers between the input and output layers. For each link represented by the arrows, is an associated weight value. The weight corresponds to a synaptic connection in a real neural network. If an ANN has at least a connection from an output unit to input or intermediate unit, it is considered to be a recurrent neural network. Even though feedforward and recurrent neural networks are both extremely used in reinforcement learning, in this subchapter as well as the practical implementation of this dissertation, only the feedforward neural networks are discussed and implemented. Figure 3.8 - Generic feedforward ANN with three input units, two output units, and two hidden layers with four units each. Deep Reinforcement Learning for Robot Navigation Systems 49 The units represented as circles in Figure 3.8 and described in Figure 3.9 are usually semi-linear units, which means that they calculate a weighted sum of the input signal and then apply the result to a nonlinear function, named the activation function, to produce the unit’s output. Different activation functions are commonly used, like sigmoid, logistic functions, RELU, inverse tangent and SoftMax. Figure 3.9 - Artificial neuron diagram with the three components: weigh, sum and activation. The activation of every single output unit of a feedforward ANN is a nonlinear activation pattern function over the network’s input units. The connection weights parameterises the functions. An ANN with no hidden layers can only represent a low number of the possible input-output functions. However, as demonstrated in [46], an ANN with a single layer containing a large number of sigmoid units can estimate any continuous function. For other nonlinear activation functions, this can also be proved. However, nonlinearity is essential since if all the units in a multi-layered feedforward ANN had linear activation functions, the whole network would be equivalent to a network with no hidden layers. Despite this property, to approximate high-complexity functions needed for many artificial intelligence tasks, abstractions, which are hierarchical compositions of numerous layers of lower-level abstractions such as deep architectures, may be required. The successive layers of a deep ANN calculate an increasingly abstract network’s input representation. Each unit can provide a specific feature contributing to a hierarchical representation of the overall input-output network function. Training ANN hidden layers is a way to automatically create appropriate features for a specific problem so that hierarchical representations can be produced without exclusively relying on hand-crafted features. ANNs are known to learn by a stochastic gradient method. Each weight is regulated in a direction aimed at improving the network's overall performance. In supervised learning cases, the objective function is the expected error over a set of labelled training examples. In reinforcement learning, ANNs can use TD errors to learn value functions or aim to maximise expected reward as a policy-gradient algorithm. In this case, it is necessary to estimate the objective function’s partial derivative concerning each weight, given the current values of all the network’s weights. The gradient is the vector of these partial derivatives. Deep Reinforcement Learning for Robot Navigation Systems 50 The most successful way to train ANNs with hidden layers, provided the units have differentiable activation functions, is the backpropagation algorithm. This learning algorithm consists of alternating between forward and backward passes through the network. Each forward pass calculates the activation of each unit, assuming the current activation of the network’s input units. After each forward pass, a backward pass efficiently calculates the partial derivatives for each weight. Similar to other stochastic gradient learning algorithms, the partial derivative vector is a precise gradient estimate. 3.2.2 Radial Basis Function A Radial basis function (RBF), is a natural generalisation process to continuous features. Rather than having discrete features, the RBF kernels allow for the input value to anything in the interval [0,1]. A common RBF feature 𝑥𝑖 has a Gaussian response 𝑥𝑖(𝑠) dependent on the state 𝑠, the centre state 𝑐𝑖 and the feature’s width 𝜎𝑖: 𝑥𝑖(𝑠) =exp (−‖𝑠−𝑐𝑖‖2 2𝜎𝑖2) (3.43) The distance metric choice is made accordingly to the way the states and tasks data is set. Figure 3.10 shows a one-dimensional example of three different RBF features Figure 3.10 - One-dimensional radial basis functions. The critical advantage of RBFs over binary features is that an approximate function is produced that varies smoothly and is differentiable. An RBF network is a linear function approximator that uses RBFs as its features. Some learning methods for RBF networks have dynamic centres and widths of the features, which turns them into nonlinear function approximators. Nonlinear methods can fit target functions with higher precision. However, the downsides are the high computational complexity and the need to perform some manual tuning before it becomes a robust solution. 3.3 Policy Gradient Methods In this subchapter, a novel idea is presented. Until the end of the Q-Learning subchapter, all the methods have been action-value methods. These learned the values of action and consequently selected actions based on their estimated action values. On this basis, the policies would not even exist if it was not for Deep Reinforcement Learning for Robot Navigation Systems 51 the action-value estimates. In Policy Gradient (PG), the methods learn a parameterised policy that selects an action without checking the value function. It would still be used to learn the policy parameter, but not for the action selection. The notation 𝜃∈ℝ is used for the policy parameter vector. 𝜋(𝑎|𝑠,𝜃)=𝑝{𝐴𝑡=𝑎 | 𝑆𝑡=𝑠,𝜃𝑡=𝜃} (3.44) It represents the probability to take an action 𝑎 at time step 𝑡 knowing that the environment is in state 𝑠 with parameter 𝜃. The only methods described in this subchapter, are the methods for learning the policy parameter based on a gradient of a scalar performance measure 𝐽(𝜃) concerning the policy parameter. These methods pursue a performance maximisation, so the updates resemble gradient ascent in 𝐽: 𝜃𝑡+1=𝜃𝑡+𝛼∇ 𝐽(𝜃𝑡) (3.45) Where ∇ 𝐽(𝜃𝑡) denotes a stochastic estimate, whose expectation approximates the performance measure gradient concerning 𝜃𝑡. The methods that follow this process logic are named policy gradient methods, independently of also learning an approximate value function. A new method, known as the actor-critic method, learns approximations to both policy and value functions. The actor refers to the learned policy, and the critic is a reference to the learned value function, usually a state-value function 3.3.1 Policy Approximation and its Advantages In policy gradient methods, a policy parameterisation can be performed in any way, if 𝜋(𝑎|𝑠,𝜃) is differentiable concerning its parameters. As a way to ensure exploration, it is commonly required that the policy never becomes deterministic, for example, that 𝜋(𝑎|𝑠,𝜃) ∈(0,1), for all 𝑎,𝑠 and 𝜃. In this subchapter, one of the most common parameterisations for discrete action space is presented as well as the advantages it offers over action-value methods. Policy-based methods also offer useful strategies for dealing with continuous action spaces, as will be further described in chapter 3.4. If the action-space is both discrete and small, a natural parameterisation method is to arrange parameterised numerical preferences ℎ(𝑎,𝑠,𝜃)∈ℝ for each state-action pair. The actions with the highest likelihood in each state 𝑠 have the highest probabilities of selection, for example, an exponential SoftMax distribution: 𝜋(𝑎|𝑠,𝜃)=𝑒ℎ(𝑎,𝑠,𝜃) ∑𝑒ℎ(𝑎,𝑙,𝜃) 𝑙 (3.46) The denominator of (3.46) is only required so the sum of the action probabilities in each state is one. This policy parameterisation is known as SoftMax in action preferences. The action preferences can be Deep Reinforcement Learning for Robot Navigation Systems 58 3.5 Conclusions In this chapter, the theoretical foundations behind the selected reinforcement learning algorithms are detailed. Reinforcement learning algorithms can learn purely from environment exploration, without any interference from an outside agent. The Markov Decision Processes and Bellman equations are the mathematics foundations behind RL algorithms. Different properties from both Dynamic Programming and Monte Carlo methods were merged to create a novel RL strategy named Temporal Difference Learning. The abstraction from the environment dynamics model and the capability of updating estimates based on previously learned estimates, without waiting for an outcome known as bootstrapping, is what makes Temporal Difference Learning as one of the top reinforcement learning methods. It also introduced two new algorithms, on-policy SARSA, and off-policy Q-Learning. Approximation methods are an essential tool for feature selection. ANNs are a nonlinear function approximation accountable for introducing Deep Learning techniques. These are responsible for some of the most impressive abilities across all machine learning algorithms, including reinforcement learning. Policy Gradient methods allow the agent to learn a parameterised policy that can select an action without checking the value function. By parameterising both the value function and the policy, a new set of algorithms known as the Actor-Critic are created and are commonly used as a state of the art strategy. Lastly, Deep Deterministic Policy Gradient is an actor-critic, model-free algorithm based on the deterministic policy gradient that can operate over continuous action spaces. DDPG has been shown to robustly perform a wide variety of tasks unfeasible for the previously presented algorithms, due to being able to function over continuous action spaces. DDPG is an excellent solution to implement in robotics since it is robust enough to overcome the problems that the robotics subject brings. One of the goals of this dissertation is to provide an introductory mathematical and theoretical foundation on reinforcement learning as well as some of the most common algorithms such as Monte Carlo methods, SARSA and Q-Learning and state of the art algorithms such as DDPG. However, for a more thorough explanation of all these algorithms and many more, the recommended literature lies on [21], as it is commonly known to be an essential book on reinforcement learning. On further chapters in this dissertation, three different algorithms of the ones previously described will be implemented, which are: Q-Learning, Policy Gradient and Deep Deterministic Policy Gradient. Deep Reinforcement Learning for Robot Navigation Systems 59 4 Simulation Framework: Development As referred to in subchapter 2.3, reinforcement learning algorithms designed for robotics must consider simulation environments. These simulation environments provide an operational imitation of a real-world process or system over time. Reinforcement learning requires a significantly high volume of interaction with the environment, commonly known as trial-and-error episodes, to learn an optimal policy. In order to teach an anthropomorphic robot to walk, one must perform around hundreds of thousands of episodes until the robot stops falling and having to be consistently picked up, successfully learning to walk. Therefore, simulators are an essential part of achieving results in a cost-effective and timely way. All simulations performed were made on an Acer Aspire V15 Nitro laptop (VN7-591G-744P). The Central Processing Unit (CPU) used is an Intel Core i7-4720HQ, and the Graphics Processing Unit (GPU) is an NVIDIA GeForce GTX 960M (2GB GDDR5). Additionally, the computer has a two storage drives, 1 TB Hard Disk Drive (HDD) and a 128 GB Solid-State Drive (SSD) with an 8GB DDR3 of Random-Access Memory (RAM). In this chapter, the study and comparison between two simulation environments is presented, along with, the development of all the simulated parts necessary for the reinforcement learning algorithms to be worked on: the environments, the agents, and the complete simulation layout. Additionally, a description of the communication between the different systems using Robot Operating System (ROS) and the embedded scripts developed. 4.1 Simulation Environments: V-REP and Gazebo Initially, two different simulation environments were considered for this dissertation: V-REP (Virtual Robot Experimentation Platform) [50], Figure 4.1, and Gazebo [51], Figure 4.2. As demonstrated in [43], both Deep Reinforcement Learning for Robot Navigation Systems 60 simulators present similar simulation capabilities, regarding worlds, sensors and actuators. In [52], it is presented a study regarding a thorough feature and performance comparison between the two simulators. Considering the physics engines, V-REP offers multiple engines such as Bullet 2.78, 2.83, ODE, Vortex and Newton whereas in Gazebo only ODE physics engine is available by default. Different physics engines may be used in Gazebo, yet they require Gazebo to be built from source. Both include a code and scene editor, and the objects of the scene allow full interaction. Figure 4.1 - V-REP simulation environment. Figure 4.2 - Gazebo simulation environment. The most significant differences between the two simulators are associated with the poor Gazebo usability and the restrictions regarding editing points on 3D meshes. Even though V-REP is the most resourceconsuming simulator, its ability to automatically spawn new threads on multiple CPU cores and thus taking advantage of the full amount of CPU power, is an aspect Gazebo fails to exhibit. In Table 4.1, the essential distinctions which lead to the choice between V-REP and Gazebo are presented. Figure 4.3 shows a simplistic design from the agent in both simulation environments. Deep Reinforcement Learning for Robot Navigation Systems 61 Table 4.1 - Comparison between V-REP and Gazebo. Characteristics V-REP Gazebo Default Physics Engine ODE, Bullet 2.78, Bullet 2.83, Vortex and Newton ODE Mesh Manipulation Yes, in real time No Robot Variety High: bi-pedal, hexapod, wheeled, flying, snake robots Low: wheeled, flying robots Programming Functionality Scripts attached to robots, plug-ins, ROS, and RemoteAPI C++ plug-ins or via ROS programs Model Description Included Scripts Hard to recognise how a third-party robot works Documentation Vast tutorials library and code examples, large community Step-by-step tutorials and a large user community User Interface No freezing issues. All functionality is fairly intuitive The interface froze a few times. Low UI usability Simulator Performance: One robot + Small scene Standard Standard Simulator Performance: Ten robots + Small scene Slower than Real Time Standard (a) (b) Figure 4.3 - Simplistic robot designed on both V-REP (a) and Gazebo (b) simulation environments. Deep Reinforcement Learning for Robot Navigation Systems 62 In conclusion, the chosen simulator: V-REP, offers several useful features, like numerous physics engines, a comprehensive model library, the ability to interact with the world during the simulation and, most importantly, mesh manipulation and optimisation. As described in [52], V-REP is suitable for highprecision modelling of robotic applications where only a few robots are operating simultaneously. 4.2 The Agent: Bot'n Roll ONE A Bot’n Roll ONE A [53] Arduino compatible is an Open Source didactic robot, intended for those who wish to start in the world of mobile robots, with little knowledge about electronics or computers. It has two microcontrollers, one ATmega328 running at 16MHz, programmable in C language with Arduino IDE, and one PIC18F45K22 running at 80MHz programmable in C with MPLABX Microchip supplied with firmware developed by botnroll.com [54]. The robot comes equipped with an LCD, two motors for differential drive, two infra-red obstacle sensors and all the electronics necessary for assembling a significant number of both inputs and outputs as seen in Figure 4.4. Its compatibility with Arduino shielding allows a diverse range of possible sensors to couple with the robot. Bot’n Roll ONE A is a robot commonly used in the laboratory for testing new algorithms, concepts and ideas. In order to implement the reinforcement learning algorithms on Bot’n Roll ONE A, its simulated version must be developed on V-REP. The Coppelia Robotics [55], creators of V-REP, provide a very intuitive stepby-step introductory tutorial to create a new robot named BubbleRob [56]. The simulated version of Bot’n Roll ONE A was developed in conformity with this tutorial with some variants introduced for easier integration with the reinforcement learning methods developed. (a) (b) (c) Figure 4.4 - Bot’n Roll ONE A robot (figure displayed with permission from botnroll.com). Deep Reinforcement Learning for Robot Navigation Systems 63 Two different simulation variants of the robot were developed. As presented in Figure 4.5, this simulation variant illustrates a complete robot model developed in a 3D modelling framework and imported to V- REP, allowing a much more realistic version of the robot. This version, due to its detail complexity, can only be simulated with a high-density mesh. However, as previously seen, V-REP works more accurately with simplistic versions of robots. Moreover, after a few tests, this simulation concept was abandoned due to its reduced performance regarding resource-consuming. Figure 4.5 - Simulated Bot’n Roll ONE A with a high detail complexity resulting in a high-density mesh. Thus, the second variant results in a simplistic simulation of Bot’n Roll ONE A, Figure 4.6. This model was drawn using only primitive shapes, which result in very simplistic meshes for low resource consumption. This method allowed the simulation environment to work with multiple robots at the same time while all the robots were running a smooth movement. Figure 4.6 - Simplistic simulated Bot'n Roll ONE A for a low-resource consumption implementation. All the robot parts were designed accordingly to the robot weight and size. All parts were weighed and measured for a realistic implementation compared to the real-world robot. In Table 4.2, all the information regarding the values necessary for a simplistic design is provided as well as the seven parts developed. Both simplistic and realistic robot objects designs are present. The principal moments of inertia were calculated using V-REP automatic formulas. The wheels use standard rubber surface specifications provided by V-REP to simulate the movement friction. The simplistic caster wheel consists of a sphere Deep Reinforcement Learning for Robot Navigation Systems 64 with no friction. When robots tend to be considerably light regarding weight, such as this one, V-REP advises the users to use a weight multiplication factor to improve the movement similarities to real-world during the simulation. Each object weight was multiplied by a 16 factor to improve the robot stability and movement control. Table 4.2 - Specifications regarding the simplistic created simulated agent. Object 3D Model Simplified 3D Model Size [m] Weight [kg] Caster Wheel 𝑥: 3.20𝑒−2 𝑦: 3.20𝑒−2 𝑧: 3.20𝑒−2 Real: 4.80𝑒−2 Implemented: 7.68𝑒−1 Wheel 𝑥: 6.50𝑒−2 𝑦: 6.50𝑒−2 𝑧: 2.60𝑒−2 Real: 3.30𝑒−2 Implemented: 5.28𝑒−1 Motor 𝑥: 3.70𝑒−2 𝑦: 3.70𝑒−2 𝑧: 6.70𝑒−2 Real: 2.10𝑒−1 Implemented: 3.36𝑒+0 Line Sensor 𝑥: 1.30𝑒−2 𝑦: 3.85𝑒−2 𝑧: 7.50𝑒−2 Real: 1.20𝑒−2 Implemented: 1.92𝑒−1 PCB 𝑥: 1.80𝑒−1 𝑦: 1.02𝑒−1 𝑧: 2.00𝑒−3 Real: 1.58𝑒−1 Implemented: 2.53𝑒+0 Acrylic Base 𝑥: 2.03𝑒−1 𝑦: 1.34𝑒−1 𝑧: 4.00𝑒−3 Real: 1.13𝑒−1 Implemented: 1.81𝑒+0 Battery 𝑥: 5.00𝑒−2 𝑦: 5.00𝑒−2 𝑧: 3.00𝑒−2 Real: 1.93𝑒−1 Implemented: 3.10𝑒+0 Deep Reinforcement Learning for Robot Navigation Systems 65 All the robot’s primitive shapes have a detailed set of properties for a specific robot’s usage. Every physical part, known as an object have their properties configured accordingly to Figure 4.7. All the robot’s objects are dynamic, collidable, measurable, detectable and renderable. Figure 4.7 - Simulated agent object properties. For the task at hand, the robot’s only actuators are its two motors, which grant a differential drive as the robot movement platform. No more actuators will be considered, as the moving platform is a robot’s physical restriction in a sense that, to add a different moving system, the robot had to be physically changed. The movement of the robot is the output for all reinforcement learning algorithms implemented, as it is crucial to have a well-configured motion system. In Figure 4.8, the implemented rotational actuators are represented. Figure 4.8 - Simulated Bot’n Roll ONE A, two rotational actuators representing the motors. The physical robot was designed in such a way that numerous modular distance sensors may be attached to the robot. However, for the challenge further described on the next subchapter, the robot must only use the embedded infra-red distance sensors. As seen in Figure 4.9, two different approaches were considered, one respecting the embedded sensors physical restriction (a), and the other, using simulated Time-of-Flight (ToF) distance sensors with different topologies (b). Deep Reinforcement Learning for Robot Navigation Systems 66 (a) (b) Figure 4.9 - Different obstacle sensor implementations using two infra-red wide obstacle sensors (a), and two ToF obstacle sensors (b). The detection range of the embedded sensors was designed accordingly to the one presented on the robot. A simple parameter measurement of range, height, angle, radius, and offset was performed so the simulated agent sensors remark as precisely as possible the physical sensors. The ToF distance sensors are just a theoretical implementation of a laser beam with a maximum detection distance of one meter. The topologies used on each reinforcement algorithm are described in chapters 5 and 6. 4.3 The Environment: RoboParty Obstacle Maze Similar to the agent, an environment must also be simulated. The specific task the simulated Bot’n Roll ONE A must surpass a maze similar to the one presented on the RoboParty Obstacle Maze challenge. RoboParty [57] is an international pedagogical event for new teams to learn how to build autonomous mobile robots in a fun and straightforward way, guided by qualified professionals. For three days and two nights, the teams are presented with an entirely disassembled Bot’n Roll ONE A, whereas they must build the mechanical components, solder the electronics and program the ATmega328. On the last day, teams are presented with three different challenges, one of them being the RoboParty Obstacle Maze challenge described in Figure 4.10. Deep Reinforcement Learning for Robot Navigation Systems 67 Figure 4.10 - RoboParty obstacle maze challenge (figure displayed with permission from RoboParty). The obstacle challenge consists of a maze with approximately 20 𝑐𝑚 of height walls with a single entrance point and a single exit point. The teams must only use the robots embedded infra-red obstacle sensors to avoid the maze walls in order to reach with no wall-bumping penalties the exit point. The robot must not have any modification to its original form to guarantee all teams compete under the same conditions. Simulation wise, three iterative complex mazes were developed for different reinforcement learning strategies study. In order to succeed, the agent must be able to reach the endpoint, thus solving the mazes. The first maze (approximately 1.2 𝑚 long) consists of a straight narrow line. The second maze (approximately 5.0 𝑚 long) has two curves to both sides, which force the robot to learn how to perform turns on non-straight walls and avoiding obstacles from both sides. The third maze (approximately 8.3 𝑚 long) has curves on both sides, slim and narrow wall distances, sharp edges and deep turns. The distance between walls is on average 0.5 𝑚. In Figure 4.11, the three designed mazes are presented and consist of simple wood walls represented in white. The endpoints are made of laser proximity sensors to detect whether the robot has successfully reached the end of the maze and are denoted by the magenta lines. The start points have no physical attributes and are represented by the robot’s position in the mazes. Figure 4.11 - Three iteratively complexity simulated mazes. The maze walls object properties, Figure 4.12, are similar to the agent’s primitive shapes in a way that is both collidable and measurable yet assume a static component, not able to be pushed around by the robot. The Laser detection sensor, Figure 4.13, works as an episode termination state since the robot has managed to discover the maze’s end successfully. It consists of a straight line at the robot’s main board Deep Reinforcement Learning for Robot Navigation Systems 74 state as quickly as possible. The goal for MountainCar is to reach the flag on top of the right mountain. Computation wise success is achieved when the position observation is the same as the flag position. 𝑜0≥0.5. The only other terminal state results from a predefined iteration overflow, so the car does not get stuck in an episode, it cannot solve. The iteration overflow terminal state may be deactivated. 4.6.2 CartPole The CartPole Environment, Figure 4.21, consists of a pole attached by an unactuated joint to a cart that is moving along a frictionless track. The goal is to keep the pendulum upright, preventing it from falling down by action over the cart’s velocity. Cartpole also proved to be a virtuous Q-Learning and Policy Gradient implementation environment presented in chapter 5 and 6. I Observation The CartPole environment provides four observation parameters, shown in Table 4.5. These are the pole’s angle and angular velocity and the cart’s position and velocity. Each observation parameter has its own minimal and maximal value and are visually characterised in Figure 4.22 as the red shapes. Figure 4.21 - OpenAI Gym CartPole simulation environment. Table 4.5 - CartPole observation. Number Notation Observation Minimum Maximum 0 𝑜0 Cart Position −2.4 2.4 1 𝑜1 Cart Velocity −∞ ∞ 2 𝑜2 Pole Angle ≈−41.8° ≈41.8° 3 𝑜3 Angular Velocity −∞ ∞ Deep Reinforcement Learning for Robot Navigation Systems 75 II Actions The CartPole environment offers two action outputs, presented in Table 4.6. The actions consist of increasing or decreasing the cart’s speed on the horizontal axis. The actions work as a sum of the previous speed and the increment or decrement of speed chosen as the present action. The amount the velocity is reduced or increased depends on the pole’s angle. This happens since the pole centre of gravity may differ the amount of energy necessary to move the cart. Both actions are characterised in Figure 4.22 as the light blue shapes. Table 4.6 - CartPole actions. Number Notation Action (Discrete) 0 𝑎0 Push Cart to the Left 1 𝑎1 Push Cart to the Right Figure 4.22 - CartPole environment observations and actions. III Initial State, Reward and Terminal States On the initial state, all the agent observations are assigned a uniform random value between ±0.05. For every step taken, a constant reward of +1 is received from the environment. This reward methodology privileges longer episodes, which translates on the cart trying to balance the pole for as long as possible. There is no success terminal state since the cart goal is never to drop the pole. However, this environment has three different terminal states: • Pole Angle is higher than ±12°; • Cart Position more than ±2.4; • Episode Length is higher than 𝑇. Deep Reinforcement Learning for Robot Navigation Systems 76 When the pole reaches the critical angle, ±12° it is considered that the pole has fallen, and therefore terminating the episode. If the cart position reaches the edge of the simulation display, the episode is also terminated. The last termination parameter is similar to MountainCar, but in this case, to avoid the algorithm to getting stuck in a long episode, after successfully learning the task. 𝑇 is the configurable value of maximum time steps in an episode. 4.6.3 Pendulum None of the aforementioned environments can provide both continuous action-space and state-space. In robotics, it is not common to work with non-continuous environments since almost every information provided by the real world is continuous. Some real-world examples of continuous information regarding robotics are motor speed, the position of a particular object, the distance to a wall, the next position coordinates and strength required to move something. Therefore, an environment with continuous action-space and state-space is necesary. The Pendulum environment, Figure 4.23, consists of a classic control problem. A frictionless pendulum starts in a random rotational position with an arbitrary angular velocity, and the goal is to swing the pendulum up, so it stays upright. The Pendulum environment allowed the study and test of Deep Deterministic Policy Gradient, further described in chapter 7. I Observation The Pendulum environment has three observation parameters, shown in Table 4.7. The first two are the cosine and sine of the angle 𝜃, regarding the actual pendulum angle. The third observation is the angular velocity of the pendulum. All three observations have finite minimum and maximum values. The observation parameters for the pendulum environment are displayed in Figure 4.24. Figure 4.23 - OpenAI Gym Pendulum simulation environment, with continuous action-space. Deep Reinforcement Learning for Robot Navigation Systems 77 Table 4.7 - Pendulum observation. Number Notation Observation Minimum Maximum 0 𝑜0 cos𝜃 −1.0 1.0 1 𝑜1 sin𝜃 −1.0 1.0 2 𝑜2 Angular Velocity −8.0 8.0 II Actions Table 4.8 shows the single continuous action output in the Pendulum environment. It consists of the effort made on the joint to move the pendulum to a vertical position. Table 4.8 - Pendulum actions. Number Notation Action (Continuous) Minimum Maximum 0 𝑎0 Joint Effort −2.0 2.0 This algorithm may sometimes present a wobbly stance and the need to invert the joint effort as balance its way to the top position. The action parameterisation is presented in Figure 4.24 as the light blue shapes. Figure 4.24 - Pendulum environment observations and actions. III Initial State, Reward and Terminal States The initial state is a random angle, bounded as −𝜋≤𝜃≤𝜋 and an arbitrary velocity constrained as −1<𝑜2<1. The reward function differs from the previous ones, since the complexity level increases. It depends on the present angle, the angular velocity and the chosen action. The selected action forces Deep Reinforcement Learning for Robot Navigation Systems 78 the agent to solve the problem while selecting actions with lower values for smoother control. The reward equation is as follows: 𝑅𝑡=−(𝜃2+0.1𝑑𝜃 𝑑𝑡2+0.001𝑎𝑡2) (4.1) 𝜃 is normalised between −𝜋 and 𝜋. Therefore the further the pendulum is from the top position, the higher the angular velocity is, and the greater the action is chosen, the lower the reward is. The highest possible reward is zero. Thus the pendulum goal must reach the vertical position as soon as possible, while selecting low actions, and maintaining its control position. There are no terminal states. However, similar to the other two environments, the configurable maximum number of time steps is added for the environments never to get stuck in infinite episodes. 4.7 Conclusions In this chapter, a thorough comparison between the two simulation environments, V-REP and Gazebo, was presented. The agent, a Bot’n Roll ONE A robot was designed on both simulators, to perform a practical comparison between the simulators. V-REP was chosen as the simulator to be used to implement the reinforcement learning algorithms due to its numerous physics engines, comprehensive model library, possibility to perform world interaction during the simulation and, most significantly, mesh manipulation and optimisation. The agent was designed in high detail requiring a significant mesh and in a simplistic version using only primitive shapes. The simplistic version was selected due to its effective computation performance. A detailed description of how the simulated agent was developed is also presented in this chapter, as well as an environment description and development to fit the RoboParty Obstacle Maze challenge criteria. With the ROS framework used, describing every ROS node and ROS topic, it is possible to connect the simulation environment to the control script, linking all the information necessary for the reinforcement learning algorithms to work successfully. Lastly, in this chapter, the embedded scripts necessary to customise the simulator were described to allow a direct interface with the agent, which was not possible with only the ROS framework. Three OpenAI Gym Environments, MountainCar, CartPole and Pendulum, were chosen to serve as a test platform for all the reinforcement learning algorithms described in chapter 3 and implemented on chapters 5, 6 and 7. Deep Reinforcement Learning for Robot Navigation Systems 79 5 Q-Learning Q-learning is a model-free, off-policy Temporal Difference control algorithm. It seeks to find the best action to take given a specific state. It only uses trial-and-error methods and estimations to predict the value function. Its off-policy characteristic allows the Q-learning functions to learn from actions that are outside its current policy. This TD control algorithm is one of the founding state-of-the-art strategies and is widely used in many low-level reinforcement learning solutions. This chapter is divided into two parts. The first, consists of implementing Q-Learning on two different OpenAI Gym’s environments, MountainCar and CartPole. This practical application will provide the initial feedback for the second part. A thorough explanation of every hyperparameter will be described and further compared to different Q-Learning tests. The second part refers to the Q-Learning implementation on the created simulated agent, Bot’n Roll ONE A. Q-Learning will be the first reinforcement learning method tested on the created simulated robot. In this chapter, the algorithm will work with all the robot state-space constraints. Therefore, digital distance sensors will be considered as discrete values. Two different Q-Learning approaches are tested and compared as well as detailed hyperparameter study. 5.1 Implementation and Testing on Gym’s Environments The Q-Learning strategies implemented on MountainCar and CartPole environments are significantly similar. The only change between the two strategies is the difference in the observation and action-space. The remainder of the implementation is identical since Q-Learning must be easily adapted for a wide range of problems to be a suitable reinforcement learning method. For different problems, different hyperparameter configurations must be adapted for finer tuning. A hyperparameter is a parameter whose Deep Reinforcement Learning for Robot Navigation Systems 80 value is set before the training process begins. Whereas, the values of the remaining parameters are calculated while training. The algorithm can be divided into two parts, the model and the environment interaction. The model is the Q-Learning algorithm core. It starts by initialising the feature transformation class since the observation is composed of continuous variables in both cases. The feature transformation is used to convert a state into a feature representation. Then it is used a scaler to concatenate the results of multiple transformer objects. The RBF kernels, Figure 5.1, are used as an approximation method, with different deviations to cover different parts of the state-space. This approximation method applies a list of transformer objects in parallel to the input data, then concatenates the result. This is useful to combine several feature extraction mechanisms into a single transformer. The creation of a Stochastic Gradient Descent (SGD) regressor per each action in an environment works similar to having an output neuron. Each SGD Regressor will use the data from the feature transformation composed by the RBF kernels to return a value. The regressor that returns the higher value is the greedy action for that state. The model class has three functions named predict, update and sample action. The predict function takes a state and after running through the SGD regressors, returns the greedy action. The update function receives the (𝑠,𝑎,𝐺) tuple and updates the estimator. The sample action function takes the state and 𝜀, to decide whether to perform exploration by choosing a random action, or exploitation, by sending the state to the predict function and returning the result. Figure 5.1 - Example of the neural network using RBF neurons used in this Q-Learning implementation. The environment interaction is the software module responsible for connecting the model to the simulator. It includes all the functions necessary to send and receive data from the simulation environment. It starts its initialisation by writing on the environment registers, the agent configurations. Next, the algorithm defines the value of the hyperparameter. At the moment, all the steps necessary to start the Q-Learning algorithm have been carried out. Thus, the function to perform an episode is presented. It starts by resetting the environment, then from the initial state 𝑠0 selects the action using the 𝜀-greedy exploration Deep Reinforcement Learning for Robot Navigation Systems 81 method and consequently receives the new state 𝑠1. After receiving the new state, it calculates the return according to the Q-Learning function, for the present time step and updates the model. After the model update, it goes back to sending a new action to the environment repeating the same process all over. This algorithm is ran until the episode encounters a terminal state. In both simulation environments, when a set of episodes ends, the graphs for that specific hyperparameter configuration are presented. The figures with four independent blue graphs represent the total reward achieved on each episode. The higher the reward achieved, the better the agent performed in that episode. In MountainCar, the objective is to reach the goal in the least number of iterations possible. Thus, the reward intended must be the highest negative value possible, since the reward are always negative for this environment. The optimal solution is for the rewards to tend to 0 over time. In CartPole, the objective is a bit different since the goal is to balance for as many iterations as possible. The reward intended must be as high as possible, meaning the agent can balance the pole for a great number of iterations. The optimal learning system has the total reward values tending to the defined maximum number of iterations. The graphs that present four different coloured lines are the running average rewards. These graphs demonstrate a comparison of the total rewards with smoother lines regarding the learning process. They represent essential information to determine how the learning process evolves throughout the episode. This is important since the total reward graphs sometimes produce results with high reward variation, and sometimes not providing a straightforward analysis. A high reward variation means that the rewards achieved change significantly from episode to episode, providing graphs with abrupt variations. In MountainCar it is possible to represent a three-dimensional graph, named cost-to-go, demonstrating the action-value for each set of observation pairs. This demonstrates the value determined by the agent for each state. This graph is negated, meaning the red values part of the graph represents the worst values and the blue part of the graph the best values. To end the algorithm, the user may choose to visualise the demonstration episodes using the learned policy 𝜋, to observe what the agent can perform. 5.1.1 MountainCar For every simulation, it was possible to conceive three different graphs: a) the total reward for each episode that indicates how good each episode was; b) the reward running average that specifies how the learning evolution is proceeding over time; c) the cost-to-go function, that is the value of each action-value in a three-dimension graph. Since MountainCar only has two input variables, namely, the cart’s speed and position, it is possible to arrange a three-dimensional graph concerning the value function for both Deep Reinforcement Learning for Robot Navigation Systems 82 observations. For every simulation, a constant number of episodes is performed, in this case, a thousand episodes are performed, and the learning process throughout the episodes is compared. The approximate simulation time is also considered for this study. I Discount Factor The discount factor is the hyperparameter that determines the importance of future rewards. For MountainCar, four different discount factors are presented and compared. The values for the different discount factors are as follows: 𝛾1=0.95,𝛾2=0.97,𝛾3=0.99,𝛾4=0.999 (5.1) All the presented discount factors have the same set of other hyperparameters configurations, 𝜀3= 0.1×0.97𝑛. The graphs on Figure 5.2, compares the total reward on each episode for all the tested discount factors values (5.1) as well as in Figure 5.3 the average running reward of the last hundred episodes, to conclude the evolution of each discount factor. (a) (b) (c) (d) Figure 5.2 - Q-Learning MountainCar total reward comparison between different discount factors. Both graphs show that for MountainCar when the discount factor tends to 1, the learning process is consistently more successful. The first discount factor 𝛾1 (a), is not capable of learning how to solve the problem. Initially, on the first 200 it solves some episodes but is not able to continue the learning process. 𝛾2 (b) the algorithm is still not able to solve the problem. However, it manages to solve more episodes Deep Reinforcement Learning for Robot Navigation Systems 83 than 𝛾1. 𝛾3 (c) the evolution of the discount factor continues, and the algorithm already finishes the 1000 episodes having solved the problem but with a suboptimal policy. 𝛾4 (d) solves the problem very successfully with an optimal policy and a robust learning process. It manages to maintain an average reward over −150 throughout the 1000 episodes. In Figure 5.4, it is presented the cost-to-go function for the four selected discount factors. These graphs compare the value the algorithm has defined for the state-space observation. This type of graphs gives a visual idea of how the policy interacts with the environment and how good or bad the algorithm thinks it is to be in a specific observation. Figure 5.3 - Q-Learning MountainCar running average reward comparison between different discount factors. (a) (b) (c) (d) Figure 5.4 - Q-Learning MountainCar cost-to-go functions comparison between different discount factors. Deep Reinforcement Learning for Robot Navigation Systems 90 happens, contrary to the MountainCar results because the inverted pendulum is a highly unstable environment and just one exploration action may move the agent to a state where it is tough to come back to an equilibrium position, if not impossible. 𝜀2 (b) takes more time to reach an optimal policy than 𝜀3 (c). Whereas, 𝜀3 (c) and 𝜀4 (d) present very similar results. The difference between 𝜀2 (b), 𝜀3 (c) and 𝜀4 (d) lays on many episodes it takes the agent to discover an optimal policy. In Figure 5.14, the average rewards of all the tested exploration methods show that for CartPole, it is necessary a decreasing 𝜀greedy, preferably with a medium amount of exploration in the first hundred episodes. (a) (b) (c) (d) Figure 5.13 - Q-Learning CartPole total reward comparison between different 𝜺-greedy functions. Figure 5.14 - Q-Learning CartPole running average reward comparison between different 𝜺-greedy functions. Deep Reinforcement Learning for Robot Navigation Systems 91 III Different Reward Configuration The Gym Environments provide a standard reward function. For CartPole the environment returns a +1 reward for each time step the agent can equilibrate the pendulum. However, these can be adjusted to fit the algorithm’s learning process better. An example of an adaption is to reward negatively when the pole falls. In this test, a −10 reward is applied whenever the pole drops. This process creates a more significant value difference between the actions that led to the pole falling and the actions that were balancing the pole. This process forces the Q-Learning algorithm to learn faster. The defined hyperparameters are 𝜀=0.1×0.99𝑛, and 𝛾 = 0.99 as demonstrated in Figure 5.15 and Figure 5.16, the solution with the adapted reward function learns an optimal policy quicker. (a) (b) Figure 5.15 - Q-Learning CartPole total reward comparison between standard and adapted reward functions. Figure 5.16 - Q-Learning CartPole running average reward comparison between standard and adapted reward functions. IV Long-Term Simulation The time for an average simulation with all the previous parameters is approximately between 23 minutes and 38 minutes. Contrary to MountainCar, where the episodes tend to be shorter as the agent is learning, in Cartpole the whole purpose is for the cart to balance the pole as long as possible. Thus the simulation time for Cartpole increases as the learning process starts to get better. For a long time simulation of Deep Reinforcement Learning for Robot Navigation Systems 92 10 000 episodes, the algorithm took about 12 hours and 50 minutes to conclude. The configured hyperparameters are as follows, 𝛾=0.99, 𝜀=0.1×0.99𝑛 and the adapted reward function. This long-term simulation Figure 5.17, demonstrates that even though there were moments where the algorithm chose non optimal actions, it always managed to return to an optimal policy reaching the 2000 rewards consistently. Figure 5.17 - Q-Learning CartPole total and running average reward long-term simulation. The 2000 reward limit was defined as the maximum possible reward, and the episode terminates when reached. This limit had to be defined since the pole would discover policies that managed to balance the pole for hundreds of thousands of episodes. 5.2 Bot’n Roll ONE A In this chapter, two different Q-Learning methods are described that were implemented and tested on a simulated Bot’n Roll ONE A. The goal is to solve three mazes with increasing complexity. The agent must go through the first maze for a specific number of episodes. Then, its learning is transferred to an agent that will try to solve the second maze. This learning process will be performed for the three mazes. However, this implementation has distinctions from the two different Q-Learning implementations made on both MountainCar and CartPole. In the Gym environments, the state-space was continuous, where for the simulated agent, the state-space is discrete, due to the physical restrictions of the robot. The objective of this chapter is to implement Q-Learning in the simulated robot while using only sensors embedded in the physical robot. Some changes are necessary for the Q-Learning algorithm to be adapted to this problem, such as a different feature approximation method. The two distinct Q-Learning methods were designed for an extensive task comparison and analysis. The different behaviour of both implementations serves the purpose of reasoning the best method. The Deep Reinforcement Learning for Robot Navigation Systems 93 difference between the two lays on when 𝑄(𝑠𝑡,𝑎𝑡) is calculated, depending on the state transitions and actions executed. The implementations will be named Q-Learning method A and Q-Learning method B for a more straightforward explanation and a more natural understanding. 5.2.1 Reinforcement Learning Components The reinforcement learning components introduced by the Q-Learning implementation differ from the components implemented using other algorithms for this specific environment. As so, in the following sections, a description of the different components regarding the two Q-Learning implementations is presented. I State-Space The observation is the sensory information resulting from the robot’s environment observation. As previously described, the robot must only use its two infra-red distance sensors to detect the surrounding obstacles to define the current state. The infra-red distance sensors embedded on the Bot’n Roll ONE A are discrete, resulting in two binary sensor information. The number of state-spaces in this case study is four. In Figure 5.18 (a) are represented the robot’s four possible states. The detection volume is conically shaped with a 20 𝑐𝑚 range and a 20° angle parameters. II Action-Space An action 𝑎 is generated in the control script and sent to the simulation environment ROS node, which in turn is applied to the agent. It represents a choice of a pre-determined set of possible actions. The complete pre-determined set of actions consists of three forward, three backward, three right turns, and three left turns all with different speeds. Additionally, two self-rotation movements, one for each side. A total of 14 different possible actions are available for the agent, visually described in Figure 5.18 (b), where colour and size represent motion intensity. (a) (b) Figure 5.18 - Simulated agent state-space (a), and action-space (b). Deep Reinforcement Learning for Robot Navigation Systems 94 III Policy Q-Learning uses a state-action function 𝑄, which is updated when an action 𝑎𝑡 is taken at time step 𝑡, thus when all 𝑄(𝑠𝑡,𝑎𝑡) are maximised, the optimal policy is to select the actions with a maximum stateaction function, 𝑚𝑎𝑥𝑎𝑄(𝑠𝑡,𝑎). IV Approximation Method Since both the action-space and the state-space are discrete, it is over processing to create an approximation method, when the values are already discrete. The number of possible actions and possible states is considerably reduced and allow the implementation of solutions that do not overcomplicate. Thus, in this implementation, the tabular method was selected as a simple solution. The tabular method consists on the creation of a bidimensional array with the number of possible actions by the number of possible states. Each position is consequently an action-value condition. This method allows a straightforward use of the action-value function and its elements at all times. V Reward Equations The reward function is denoted as 𝑅, that represents the reward obtained for each action 𝑎, at time step 𝑡. The following function characterises the reward system: 𝑅𝑖= { −1,𝑝𝑒𝑟 𝑡𝑖𝑚𝑒𝑠𝑡𝑒𝑝 −103𝛿𝑢(𝑖−1),𝑝𝑒𝑟 𝑡𝑖𝑚𝑒𝑜𝑢𝑡 −103(40𝑖−1),𝑝𝑒𝑟 𝑐𝑜𝑙𝑙𝑖𝑠𝑖𝑜𝑛 103(50𝑖−1),𝑝𝑒𝑟 𝑠𝑢𝑐𝑐𝑒𝑠𝑠 (5.5) Where 𝑖 is a discrete variable from one to three that represents the maze level. The low negative time step reward forces the agent to try to reach success as fast as possible to maximise the reward. For the timeout, so the agent does not get stuck in an episode, 𝛿𝑢 stands for a unitary delta impulse function that can be represented as: 𝛿𝑢(𝑡−𝑇)={1,𝑡−𝑇=0 0,𝑡−𝑇≠0 (5.6) It results in a negative reward only on the first level. This reward prevents the robot from getting stuck in a state or set of states, performing the same actions and never leaving the same spot or never being able to reach a terminal state. It is only used in the first level since it is essential to the initial learning and not so much in the later levels. The success and collision functions were calculated for an optimised robot’s performance. The exponential increase characteristic is a crucial feature to solve the iterative complexity problem. Higher rewards for higher levels allow a coherent knowledge to solve all the different mazes.. Deep Reinforcement Learning for Robot Navigation Systems 95 5.2.2 Method A: New Action Every Time Step On Q-Learning method A, the control script reads the sensor information, calculates the respective 𝑄(𝑠𝑡,𝑎𝑡) and sends the updated action to the simulator’s ROS node. This occurs at a fixed ∆𝑡, which means the robot will go through a constant number of iterations per second. For every ∆𝑡, an action is calculated and selected via the exploration strategy, in this case, 𝜀-greedy, and sent to the agent. This method allows the agent to experiment with different actions, even though there is no state change. In this method, a total of a hundred episodes were performed for the first and second level mazes. The 100 episodes performed for each maze turned out to be insufficient for the agent to learn an optimal policy successfully. In Figure 5.19, the results in the form of rewards for this method are presented. The graphs only show the first and second levels together, since this method could not successfully solve the second maze. The orange line represents the total reward for each episode, and the blue line represents the average running reward. As seen, the robot barely solves the first maze, assuming a much more basic strategy than the one displayed in method B. The average reward line demonstrates a sub-optimal policy compared to the one in method B. In Figure 5.19 are presented the total reward for each episode and the running average rewards for the last fifty episodes. These represent the reward evolution, which allows an understanding of the robot’s level of successfulness. In Figure 5.20 are plotted the most noticeable changes made on 𝑄 on each episode. Showing how the highest action-value is adjusted for each episode, granting an understanding of how the intelligence system is evolving. Lastly, in Figure 5.21, the number of collisions denoted by the red line, the number of timeouts denoted by the blue line and the number of successes denoted by the green line are displayed. This allows a visual reference of how many collisions, timeouts and successes the agent faces along the learning process. On Table 5.1 the hyperparameter transition table is presented for the different levels. These values were adjusted for optimised learning. (a) (b) Figure 5.19 - Q-Learning Bot’n Roll ONE A, method A total and average rewards for the first two levels. Deep Reinforcement Learning for Robot Navigation Systems 96 (a) (b) Figure 5.20 - Q- Learning Bot’n Roll ONE A, method A biggest change on the action-state function 𝑸. Figure 5.21 - Q-Learning Bot’n Roll ONE A, method A successes, collisions and timeouts. Table 5.1 - Hyperparameter configuration for Q-Learning method A. Hyperparameters Level 1 Level 2 Level 3 𝛼 (learning rate) 0.1 0.01 0.0001 𝑟𝑐 (collision reward) -1000 -4000 -1600000 𝑟𝑠 (success reward) +1000 +5000 +2500000 𝑟𝑡 (timeout reward) -1000 0 0 Timeout counter 1000 4000 6000 𝜀𝑖𝑛𝑖 (initial 𝜀 -greedy) 0.05 0.01 0.01 Deep Reinforcement Learning for Robot Navigation Systems 97 5.2.3 Method B: New Action Whenever the Observation Changes The second implementation, Q-Learning method B, has the same ∆𝑡 characteristic, meaning it will read the sensor value and calculate 𝑄(𝑠𝑡,𝑎𝑡) the same number of times per second. However, it differs from the previous method since it only chooses a new action when a state change occurs. The agent will keep performing the received action 𝑎 and calculating the action-value function 𝑄 until a state transition occurs. Only when the sensor data differs, a new action is calculated, meaning an action will only go through the 𝜀-greedy method whenever the state differs. In its essence, this can be interpreted as using options as introduced in [58]. The main difference between the two methods happens when the agent remains in the same state for a significant amount of time. Method A can alter the action the agent is performing every iteration if so the 𝑄(𝑠𝑡,𝑎𝑡) and the exploration strategy select. Also, method B must remain with the chosen action until a state change occurs. The graphs for this method are presented in Figure 5.23 and Figure 5.24. The labels and indices are equal to the ones presented on method A. The total and average reward in Figure 5.22, the most significant changes in 𝑄 in Figure 5.23, and the number of different occurrences in Figure 5.24. For this method, the same number of a 100 episodes per level were performed for all three mazes. This value revealed to be enough for the agent to learn the specified task successfully. As presented, the simulated robot successfully learns the three mazes. However, when transferring to the following level, the robot needs to adapt to the different environment by adjusting its 𝑄 values. In Figure 5.22, the blue line demonstrates that the agent is successfully learning a strategy in order to solve the maze. In Table 5.2, the hyperparameter transition table between levels is presented. These values had to be adjusted for optimised learning. (a) (b) (c) Figure 5.22 - Q-Learning Bot’n Roll ONE A, method B total, and running average rewards. Deep Reinforcement Learning for Robot Navigation Systems 98 (a) (b) (c) Figure 5.23 - Q-Learning Bot’n Roll ONE A, method B biggest change on the action-state function 𝑸. Figure 5.24 - Q-Learning Bot’n Roll ONE A, method B successes, collisions and timeouts. Table 5.2 - Hyperparameter configuration for Q-Learning method B. Hyperparameters Level 1 Level 2 Level 3 𝛼 (learning rate) 0.008 0.001 0.0001 𝑟𝑐 (collision reward) -1000 -4000 -1600000 𝑟𝑠 (success reward) +1000 +5000 +2500000 𝑟𝑡 (timeout reward) -1000 0 0 Timeout counter 1000 4000 6000 𝜀𝑖𝑛𝑖 (initial 𝜀 -greedy) 0.05 0.01 0.01 The value evolution of each action is another essential parameter. Tracking this information allows an action-space as well as action transition, proper understanding. Figure 5.25 presents the different actions Deep Reinforcement Learning for Robot Navigation Systems 99 by colour, and the different action-value evolutions are plotted throughout 100 episodes on the same state. This extract is the method’s B “Right Obstacle” state from the second level maze. For a “Right Obstacle” state, the agent’s natural response should be to turn left, however in this case, not always the agent had that perception. Due to exploration resulting from the 𝜀-greedy exploration method, the agent finds a better solution. In this case, “Front Medium” represented as the black line, has a higher value than the “Left Strong” action, represented as the blue line, around episode 18. This solution caused the action-value to change its maximum action for this state. With time, the agent realises that the “Front Medium” action, which previously was considered to be a great answer, was probably a lucky action, and starts to decrease its trust on “Front Medium”, eventually falling to a sub-optimal action. However, due to another exploration, that action managed to surpass again the now optimal action which then slowly again eventually fades, and the agent manages to continuously increase its trust on the “Left Strong” action. This trust continues to rise until the end of the training. Figure 5.25 - Action evolution for method B, “Right Obstacle” state from the second level maze. Another essential parameter studied is navigation evolution. In Figure 5.26, a visual representation of the navigation evolution is presented for this method. The colours red, orange, yellow and green correspond to the episode’s number for each maze as described in the figure’s label. These navigation details show the robot’s navigation evolution throughout the reinforcement learning process. As demonstrated, the robot manages to adjust its parameters for each maze to increase its success rate as well as the amount of maze completed. For the first maze, the robot is able to learn two different successful policies to reach the endpoint. For the second and third maze, the robot manages to successfully improve its performance by making minor adjustments to 𝑄. Overall, the robot acomplishes a strategy to either go further in the maze or find new policies to solve the navigation and obstacle avoidance problem. Deep Reinforcement Learning for Robot Navigation Systems 106 Figure 6.2 - Policy Gradient MountainCar running average reward comparison between different learning rates. II Discount Factor The discount factor 𝛾 determines the importance of future rewards. A comparison of four different discount factors in this environment with a learning rate 𝛼=0.01 and 𝑛=10 is presented. The compared discount factors are: 𝛾1=0.97,𝛾2=0.99,𝛾3=0.995,𝛾4=0.999 (6.2) In Figure 6.3 for 𝛾1 or lower values (a), the algorithm is not capable of learning the task at hand. The low value compared to the others tested means that 𝛾1 (a) gives higher importance to reaching as soon as possible to the goal rather than the future values that may take the agent to the goal. The difference between 𝛾1 and the closest tested value 𝛾2 (b) is only of 0.02. However, this difference makes a significant change in the learning process. From 𝛾2 on, (c) and (d), the agent successfully learns how to solve the MountainCar problem, with just some minor differences regarding reward variation, plotted in Figure 6.4. (a) (b) (c) (d) Figure 6.3 - Policy Gradient MountainCar total reward comparison between different discount factors. Deep Reinforcement Learning for Robot Navigation Systems 107 Figure 6.4 - Policy Gradient MountainCar running average reward comparison between different discount factors. III Number of Artificial Neurons A different hyperparameter introduced by the Policy Gradient algorithm is the different number of neurons in the neural networks. The policy network has a single hidden layer as part of its architecture, and differences in the number of units in the hidden layer are compared. The increase of neurons of an ANN network increases computational-costing, thus requiring higher processing units or more time to do the forward and backpropagation. The other hyperparameter values are 𝛼=0.01 and 𝛾=0.999. The different number of neurons tested are as follows: 𝑛1=5,𝑛2=10,𝑛3=20,𝑛4=40 (6.3) Similar to the other hyperparameters, Figure 6.5 demonstrates the plots of the total reward of each episode for a different number of hidden layer neurons, and Figure 6.6 the running average of the rewards throughout the episodes. A higher number of neurons such as 𝑛4 (d) increases significantly the model complexity. When working with small action-spaces and state-spaces, these solutions tend to overcomplicate the problem, thus not being able to solve it. For implementations with a higher number of neurons, like 𝑛4 (d) and even 𝑛3 (c), it is demonstrated that the learning is not as smooth as a lower number of neurons like 𝑛2 (b) and 𝑛1 (a). For 𝑛1, 𝑛3 and 𝑛4 around episode 600, they all try to adjust the optimal policy, even though this results in a learning deterioration. However, the three solutions are able to work around this and with a different number of episodes returning to a policy that solves the task. The two largest number of neurons, 𝑛3 and 𝑛4, increased the initial learning considerably, as displayed in the average reward graphs in Figure 6.6. The difference between the four different configurations and their efficiency may result as a part of the chosen learning rate and the discount factors. Deep Reinforcement Learning for Robot Navigation Systems 108 (a) (b) (c) (d) Figure 6.5 - Policy Gradient MountainCar total reward comparison between different number of neurons. Figure 6.6 - Policy Gradient MountainCar running average reward comparison between different number of neurons. IV Long-Term Simulation The long-term simulation was set with the following hyperparameters: 𝛼=0.01,𝛾=0.999,𝑛=10 (6.4) In Figure 6.7, the total and running average are plotted. The algorithm successfully learns to perform actions to solve the problem. It is shown that this method explores different policies throughout the learning process and successfully adapts when these results in suboptimal policies. This long-term simulation took around 33 minutes to run, whereas the short-term simulations took approximately 5 Deep Reinforcement Learning for Robot Navigation Systems 109 minutes. The consistency of the average regarding the last 7000 episodes demonstrates the robustness provided by this learning method. Figure 6.7 - Policy Gradient MountainCar total and running average reward long-term simulation. 6.1.2 CartPole For the Cartpole environment, the same two graphs are presented, the total reward for each episode and the average reward for the previous hundred episodes. The main differences regarding the MountainCar environment are the high instability of the inverted pendulum problem and the time necessary to perform the simulations. Cartpole is an unstable environment, as every action has a great significance to the success or not of the episode. As discussed, along this subchapter, it is essential to have a good hyperparameter configuration. Unlike MountainCar, the parameter configurations that can make successful learning are significantly lower. In order to study the hyperparameters, a thousand episodes are performed, the rewards are compared, and the completion times are defined. A maximum amount of time steps is set at 2000 similar to the Q-Learning implementation. Since the agent after successfully learning the task would have results much higher than the stipulated maximum to avoid wasting unnecessary time. I Learning Rate The developed tests were made with the same configurations for all the different hyperparameters, 𝛾= 0.99 and 𝑛=10. The learning rates are the following: 𝛼1=0.02,𝛼2=0.01,𝛼3=0.005,𝛼4=0.002 (6.5) In Figure 6.8, the four plots respective to the tested learning rates are presented. 𝛼1 (a) learns the task successfully after 1000 episodes but through its learning process it tries significantly different policies which result in bad rewards, even though this learning rate can recover its learning, it takes a considerable Deep Reinforcement Learning for Robot Navigation Systems 110 number of episodes compared to 𝛼2 (b). When testing learning rates lower than 𝛼2 it is possible to determine that these need more episodes to reach the maximum reward, slowing the learning process. 𝛼3 (c) and 𝛼4 (d) solutions also demonstrate a higher instability due to the nature of the control problem, that consequently results in graphs with higher reward variation. (a) (b) (c) (d) Figure 6.8 - Policy Gradient CartPole total reward comparison between different learning rates. In Figure 6.9, it is possible to see the learning evolution without the high variation shown in the total reward graphs. Figure 6.9 - Policy Gradient CartPole running average reward comparison between different learning rates. Deep Reinforcement Learning for Robot Navigation Systems 111 II Discount Factors Four different discount factors are introduced with a constant number of artificial neurons 𝑛=10 and a learning rate of 𝛼=0.01. The tested discount factors are: 𝛾1=0.97,𝛾2=0.99,𝛾3=0.995,𝛾4=0.999 (6.6) Figure 6.10 demonstrates the different rewards in each episode for each discount factor. The three first discount factors 𝛾1 (a), 𝛾2 (b) and 𝛾3 (c) have learned an optimal policy throughout 1000 episodes. Of the three, 𝛾2 is the discount factor that has the most stable initial learning, from the first episode to the first time it is able to perform a 2000 reward for a couple of straight times. (a) (b) (c) (d) Figure 6.10 - Policy Gradient CartPole total reward comparison between different discount factors. At approximately episode 300, this can be easier visualised in Figure 6.11. 𝛾3 introduces a solution with higher reward variation and with the discount factor increase, the learning process tends to be more unstable. 𝛾4 (d) introduces a highly unstable solution that even loses its optimal policy and is unable to have a successful learning process at the end of the 1000 episodes. Deep Reinforcement Learning for Robot Navigation Systems 112 Figure 6.11 - Policy Gradient CartPole running average reward comparison between different discount factors. III Number of Artificial Neurons As stated in 6.1.1III, the Monte Carlo strategy used has an artificial neural network. It has a hidden layer and the number of artificial neurons in that layer is a hyperparameter. The compared number of hidden layer neurons are the following: 𝑛1=5,𝑛2=10,𝑛3=20,𝑛4=40 (6.7) In Figure 6.12 and Figure 6.13, the respective total episode reward and the running average are plotted. In this implementation, the increase in the number of neurons can be linked to the number of episodes necessary to reach a 2000 policy. From 𝑛1, to 𝑛4 the time necessary to reach the maximum reward for a couple of times decreases. Meaning that 𝑛4 (d) is the solution that takes the smaller number of episodes. However when considering stability, 𝑛4 has a considerable amount of episodes where the reward achieved shows that the experiments made translate into not so successful attempts. 𝑛3 (c) is the most stable solution even though it takes approximately more 150 episodes to achieve its first straight maximum reward possible. 𝑛2 (b) is a slower and more unstable solution than 𝑛3. 𝑛1 (a) is clearly an oversimplified solution, as seen in the number of iterations necessary to reach the 2000 reward consistently. 𝑛1 is outperformed by the solutions with higher number of artificial neurons since it is significantly surpassed, both in stability and time necessary until it reaches an optimal policy. All the solutions can provide an optimal policy after 1000 episodes. As also previously stated, these results are known to be connected to the selected learning rate and discount factor, different values on these hyperparameters would result in different learning processes. Deep Reinforcement Learning for Robot Navigation Systems 113 (a) (b) (c) (d) Figure 6.12 - Policy Gradient CartPole total reward comparison between different number of neurons. Figure 6.13 - Policy Gradient CartPole running average reward comparison between different number of neurons. IV Long-Term Simulation The long-term simulation was performed using the following hyperparameters: 𝛼=0.01,𝛾=0.99,𝑛=20 (6.8) The long-term simulation for CartPole using the Monte Carlo method is not as straightforward as the previous long-term simulations. Due to the instability of the inverted pendulum control problem, the longterm simulations are not always able to reach the 10 000 episode mark while having learned an optimal policy. In Figure 6.14 is an example of a non-successful long-term simulation. Even though it seems that Deep Reinforcement Learning for Robot Navigation Systems 114 it has learned an optimal policy from episode 2800 to episode 8000, it fails the learning process. The non-linear function approximator used, ANNs can sometimes create unstable learning systems. This downfall, linked with the fact that just a minor change on the policy can make the inverted pendulum stop balancing, demonstrates that not always the learning process can be successful even using the same hyperparameters. The time to perform the long-term simulation was approximately 7 hours, whereas the short-term took around 30 minutes. Figure 6.14 - Policy Gradient CartPole total and running average reward long-term simulation. 6.2 Bot’n Roll ONE A In this chapter, a Policy Gradient Monte Carlo method is applied and tested on a simulated Bot’n Roll ONE A. The goal similar to the previous chapter, is to solve three mazes with increasing complexity. The agent must surpass each level by undergoing a fixed number of episodes on each maze. After completing a maze, the agent will be positioned on the following level, and so on until it solves the third maze. The implementation on the Bot’n Roll ONE A and the respective environment is equal to the one presented on previous subchapters. The method consists of a neural network as the policy model and uses Monte Carlo methods to update the policy model at the end of each episode. However, the simulated version introduces a change in the obstacle sensors. Instead of a dual discrete solution, in this implementation, a solution with five continuous sensors is presented. 6.2.1 Reinforcement Learning Components A precise reinforcement learning components definition is an essential introductory task to understand the algorithm’s performance. In the following sections, a description of the different RL components regarding the implemented PG method is presented. Deep Reinforcement Learning for Robot Navigation Systems 115 I State-Space The information returned by the agent’s sensors defines the state-space. Contrary to the state-space defined in 5.2.1I, in this chapter, the distance sensors physical restrictions are abandoned in favour of a more complex and realistic high-level obstacle avoidance framework. The robot sensors now consist of five Time-of-Flight (ToF) beams pointed to five different directions, such as a) left, b) 45° between left and front, c) front, d) 45° between the front and right, and e) right. These beams are displayed in Figure 6.15. Therefore, the number of state spaces is five, and each one is a continuous value between 0 and 1, representing no obstacle, and an obstacle right next to the robot, respectively. The detection volume is a laser with a 1 𝑚 range. Figure 6.15 - Simulated agent adapted action-space with five simulated ToF distance sensors. II Action-Space The action-space is equal to the one presented in the previous chapter. Since this Monte Carlo policy gradient method still cannot handle continuous actions, a predefined set of discrete actions described in Figure 5.18 were created to fit the algorithm restrictions. The algorithm can choose from a range of fourteen possible actions. The action 𝑎 after being calculated in the control script is sent to the simulator via the ROS node. III Policy This algorithm has a stochastic policy 𝜋(𝑎|𝑠,𝜃) that outputs the probability of an action being selected. Its model is an artificial neural network whose outputs are activated via a softmax function that introduces the action’s probabilities. The number of output neurons is the number of actions, where the value of Deep Reinforcement Learning for Robot Navigation Systems 122 over actions, and selects an action according to this distribution, whereas a deterministic policy always returns the same action with the highest expected 𝑄-value. In the next chapter, a policy gradient method with a deterministic target policy named Deep Deterministic Policy Gradient will be analysed and detailed. Deep Reinforcement Learning for Robot Navigation Systems 123 7 Deep Deterministic Policy Gradient Deep Deterministic Policy Gradient is a Policy Gradient algorithm that uses a stochastic behaviour policy for an improved exploration but estimates a deterministic target policy, which is considerably easier to learn. Since DDPG is off-policy and makes use of a deterministic target policy, this permits the use of the Deterministic Policy Gradient theorem. DDPG is an actor-critic algorithm that is primarily composed of two artificial neural networks, one for the actor and one for the critic. The networks calculate action predictions for the current state and generate a temporal difference error signal at each time step. The input of the actor-network is the current state, and the output is an array of float values representing an action chosen from a continuous action-space. The critic’s output is the estimated 𝑄-value of the current state and the action given by the actor-network. The deterministic policy gradient theorem provides the weight update rules for the actor-network. The critic network is updated regarding the gradients obtained from the TD error. In this chapter, a Deep Deterministic Policy Gradient implementation on the OpenAI’s Gym environment Pendulum is presented. Different hyperparameter configurations and their impact on the learning process were analysed, tested and compared. 7.1 Implementation and Testing In the implementation made in this chapter, the Deep Deterministic Policy Gradient algorithm is branded by its actor-critic strategy. It uses two distinct ANNs, the actor-network and the critic-network. The actornetwork obtains as inputs the environment observation, the values from the three different states which are part of the environment’s state-space. It has a hidden layer of 30 artificial neurons and its output is the action-space dimension. For this example, it is just the pendulum angular velocity. The critic-network Deep Reinforcement Learning for Robot Navigation Systems 124 inputs are the current state, the action previously made, and the reward returned by the environment. This network also has 30 in its hidden layer with just one output, which is the estimated 𝑄-value of the current state and the action the agent performed. In Figure 7.1, a diagram of the implemented DDPG algorithm is presented. The Pendulum Environment is an excellent choice for implementing Deep Deterministic Policy Gradient as it provides continuous action-space. Figure 7.1 - Diagram of the implemented Actor-Critic method with the specific actor-network and critic-network. However, the application of ANNs on Deterministic Policy Gradient method behaves poorly, not being able to converge. In general, training and evaluating a policy and value function with thousands of temporallycorrelated simulated courses leads to a significant amount of variance in the approximation to the 𝑄- function. The TD error signal consolidates the variance received by wrong predictions over time. Thus, to solve the lack of convergence problem, a replay buffer is used to store the agent experiences during training and arbitrarily sample previous experiences. This strategy is called experience replay, and it was used on this implementation with batches of 32 episodes. 7.1.1 Pendulum The inverted pendulum swing-up problem is a classic literature control problem. In this environment, the algorithm receives from the simulator the pendulum’s angle, as the cosine and sine, and its instantaneous angular velocity. In order to fulfil the goal of swinging it to the upright position, a continuous angular speed must be performed by the agent. For every simulation, two different graphs are presented, the total reward Deep Reinforcement Learning for Robot Navigation Systems 125 for each episode and the running reward average. The total reward graph indicates how good each episode is. Similarly to MountainCar, the range of possible rewards are always negative, so the goal for the agent is to have rewards throughout the episodes that tend to 0. The running reward average demonstrates how the learning evolution is proceeding over time. A constant number of 1000 episodes, were performed for every hyperparameter configuration. A detailed hyperparameter configuration is presented and analysed throughout this chapter. I Actor-Network Learning Rate The Learning Rate for the Actor-Network denoted as 𝛼𝑎, is the hyperparameter responsible for the step size the artificial neural network performs. A comparison of four different 𝛼𝑎 is presented in this section. The studied learning rates are the following: 𝛼𝑎1=0.05,𝛼𝑎2=0.01,𝛼𝑎3=0.005,𝛼𝑎4=0.002 (7.1) The values used for the rest of the hyperparameters are: 𝛼𝑐=0.01,𝛾=0.95,𝜎 = 3,𝜔=0.9999. In Figure 7.2, the plots considering the total rewards for each episode for all four actor-network learning rate configurations are presented. The actor learning rate has a significant influence on the learning reward variation, as can be noted by the difference between the four graphs. 𝛼𝑎1 (a) shows a learning process with high reward variation since the pendulum has many steps with low rewards. (a) (b) (c) (d) Figure 7.2 - DDPG Pendulum total reward comparison between different actor learning rates. Deep Reinforcement Learning for Robot Navigation Systems 126 As the learning rate decreases, 𝛼𝑎2 (b) and furthermore 𝛼𝑎3 (c) it is noted that the reward variation starts to decrease. 𝛼𝑎3 presents a solution with very little reward variation regarding episodes with low rewards. However, with higher decreases such as 𝛼𝑎4 (d) the learning process starts to deteriorate in the last hundreds of episodes. Figure 7.2 and Figure 7.3 shows how the reward variation of all learning rate configurations influences medium-term learning. Figure 7.3 - DDPG Pendulum running average reward comparison between different actor learning rates. II Critic-Network Learning Rate Similarly to the previous section, the learning rate for the critic-network hyperparameter denoted as 𝛼𝑐, controls the ANNs step size. Four different critic-network learning rate configurations are presented as follows: 𝛼𝑐1=0.02,𝛼𝑐2=0.01,𝛼𝑐3=0.005,𝛼𝑐4=0.002 (7.2) The values used for the rest of the hyperparameters are: 𝛼𝑎=0.005,𝛾=0.95,𝜎 = 3,𝜔= 0.9999. The four graphs shown in Figure 7.4 demonstrate the four learning rates for critic-network adjustments. Regarding this hyperparameter, there are differences in the initial learning and the reward variation registered throughout 1000 episodes. 𝛼𝑐1 (a) and 𝛼𝑐4 (d) show an initially slow exponential learning, whereas 𝛼𝑐2 (b) and 𝛼𝑐3 (c) have a high reward on the first couple of episodes and maintain that reward over 100 episodes. Independently of this initial learning, the four learning rates have similar learning behaviours from episode 100 to 200. Regarding the learning reward variation, 𝛼𝑐2 (b) shows a more natural learning process with a higher number of solved episodes. Both the initial learning and the reward variation can be easily understood in Figure 7.5 as the reward running average. Deep Reinforcement Learning for Robot Navigation Systems 127 (a) (b) (c) (d) Figure 7.4 - DDPG Pendulum total reward comparison between different critic learning rates. Figure 7.5 - DDPG Pendulum running average reward comparison between different critic learning rates. III Discount Factor The Discount Factor 𝛾 controls the importance of future rewards versus the present ones. In this section a comparison and analyses of four different 𝛾 values are presented: 𝛾1=0.9,𝛾2=0.95,𝛾3=0.99,𝛾4=0.999 (7.3) The values used for the other hyperparameters are: 𝛼𝑎=0.005,𝛼𝑐=0.01,𝜎=3,𝜔 = 0.9999. Figure 7.6 shows an interesting different learning configuration. 𝛾4 (d) is the discount factor that demonstrates the highest reward variation. In contrast from 𝛾1 (a) to 𝛾3 (c) it is noticeable that the reward variation on the learning process is transferred from the second half of the learning to the first half of the Deep Reinforcement Learning for Robot Navigation Systems 128 learning. In 𝛾1 the biggest part of the reward variation only starts appearing on episode 600. In 𝛾2 (b) the reward variation starts appearing a bit sooner, approximately on episode 400. For 𝛾3 the learning process changes and only has a high reward variation on the first 500 episodes. This demonstrates that many times, the hyperparameters introduce certain details on the learning process essential for the success of the agent. In Figure 7.7 the differences on the reward variations appearances can be observed, where for 𝛾1 the average drops on the last half of the episodes run, 𝛾2 drops approximately at episode 400 and 𝛾3 average rises on the second part of the thousand episodes. (a) (b) (c) (d) Figure 7.6 - DDPG Pendulum total reward comparison between different discount factors. Figure 7.7 - DDPG Pendulum running average reward comparison between different discount factors. Deep Reinforcement Learning for Robot Navigation Systems 129 IV Exploration Noise The exploration method for continuous action-spaces is different from the discrete action-spaces. Instead of performing a different action for exploration, the algorithm introduces a noise function to the selected continuous action. In this implementation, a Gaussian distribution is implemented to provide the exploration as noise for the action. Similarly to the exploration methods introduced on discrete actionspaces, the exploration methods decrease over the number of episodes, using decay rates. A Gaussian distribution is defined by its mean, that is the algorithm’s selected action, and the deviation. Four different simulations were performed using two different deviations 𝜎, and two different decay rates 𝜔: 𝜎1=3, 𝜎2=3, 𝜎3=5, 𝜎4=5 (7.4) 𝜔1=0.9995, 𝜔2=0.9999, 𝜔3=0.9995, 𝜔4=0.9999 (7.5) The values used for the other hyperparameters are: 𝛼𝑎=0.005,𝛼𝑐=0.01,𝛾=0.99. By analysing both Figure 7.8 and Figure 7.9 with the two different deviations and decay rates, it is possible to stand out the differences between the two hyperparameters. For the two different deviations with the same decay rates, it is possible to point out that 𝜎1 (a) and (b) allows a learning with less reward variation since the exploration is also minor, while 𝜎3 (c) and (d) has higher reward variation. (a) (b) (c) (d) Figure 7.8 - DDPG Pendulum total reward comparison between different exploration noises. Deep Reinforcement Learning for Robot Navigation Systems 130 This was expected to occur and it is due to the higher exploration that ultimately results in a longer exploration. The higher decay rate 𝜔2 (b) and (d) shows that the end of both simulations have less variance on the rewards than the lower 𝜔1 (a) and (c). Even though the exploration takes more episodes, it is made in an improved way that outperforms lower deviations. Figure 7.9 - DDPG Pendulum running average reward comparison between different exploration noises. V Long-Term Simulation The long-term simulation demonstrates how an optimal set of hyperparameters for short term simulations performs throughout 10 000 episodes. The long-term simulation serves to prove the long-term efficiency of the selected algorithm as well as the configured hyperparameters. The hyperparameters were selected considering the study previously demonstrated and are as follows: 𝛼𝑎=0.01,𝛼𝑐=0.002,𝛾=0.005,𝜎=3,𝜔=0.9999 (7.6) Figure 7.10 shows the reward of each episode and the average running reward. This specific simulation demonstrates that the algorithm learned the task at hand and after the last episodes still successfully solves the environment with an average reward higher than −400. However, in short-term simulations, the final average value rounds the −200. The average running rewards show that the algorithm maintains a high average until approximately episode 3500. After the first 3500 episodes, the rewards drop significantly until episode 7500, during a period where the developed policy does not perform as good as it formerly did. From episode 7500 onwards the agent solves the environment in approximately 300 iterations. For an improved result, the hyperparameters reconfiguration could create a different policy that better meets the long-term learning process. Deep Reinforcement Learning for Robot Navigation Systems 131 Figure 7.10 - DDPG Pendulum total and running average reward long-term simulation. 7.2 Conclusions In this chapter, a Deep Deterministic Policy Gradient implementation in OpenAI’s Gym environment Pendulum was accomplished. This algorithm made possible the conclusion of some essential topics regarding the advantages of using DDPG algorithms: 1. A stochastic behaviour policy associated with a deterministic target policy provides a virtuous exploration while contributing for a considerably smoother learning process. 2. The Actor-Critic algorithm aims to take advantage of both value-based and policy-based methods. The agent controls the agent’s behaviour by learning the optimal policy, while the critic evaluates the action by calculating the value function. These two models collaborate so both can get better in their role. The overall architecture can provide efficient learning. 3. The artificial neural networks presented in both actor and critic methods allow a broad approximation to large state-spaces, thus working as a robust approximation method for complex reinforcement learning environments. The non-linear approximation methods are a big step to implementing RL in robotics. 4. The continuous action-space shows better resemblances to real-world problems. In nonsimulation environments, such as the physical world, the majority of actions is not discrete, so continuous action-spaces algorithms are essential for the future of reinforcement learning applied to real-world problems. The connection between all these points is the direction to implement reinforcement learning to real-world robotics. The DDPG studies show enormous potential to be one of the top leading algorithms of this scientific subject.