SHAPING AND POLICY SEARCH FOR NEAREST-NEIGHBOUR CONTROL POLICIES WITH APPLICATIONS TO VEHICLE STEERING by KEN ALTON B . S c , The University of Calgary, 2000 A THESIS S U B M I T T E D IN P A R T I A L F U L F I L M E N T O F THE REQUIREMENTS FOR T H E DEGREE OF M A S T E R OF SCIENCE in T H E F A C U L T Y O F G R A D U A T E STUDIES (Department of Computer Science) T H E U N I V E R S I T Y O F BRITISH C O L U M B I A December, 2004 © K E N A L T O N , 2004 Abstract ii Abstract The graceful animal motion we see in nature has proven extremely difficult to reproduce algorithmically. There is a need for further research into motion control techniques to address this problem adequately for computer animation and robotics applications. In this thesis, we describe a novel method for the synthesis of compact control policies for a variety of motion control problems. Direct policy search is applied to a nearest-neighbour control policy, which uses a Voronoi cell discretization of the observable state space, as induced by a set of control nodes located in this space. Such a semi-parametric representation allows for policy refinement through the adaptive addition of nodes. Thus, a coarse-to-fine policy search can be performed in such a way that the problem is shaped for easy learning. We apply our method to developing policies for steering various vehicles around a winding track. In particular, a policy is learned to steer a double-trailer truck backwards, a problem of considerable difficulty given the instability of the trailers. We also generate policies for the problems of balancing an inverted pendulum on a moving cart and driving the state of a point mass around a user-specified limit cycle. We examine these motion control results critically and discuss the limitations of the nearest-neighbour policy representation and our policy search method. Table of Contents . iii Table of Contents Abstract Table of Contents List of Tables List of Figures . , Acknowledgements . . . 1 2 Introduction 1.1 Motivation 1.1.1 Understanding Motion Control 1.1.2 Applications of Motion Control 1.2 Goals and Scope 1.3 Assumptions 1.3.1 Reactive Control 1.3.2 Control in Simulation 1.4 Reinforcement Learning Framework 1.4.1 R L and Other Frameworks 1.4.2 Challenges in R L 1.5 Policy Search 1.6 Contributions 1.7 Thesis Outline P O M D P and Policy Search Framework 2.1 P O M D P s and Reinforcement Learning 2.1.1 Policies and State Trajectories 2.1.2 Reward and R L Problems 2.2 Value-based Methods and Limitations 2.2.1 Dynamic Programming 2.2.2 Standard Value-based Methods 2.2.3 State and Action Discretization 2.2.4 Value Function Approximation 2.2.5 Partial Observability 2.3 Policy Search 2.3.1 Previous Work 2.3.2 Policy Representation 2.3.3 Evaluation 2.3.4 Optimization 2.3.5 Shaping 2.4 Summary 11 iii v i vii i x 1 1 1 2 3 4 4 4 5 6 7 9 1 0 10 12 12 • • 14 15 15 15 16 17 17 19 19 20 22 23 24 26 30 Table of Contents 2.4.1 2.4.2 Relevance of Framework Related Work iv 30 .31 Nearest-Neighbour Control Policies 3.1 Policy Definition 3.2 Related Work 3.3 A 2D Example 3.3.1 Problem Formulation 3.3.2 Policy Evaluation 3.3.3 Policy Search 3.3.4 Results 3.4 Summary 33 33 34 35 36 37 39 40 40 Cart and Pole 4.1 Problem Overview 4.2 Related Work and Problem Variations 4.3 Problem Formulation 4.4 Policy Evaluation 4.5 Policy Search 4.6 Results 4.7 Discussion and Future Work 4.7.1 A 2-Node Policy 4.8 Interactive Extensions 41 41 42 43 44 46 48 51 52 54 Vehicle Steering 5.1 Related Work 5.2 Problem Formulation 5.2.1 Vehicle Tracks 5.2.2 Policy Representation 5.3 Policy Evaluation 5.4 Policy Search 5.5 Results 5.5.1 Backwards Driving 5.5.2 Forwards Driving 5.6 Summary and Future Work 55 57 59 61 63 65 67 70 71 79 80 Discussion 6.1 Nearest-Neighbour Policy Representation 6.2 Policy Search Method 83 83 90 Conclusion 92 A 2D Example: Time-Based Policy A . l Constructing a Time-Based Policy A. 2 Bootstrapping a Nearest-Neighbour Policy 94 94 95 Cart and Pole: Additional Information B. l Equations of Motion B.2 Perturbation Algorithm 97 97 • • • 97 Table of Contents v C Vehicle Steering: Additional Information C . l Left-Right Symmetry Proof for Steering Policy C.2 Equations of Motion C.3 Perturbation Algorithm 99 99 100 101 Bibliography 104 List of Tables vi List of Tables 4.1 Paramaters and results for cart and pole problem 49 5.1 5.2 Our vehicle steering problem versus car control for R A R S Paramaters and results for vehicle steering problems 58 82 B.l Constants used for the cart and pole perturbation algorithm. 98 List of Figures vii List of Figures 1.1 Agent observing and acting in an environment 6 2.1 2.2 2.3 Evolution of a state trajectory Comparison of a poorly-shaped and well-shaped optimization Progressive refinement using a series of optimizations 14 27 29 3.1 3.2 3.3 3.4 3.5 A n abstract diagram of a nearest-neighbour policy. Nearest-neighbour policy for 2D trajectory tracking problem Dynamics for control of a point mass in one dimension A P O M D P reward function for the trajectory tracking problem. Policy evaluation for the 2D trajectory tracking problem 34 36 37 38 39 4.1 4.2 4.3 4.4 4.5 4.6 Setup of the cart and pole problem Dynamics for the cart and pole system Policy performance during the cart-pole policy search Example state evolution for the cart and pole system Controllable states for the cart and pole system Trajectory following the Voronoi cell boundary to the goal region 43 44 48 50 51 53 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.10 5.11 5.12 5.13 5.14 5.15 5.16 5.17 5.18 5.19 5.20 5.21 5.22 Steering one and two trailer trucks backwards Jack-knifing of backwards-driving trucks Truck sensory information Steering Angle versus Simulation Time Step for vehicle steering Dynamics for the vehicle simulation A n example of a complete track for backwards truck-steering Tracks from 3 different track classes Symmetric observations of the truck policy. Distance measured along the center of the track. Initial states for truck backing-up Options for perturbing policy parameters Truck dimensions for the single-trailer truck backing problem Steering a one-trailer truck backwards Policy performance versus function evaluations for truck Driving a truck backwards in unexpected situations Driving a two-trailer truck backwards Difficult initial states for two-trailer truck Car driving backwards on an unfamiliar track Car driving backwards on two variable tracks Car driving backwards in unexpected situations Car driving forwards on a narrow track Car driving forwards on a wide track 55 56 59 60 61 62 63 64 65 67 70 71 72 73 74 75 76 77 78 78 79 79 .' List of Figures viii 5.23 Truck driving forwards on an unfamiliar track 80 6.1 6.2 6.3 6.4 6.5 Poor nearest-neighbour approximation of a linear function Poor nearest-neighbour approximation of a discrete function Chattering between the opposing actions of Voronoi cells Stretched Voronoi cells with unnormalized sensory variables Nearest-neighbour node positions for a walking trajectory 84 85 86 88 89 A.l A time-based policy approximating a desired limit cycle 95 C.l Motion of the truck during a simulation time step 101 Acknowledgements ix Acknowledgements I would like to thank Michiel van de Panne for ideas that inspired this work, valuable criticism, and enthusiasm. Michiel's thoughts and encouragement were instrumental from the beginning of this thesis through to its completion. Ian Mitchell has provided much insightful feedback about the work, for which I am grateful. His comments have been helpful in pointing out some of the weaknesses of our method and possible alternatives. This knowledge will prove valuable in extending and improving on the ideas presented in this thesis. Also, I would like to acknowledge Dana Sharon for interesting discussions about our closely related work. She has shown that a similar policy search method can be used to learn policies for planar biped walking, which I find very exciting. Finally, I am thankful for the encouragement and support of my friends and family, who all helped to restore balance to my life during the most stressful and discouraging times of this research. Particularly, I want to thank Zorana for helping me keep in mind what is important in life and my parents for their loving long-distance support. Much of this work has been supported by a N S E R C P G S - A scholarship. Chapter 1. Introduction 1 Chapter 1 Introduction How are humans and animals able to move through complex environments with seeming effortlessness? This is a problem that has received much attention in the fields of biomechanics, computer animation, and robotics, yet it remains very much unsolved. This thesis looks at learning automatic controllers for several specific motion control problems. The intention is that this research will shed light on issues in motion control and take us a step further towards algorithmically reproducing the graceful motion that is evident in humans and animals. In this introduction, we discuss compelling reasons to study motion control and present the major goals of our work. We also describe the assumptions that are made regarding the type of motion control considered in this thesis and justify these assumptions. We briefly introduce the reinforcement learning framework and discuss some of its major challenges. Next, policy search is considered as a practical approach for solving motion control problems. This is the approach that is taken in our work. Finally, we summarize the contributions of our work and present an outline of the rest of the thesis. 1.1 Motivation 1.1.1 Understanding Motion Control The movement of animals and people can seem so natural and effortless that this type of motion control is usually taken for granted. Everyday we see many such examples: a man walking his dog, a crow flying overhead and settling down on the edge of a rooftop, or a squirrel scurrying up the bark of a tree. When we see that squirrel perform some fearless acrobatic routine across the branches of the tree, we may pause and wonder at its incredible agility. However, few casual observers actually attempt to understand how such graceful animal motion is produced. Researchers in the field of biomechanics are an exception. They study, among other things, the neuro-muscular activity that produces animal motion. Also, researchers in computer animation and robotics may investigate the biomechanics of animal motion for the purpose of reproducing it. Alternatively, one can attempt to synthesize animal-like motion without necessarily understanding all the details of the neuro-muscular systems that produce this motion in nature. Computer animators Chapter 1. Introduction and robotics engineers are mostly concerned with results. 2 If satisfactory motion results can be obtained with a simplified model then why complicate it with physiological details? For example, in this thesis we synthesize steering controllers for various vehicles in simulation. We would like the motion of the vehicles to appear as if they are driven by a person, even though that person is not visible in the results. However, we do not attempt to model the biomechanics of the driver in order to produce realistic steering motions. Of course, in this case, the subtleties of the human motion are hidden. If the goal is to synthesize a specific animal motion, like canine walking, it becomes more compelling to model the biomechanics in order to capture all the nuances. We shall use the term motion control to mean the control of a physical system, simulated or real, to produce a desired type of motion. Since we are more concerned with understanding principles of general motion control rather than the details of a particular biological implementation, we synthesize motion using an abstract control representation. In this way, we hope to gain insight into general motion control, which could be applied to reproducing animal motions for animation or robotics or to synthesizing entirely new types of motion. 1.1.2 Applications of M o t i o n Control Motion control is currently applied extensively in robotics. For industrial processes, robot arms and manipulators are common, and their movement must be controlled in a safe and purposeful manner. Also, a great deal of research has gone into the engineering of mobile robots. Many of the most difficult control problems in robotics involve imitating human and animal motion. State of the art humanoid robots are capable of walking, but in a manner that is, at present, clumsy in comparison to humans. A better understanding of motion control is imperative in creating robots that move in a more graceful and robust fashion. This is true whether we are trying to reproduce human or animal motion in a robot or designing entirely new ways for robots to move and manipulate their environments. In a similar vein, human prosthetics are also a sensible application for motion control. The human body is an incredibly tuned motion control system. Artificial replacement parts should be carefully designed using both biomechanics and principles of general motion control. Prosthetics should integrate as seamlessly as possible with the body in both physical appearance and motion properties. In computer animation, motion control has much potential. Initially, the motion of characters was designed entirely by human animators. Recently, motion capture techniques have allowed the motion of real human actors to be recorded and transferred to animated characters. Once the data acquired by motion capture is available, it can be used to quickly produce realistic animations. However, Chapter 1. 3 Introduction producing the variety of motion seen in the real world requires an enormous amount of data, the acquisition of which is expensive and time-consuming. Also, motion captured from a particular actor cannot easily be applied to a character of different proportions or morphology. Most importantly, current motion capture methods cannot be used to animate the complex and often unpredictable interaction of a character with elements of its environment. A promising alternative is to use motion control of a virtual character with a physical simulation of its body and environment. The physical simulation of fluids and rigid bodies for animation has been very successful. However, moving a character with the agility of a human or with the grace and style of a hand-animated character requires great improvement in the motion control techniques available. 1.2 Goals and Scope The long-term goal of our research is to form a better understanding of general motion control through the development of a principled methodology for synthesizing motion controllers. Such a methodology could provide great benefit in application areas such as animation and robotics. Toward this end, this work focuses on automatically learning reactive controllers for a limited class of problems in simulation, including the classical cart and pole problem and the steering of cars and trucks. Of course, motion control is simply a type of control, which includes other types, such as the control of chemical processes. Our work focuses on motion control, although the benefits of the knowledge obtained may naturally carry over into other areas. The representation of a motion controller is important and we want to gain insight into desirable properties and key trade-offs in the choice of representation. In this work, we test and evaluate a particular representation, the nearest-neighbour control policy, to help accomplish this. Also, guiding or shaping of the learning process has always been an important aspect in the training of a human or animal to perform a task. For example, when an athlete learns to perform a difficult physical manoeuvre, he typically learns in stages of refinement. First, the crude motion is learned; then, it is carefully tailored, often with the guidance of an coach. A goal of ours is to investigate shaping the problem of learning a motion controller, which we believe is necessary to make high-dimensional control problems tractable. For this reason, this thesis looks at the progressive refinement of a controller and other shaping techniques for motion control. Chapter 1. 1.3 1.3.1 Introduction 4 Assumptions Reactive Control In this thesis, we study reactive motion control. In reactive control, actions are determined solely by the current observation of the system state. In other words, a reactive controller has no memory of past observations or temporary plans that affect its actions. Of course, the current observation may be ambiguous, in which case consideration of the context of the observation may be needed to take optimal actions. However, the complexity of control tasks that can be handled by a purely reactive controller is surprising. For instance, we demonstrate the reactive control of a simulated double-trailer truck driving backwards along a winding track with only local sensory information. Also, reactive control is particularly suited to unpredictable environments, such as flying a simulated spaceship through an asteroid field. At some point it becomes inefficient to make long-term plans when they are constantly being rendered useless by unpredictable events. In arriving at an understanding of general motion control, it is valuable to study reactive control, given its conceptually simple nature. 1.3.2 Control in Simulation We restrict our investigation to motion control in simulated systems. It is easier to justify studying motion control in the real world because of the obvious tangible benefits, such as industrial robots. However, there are a number of reasons why motion control in simulation is an important topic of inquiry, some of which are listed here: 1. It is far less costly and less risky to experiment with motion control in simulation than to experiment with actual robots. 2. Simulation affords some luxuries that are not possible in the real world. For example, it is often possible to invert the dynamics of a simulation and move backwards in time, allowing for a bidirectional search to connect an initial state with a goal state. 3. Once they are adequately developed, techniques for designing controllers in simulation can often be used to build robots in the real world. 4. Motion controllers can be ported to the real world if the dynamic simulation is sufficiently realistic. 5. For a robot to predict and plan in a world that contains dynamic people, animals, and other robots, it would benefit from a simulated model of how these other entities move. Chapter 1. Introduction 5 6. The motion control of virtual animals and humans in simulated environments can be used for animation. 1.4 Reinforcement Learning Framework We look at motion control problems in a reinforcement learning (RL) framework. A particular motion control problem is specified using the formalism of a partially observable Markov decision process ( P O M D P ) . In this section, we briefly describe the R L framework and explain our reasons for choosing it among other possible frameworks. The R L framework and the P O M D P are further formalized in Chapter 2. Motion control can be viewed as a sequence of action choices with potentially delayed consequences in an uncertain dynamic environment. The P O M D P , which originated in operations research and was introduced to the A l community by [CKL94], is a way of formalizing these types of sequential decisionmaking problems. A P O M D P describes the relationship between an agent and its environment, like that illustrated in Figure 1.1. It specifies what aspects of the system state can be observed by the agent, what sort of actions the agent is permitted to take, and how those actions affect the evolution of the state. It also specifies the amount of reward that is received by the agent when it takes an action to transition between states. In this way, the goal of the agent is defined, since its objective is to obtain as much reward as possible. Dynamic systems with discrete or continuous state can be described using the P O M D P formalism. The state can be partially or completely observable to the agent. Note that partial observability means there is a limited and perhaps noisy view of the state of the system, analogous to viewing the world through a dirty windshield. This assumption makes these problems considerably more difficult and also much more realistic. In the rest of the introductory discussion, we ignore the complication of partial observability. A control policy, or simply policy , is a set of behavioural rules for the agent. It tells the agent 1 which action it should take in any particular state. The goal in reinforcement learning is to learn the optimal policy, which is the policy that chooses the best action in any given state. The best action is the one that allows the agent to receive the most reward over time. We define a reinforcement learning problem (RL problem) to be a problem that can be framed in terms of finding the optimal 2 policy for a specified P O M D P . 3 In the R L framework, policy is an appropriate synonym for controller and both terms are used interchangeably in this thesis. In the R L framework, RL problem is an appropriate synonym for control problem and both terms are used interchangeably in this thesis. Note that in [SB98] the reinforcement learning problem is a general framing of "the problem of learning from 1 2 3 Chapter 1. Introduction 6 action Figure 1.1: Agent observing and acting in an environment. Standard methods to solve R L problems include value iteration and policy iteration, which are based on the principals of dynamic programming and require complete knowledge of the environment dynamics. However, other methods such as temporal difference learning and Q-learning do not require an explicit model of the environment. All of these methods try to find or approximate the optimal policy indirectly by computing an optimal state-value function (or, alternatively, action-value function), which assigns a value to each state (or each state-action pair). A n y method that is used to solve R L problems by computing a state-value or action-value function we call a value-based method. In general, we use the term RL method to refer to any method that is used to solve R L problems, not restricted to value-based methods. 1.4.1 R L and Other Frameworks It is important to note that there are other standard frameworks, such as control theory [Oga70] and kinodynamic planning [HKLR02], for looking at motion control problems. Control theory techniques are often used when a target state trajectory is given and the problem is to track that trajectory. This is accomplished by minimizing the error between the current state and the desired state on the target trajectory. A serious limitation is that many of the existing mathematical techniques in this framework assume that the system dynamics are linear and time-invariant. Motion control problems often have complex nonlinear and discontinuous dynamics. In particular, this is the case when motion may be jarred by contact with other objects, like the contact of a character's foot interaction to achieve a goal" using the Markov decision process, a fully-observable version of the P O M D P . Chapter 1. Introduction 7 on the hard ground. There have been many practical successes based on control theory, especially in controlling chemical and mechanical industrial processes. However, there is a large gap between the state of the art in control theory and that which is necessary to create graceful and physicallyrealistic character animation, for example. Furthermore, with respect to trajectory tracking, this framework often does not consider how the trajectory is obtained and how geometric constraints in the environment influence it. We might also look at motion control from a kinodynamic planning (KP) perspective [HKLR02]. In this framework, an initial state and a goal state are given and the problem is to plan a trajectory that connects the two states, subject to the kinematic and dynamic constraints of the system. K P can be used to complement the control theory framework. A desired trajectory can be obtained using K P and then a control theory technique can be used to track the trajectory. However, K P is limited in that it assumes the problem can be specified using an initial and goal state, or perhaps a sequence of states. Frameworks like control theory and K P have produced useful tools in robotics engineering. The motion system for a robot is typically designed using several subsystems, each solving a particular problem. For example, the system may be composed of a high-level task planner, a kinodynamic planner, a trajectory tracker, and perhaps a sensory subsystem. Each of these subsystems can be designed within a separate framework. Reinforcement Learning is an extremely general framework. As is pointed out in [SB98], it can be used to specify a large variety of problems, including those of different robotic subsystems. Path planning, trajectory tracking, and high-level task planning can all be cast as problems of learning a policy that obtains the maximum reward over time. In this thesis, under the framework of R L , we solve problems as diverse as following a specified limit-cycle trajectory for a point mass in one dimension and steering a truck backwards on an unseen track. We frame motion control problems using R L because of its generality and conceptual simplicity. 1.4.2 Challenges i n R L The R L framework is general and intuitive but it still faces some major challenges. For one, the optimal policy may be extremely difficult or even impossible to learn in large or infinite state spaces. This is a serious issue, since most interesting problems, such as humanoid walking, have many continuous state variables. In these cases it is necessary to learn an approximation of the optimal policy. This can be accomplished by using a priori knowledge to limit the region of the state space that is explored and otherwise limit the set of policies considered. To learn an approximate optimal policy we might evaluate policy actions from a finite sample Chapter 1. Introduction 8 of states in a potentially infinite state space. If the state sampling is representative of all states of concern and the policy generalizes to these states, then hopefully a good policy for the sample is good in general. It would be advantageous to sample states for evaluation by their importance for determining the optimal policy. For example, many states in the state space can never be visited or would only be visited by very poor policies so there is no need to waste computation to determine what action should be taken in these states. This can be accomplished in part by simulating state trajectories using the current approximation of the optimal policy during an iterative scheme, as is suggested in [SB98] and [BT96]. It is also useful to apply a priori knowledge in choosing the initial states for simulation. Furthermore, in some states, the choice of action may be irrelevant to the outcome of the system. For example, once a walking robot has fallen over, any possible action may prove futile. It is inefficient to explore all possible actions in states where those actions are equally ineffective. Expert knowledge can often be used to limit the part of the state space that is explored to that which is relevant and to give preference when sampling evaluation states to those where control has a large impact on the outcome. In infinite state and action spaces it is also necessary to limit the set of policies considered by choosing a certain representation or parameterization of this set. In effect, this choice imposes a structure on the considered policies, so that solutions must conform to a certain policy type. There are two conflicting goals in this choice of parameterization. We want the parameterized set to include some policies that are close enough to optimal so that we will be satisfied with their performance. However, we also want the structure of this set of policies to be small and simple enough that it is easy to find one of these satisfactory policies within it. This choice typically requires some specific knowledge about the structure of the R L problem and a good idea about what type of policy would be useful in solving it. Of course, if an expert is capable of narrowing the set of potential policies down to a single candidate, then no search of this set is required and we are left with a hand-engineered solution. Another challenge is to specify rewards in order to elicit a desired agent behaviour. In the R L framework, much of the difficulty in solving a specific problem, is delegated to the task of choosing a reward scheme. The P O M D P , and particularly the reward scheme, must be chosen carefully, so that the resulting optimal policy corresponds to agent behaviour that is desired. Furthermore, the choice of rewards can be used to ease the process of learning the optimal policy. For example, [Ng03] describes shaping rewards, which are modifications to the reward scheme that can accelerate learning, yet leave the optimal policy unchanged. In this thesis, we do not specifically examine the choice of rewards. However, we do consider the closely related topic of shaping the policy search through the Chapter 1. 9 Introduction choice of policy evaluation function and initial policy parameters and by staging the learning process. Many successful solutions to practical R L problems require expert knowledge to narrow down the search of possible policies and to shape the learning process. One way of doing this is to conduct a policy search using shaping techniques, as is discussed next. 1.5 Policy Search In this thesis, we use policy search to compute the policies of several motion control problems. In policy search, a limited set of policies is defined and that set is searched directly for an optimal policy . Any method that uses policy search to solve an R L problem we call a policy search method. 4 These are contrasted with value-based methods [Lar68, BT96, SB98], which use value functions to determine the optimal policy. Policy search can be much more efficient than value-based methods if the set of policies can be narrowed considerably using a priori knowledge of the problem. A successful practical example of policy search is in [Ng03] , where the authors devise a rough 5 control program to fly a helicopter with some parameters left undetermined. The various forms of this control program that arise from different parameter settings comprise the set of considered policies. Policy search is then used to find the optimal policy within the set, or in other words to learn the optimal parameters for the control program. This example is indicative of how policy search is a compromise between hand-engineering and learning a policy . Hand-engineering is used to create a 6 general policy structure and the policy search fills in the details by learning the optimal parameters for the policy structure. To effectively solve a motion control problem using policy search it is important to choose: 1. A policy representation that is adequate for the problem and yet as simple as possible. 2. A n observable state representation that highlights features of the state that are pertinent to the motion control task. 3. A n evaluation method for policies such that the policy score is indicative of the quality of the solution to the problem. 4. Initial policy parameters that provide a good starting point for the policy search. A l l of these choices guide policy learning through the use of a priori knowledge to impose a structure on the policy search. Any technique that is used to shape the search in this way, we refer to as a T h e optimal policy within the set that may not correspond to the overall optimal policy. T h i s example is discussed, further in Section 2.3.1. Because learning optimal policy parameters and conducting a search for an optimal policy usually mean the same thing, we use the phrases searching for a policy and learning a policy interchangeably. 4 5 6 Chapter 1. Introduction 10 shaping technique. The choice of policy representation, observable state representation, evaluation function, and shaping techniques in general are further explained in Chapter 2. 1.6 Contributions We demonstrate that policy search applied to a nearest-neighbour policy representation (NNPR) can be used to solve a variety of motion control problems. This representation's semi-parametric character lends itself to adaptive policy refinement, and we show how this can be used as an effective technique for shaping the policy search. We illustrate the use of other important shaping techniques, including the choice of evaluation function and observable state representation. The flexibility of the nearest-neighbour representation is conveyed through the range of motion control problems solved in this thesis. These include the classical cart and pole problem and the steering of cars and trucks down a winding track using local environment sensing. In one example, we demonstrate the steering of a truck with two trailers backwards along the track, which is of particular interest because of the considerable instability of the trailers. In [NW89], the authors solve a related problem using self-learning of a neural network policy to steer a single-trailer truck backwards towards a fixed goal state. Also, T D learning has been used to learn policies that drive a car forwards down a specific winding track in the context of R A R S , the Robot Auto Racing Simulator [Cou02, PH98]. The steering problem we solve is considerably different than these R A R S examples in that we use a fixed vehicle velocity and only local track observations, we handle the steering of unstable systems, and perhaps most significantly, our learned policies are shown to generalize to different tracks of the same style as the training track. We also look at the problem of driving the state of a one-dimensional point mass around a userspecified limit cycle in a robust fashion. Almost all types of locomotion are cyclic in nature, so it is important that a controller be able to follow a desired limit cycle robustly in the presence of perturbations, such as wind gusts or terrain variations. For example, [Sha04] describes the use of a nearest-neighbour policy to control planar biped walking on variable terrain with the variations in ground level being unanticipated. 1.7 Thesis Outline In Chapter 2, we formalize the P O M D P and policy search framework in which we will be viewing motion control problems. In Chapter 3, we define a nearest-neighbour policy, which we shall use as our policy representation and we provide the example of using such a policy to drive the state of a point-mass around a limit cycle. Moreover, we discuss specific shaping techniques that are used Chapter 1. Introduction 11 in our work, including adaptive refinement of the policy. The application of the nearest-neighbour representation to the control of a cart and pole system is described in Chapter 4. We apply our method to the steering of cars and trucks in Chapter 5. Chapter 6 takes a critical look at the benefits and drawbacks of the nearest-neighbour representation and our policy search method. The work is concluded and future directions laid out in Chapter 7. Related work is distributed throughout the thesis in order to locate it directly with the appropriate related discussions. Theoretical works on P O M D P s , reinforcement learning, and policy search are referenced in Chapter 2. References specific to the problem of cart and pole are included in Chapter 4 and those for vehicle steering problems are in Chapter 5. Chapter 2. POMDP and Policy Search Framework 12 Chapter 2 POMDP and Policy Search Framework It is useful to have a consistent language in which to talk about motion control problems. We use the P O M D P as a way of formalizing such problems. Also, we take a particular approach to solving R L problems, namely policy search. This chapter describes this perspective of viewing and attacking problems in motion control. In Section 2.1, we formalize the P O M D P and explain R L problems in further detail. Value-based R L methods and their limitations are examined in Section 2.2. R L problems are framed from a policy search perspective in Section 2.3. We go over previous work in solving R L problems, and particularly motion control problems, using policy search. We look at the important choices of policy representation, evaluation metric, and optimization technique. Also, shaping and how it can be used to aid policy learning is discussed. Finally, in Section 2.4, we summarize the discussion of the P O M D P and policy search framework and outline which aspects and previous work are most relevant to our work in motion control. 2.1 POMDPs and Reinforcement Learning The partially observable Markov decision process ( P O M D P ) is a useful way of formalizing sequential decision making with delayed consequences in'uncertain dynamic environments. We use the P O M D P as a way of framing various motion control problems in a consistent manner, such that the commonalities and distinctions between the problems are highlighted. A P O M D P describes the states which an agent can take on within its environment, the aspects of its state which it can observe, and actions it can take to affect its state. It also describes how the agent gets rewarded for changes in its state and how important future rewards are to current action decisions. A P O M D P is defined as {S, O, A, v, w, r, 7 ) , where: • S is the set of states, • O is the set of observations, • A is the set of actions, Chapter 2. POMDP 13 and Policy Search Framework • v . S x A —* 5 is the state transition function, • uj : S —• O is the observation function, • r : 5 x 4 x 5 - > R i s the reward function, • 7 € [0,1] is the discount factor. This definition is generally consistent with a standard P O M D P definition [MPKK99]. However, we consider only deterministic P O M D P s , while in [MPKK99] and other definitions [Ng03, CKL94], v and u> are probabilistic . 1 For all of our control problems, S is a continuous state space, i.e., S = M , where d is the ds s dimension of the state space. Let s G 5 be a state, represented by a d -vector of real numbers. s Similarly, O is a continuous observation space, i.e., O = R ° , where d is the dimension of the d 0 observation space. Let o € O be an observation represented by a d -vector of real numbers. Also, G A C R, da with d being the dimension of the action space, as the control problems described in a this work have one or more control variables with a range of real values. Let a £ A be an action represented by a d -vector of real numbers. Q We use the notations s , o , and a to refer to the state, observable state, and action respectively t t t at a discrete time step t . The state transition function, v, describes how the state of the system 2 will evolve, given the input of certain actions, by mapping a state, s , and action, at, to a successor t state, St+i- As a window onto the state of the system, the observation function, u> : S —* O, describes what can be observed about the state. If the state is completely observable, O = S and OJ = I is the identity function. The reward function, r, maps a state, s , and the action taken at that state, a , to a real-valued t t reward. We take r = r(s , at) to be the reward received at time step t . The reward function rewards 3 t t good choices of action and punishes bad ones indirectly (and not always immediately), through the transitions in system state that are achieved by a sequence of actions. In a P O M D P , as in real life, gratification is not always instant and actions at one time can affect the state of the system such that the repercussions are felt only considerably later. Finally, 7 determines how important rewards obtained in the future are to choosing actions now, in a way that will be formalized shortly. Probabilistic state transition and observation functions are normally used to model environments with noisy observation and action, which are typical conditions for real-world robots. W e make the assumption that time is discretized, which is reasonable considering the problems we consider involve simulation on a digital computer. Note that, in some P O M D P definitions, rt is based only on st (e.g. [Ng03]). 1 2 3 Chapter 2. POMDP 2.1.1 14 and Policy Search Framework Policies and State Trajectories A P O M D P describes the environment in which an agent acts. This agent learns some rules of behaviour, called a policy, which tell it exactly how to act in each possible situation. W i t h P O M D P s , an observation, o , may not give the policy enough information to discern exactly what is the current t state of the system, s . Of course, s is often what is needed by a policy to determine the optimal t t action required to drive the state of the system towards that which is desired. For this reason, a policy might put its current observation, o , into context by considering the history of all observations t oi,... ,o in determining the current action, at- To accomplish this, a policy would require a memory t in which to store and manipulate (e.g., consolidate) past observations. A policy with a memory is capable of having temporary goals and is sometimes called a purposeful policy. O n the contrary, a policy without a memory must simply decide on the action, a , it will take based only on the t current observation, ot- Such a policy could be considered to have a purpose or goals but they are permanently inscribed in its rules of behaviour. Policies of this type are called reactive or memoryless policies. time step (-/ i t Figure 2.1: Evolution of a state trajectory. In this thesis, we deal with reactive policies. The symbol IT refers to both a policy and its characteristic mapping of observation to action. For example, 7r : O —• A, describes how the policy 7r responds to each possible observable state, o. Let II be the set of all such policies. When a policy acts within a P O M D P the system evolves over sequence of states, {s\,si), called a state trajectory, or simply trajectory. This trajectory is determined by the following recursion: _ S where Smit t - \ f Sinit if t = v(s -u«(u>{st-i))) if * > 1, t 1 is the initial state. Figure 2.1 illustrates how a state trajectory evolves. It is useful to notice that a trajectory is entirely determined given Si u, v, u>, and n. n Chapter 2. POMDP 2.1.2 and Policy Search Framework 15 R e w a r d and R L Problems The reward function, r : S x A —> K , allows us to evaluate policies, and therefore to determine which policies are optimal. It specifies the reward that is received by a policy when an action is taken in a particular state. Typically, the P O M D P (and, in particular, the reward function, r) is framed so as to elicit an optimal policy that results in a desired behaviour of the entire system. A policy is optimal if, from any initial state, it receives as much discounted reward as possible, summed over the resulting trajectory. This cumulative discounted reward is determined by the policy 7r and the initial state s and is used to define a state-value function for the policy, oo V*(a) = Y,1 - ru t l t=i where 7 6 [0,1] and rt is the reward received at time step t when policy TT is executed from the initial state s. Note that the smaller 7 is, the more discounted future rewards are, and the more short-sighted optimal policies will be in determining actions. Choosing the reward function, r, and the discount factor, 7 , that correspond to a desired system behaviour is certainly not trivial in many cases and this continues to be an open area of R L research. In reinforcement learning, we take a hedonistic viewpoint by trying to maximize discounted reward received over time. In other words, we try to find a policy TT*, such that V*'(s) = maxV*(s), 71-en (2.1) for all states, s. The objective of a reinforcement learning problem is to find an optimal policy, ir*, or some near-optimal approximation of ir*. Note that it is usually impractical or impossible to search through all policies to find one that is optimal, since |II| = |j4|I°L 2.2 Value-based Methods and Limitations Most value-based methods were developed for MDPs, which are the subset of P O M D P s with complete observation, i.e, with u> being the identity function. For the discussion of value-based methods, we will initially assume that we are dealing only with MDPs. A comprehensive description of valuebased methods for general (including nondeterministic and deterministic) M D P s can be found in [SB98, BT96, KLM96]. 2.2.1 Dynamic Programming Much of reinforcement learning theory is based on the principles of dynamic programming [Bel57], which exploit the structure of an M D P to find IT* more efficiently than through an exhaustive search Chapter 2. POMDP and Policy Search Framework 16 of n . For M D P s with finite state and action spaces, an optimal policy, it*, can be found indirectly by solving the Bellman optimality equation for V*, of which the following is one of a number of equivalent forms: V*{s) = msxMs,a)+V*(s')), (2.2) where s' is the state reached by taking action a from state s. The unique solution gives the optimal state-value function, V*, which is equivalent to the solution of Equation 2.1, V" . There may be more than one policy, 7r*, that is optimal, but they share the same optimal state-value function. Once V* is available, an optimal policy can be denned by choosing actions greedily to achieve as much cumulative discounted reward as possible: 7T*(s) = argmax (r(s,a) a€A 2.2.2 + V*(s')) Standard Value-based Methods One standard method for solving Equation 2.2 to obtain V* is the value iteration algorithm, which makes successive improved approximations of V* and has proven guarantees of convergence. Another method is policy iteration, which manipulates policies directly by evaluating the current policy ir to obtain V v and determining the next improved policy by choosing actions greedily based on V. Policy iteration terminates after at most \A\\ \ iterations. S Value iteration and policy iteration assume that a model of the M D P is available, i.e, that the transition function, v, and the reward function, r, are known. However, in many R L problems, a policy must be learned without direct access to an M D P model, but only through the experience of choosing sequences of actions and taking note of the resulting rewards. The TD(X) algorithm can be used for policy evaluation (i.e., to find V ) without a model by updating the values of states in w experienced trajectories. The function V* can be estimated by always using the policy that is greedy with respect to the current value function estimate to compute the trajectories. Similarly, Q-learning can be used to learn the optimal action-value function, Q*(s,a), through updates to action-values during actual experience. The function Q*(s,a) assigns values to state-action pairs by specifying the cumulative discounted reward for taking action a from state s and taking optimal actions afterwards. Q-learning and other temporal difference (TD) methods can be contrasted with value and policy iteration, which require a model and update the value function with full sweeps of the state space. All of these methods can be considered generalized policy iteration, which includes any method that alternates between improving an estimate of the value function for the current policy and improving the policy to take greedy actions with respect to the current value function estimate. Chapter 2. POMDP and Policy Search Framework 17 The value-based methods described above are sufficient for M D P s with small, finite state and action spaces. However, most interesting R L problems have large and/or continuous state spaces and some have large and/or continuous action spaces . For the vast majority of problems with continuous 4 state spaces, it is impossible to learn a value function exactly by one of these value-based methods. 5 In these cases, it is necessary to solve the R L problem approximately by discretizing the problem or approximating the value function in some other way. 2.2.3 State and A c t i o n Discretization Continuous state and action spaces can be discretized to solve an R L problem approximately [Lar68]. However, the curse of dimensionality dictates that the number of discretized states varies exponentially with the dimension of the state space, d , which makes most R L problems, even of moderate s (5-10) dimension, intractable. Since some regions of the optimal value function may have more variation than others, adaptive resolution schemes can be used to focus computation and storage resources on interesting areas of the state space. For instance, [MA95] presents the PartiGame algorithm for finding feasible trajectories to goal regions by adaptively partitioning the state space. This algorithm was tested successfully on problems with continuous state spaces ranging from 2 to 9 dimensions. PartiGame is limited to solving problems with a fixed goal region, as opposed to having arbitrary reward functions. Unlike R L problems, as we have defined them, it does not approximate the value function and does not necessarily find optimal or near-optimal trajectories to the goal. In [MM02], a variable discretization of the value function is used. The state space is partitioned into cells using a tree representation. The decision of whether to split a cell is based not only on local variation in the value function or optimal policy but also on the non-local impact on other cells. This value-based method is used to find near-optimal solutions to deterministic control problems of as many as 5 continuous state dimensions. 2.2.4 Value Function Approximation R L problems can also be solved by using a function approximator with generalization capabilities, such as a neural network, to approximate value functions. Generalization can be useful in large state spaces, whether discrete or continuous. [Tes95] used TD-learning with a backpropogation neural network to learn a policy that could play backgammon at the human master level. The algorithm For example, a 9 degree-of-freedom biped used to learn walking control in [Sha04] moves in an 18-dimensional continuous state space. If an action consists of setting a target position for each joint or applying a force to each joint the action space would be continuous and 6-dimensional. Here we use value function to refer to a state-value or action-value function, although in most other cases value function will refer only to the state-value function. 4 5 Chapter 2. POMDP 18 and Policy Search Framework learned through several months of self-play and the most sophisticated version used hand-crafted useful features in the state vector. Although backgammon has discrete state, the number of possible states is estimated to be more than 1 0 , which makes approximation of the value function necessary. 20 In another example, a neural network and TD-learning was used to approximate the value function in [Cou02]. A policy was found that allowed a snake-like creature to swim in an 12-dimensional continuous state space with 4-dimensional continuous actions. Although the dimensionality of this problem was large, it is questionable whether it is more complex than problems with highly nonlinear control and 4-dimensional state spaces, like the cart-pole swing-up and acrobat problem, which were also addressed in the work. There are likely a large number of policies that would allow the snake to swim in one direction, which would make it relatively easy to find one that is locally optimal. However, this example demonstrates that neural networks can effectively generalize in high-dimensional spaces. [Cou02] also used TD-learning to learn a policy for car racing, which we compare to our vehicle steering work in Chapter 5. The main disadvantage of using a neural network (or a similar generalizing function approximator) is its poor locality. Incremental updates to the weights of the neural network may have side-effects in regions of the value function domain which are unrelated to the training data currently being learned. For this reason, there are few convergence guarantees in this setting, thus nullifying one of strongest features of value-based methods. Some limited positive convergence results are in [BT96], including a proof convergence of TD(X) algorithm for approximate policy evaluation using linear 6 function approximators. A n example of divergence for the case of nonlinear approximation is also shown. A framework for handling continuous-time control problems, without explicitly discretizing the state space, the action space, or time, has been presented in [DoyOO]. The main advantages of this framework are that the action can vary smoothly yielding better policy performance, the gradient of the value function can be used to determine near-optimal control, and there is no need to determine how to partition state, action, and time. The task of finding the right granularities is delegated to the function approximation and numerical integration algorithms. A cart-pole swing-up problem with highly nonlinear control in 4 continuous state dimensions was solved using this framework and a normalized Gaussian network is used to approximate the value function and policy. This approximation scheme has the disadvantage that the basis functions are positioned in a regular grid and therefore number exponentially with the number of state space dimensions, although it is possible to use other approximation schemes within the framework. 6 Policy evaluation computes the value function, V", of a fixed policy 7r. Chapter 2. POMDP 2.2.5 and Policy Search Framework 19 P a r t i a l Observability- A l l value-based methods described above are designed to work for M D P s , where the state is completely observable. In the setting of P O M D P s , with partially-observable state, the problem of finding an optimal policy is considerably more difficult. This is because the observable state will typically not be Markovian in which case the choice of optimal actions may depend on previous observations, not 7 simply the current observation. It is possible to use a value-based method for M D P s on a P O M D P using the observable states and ignoring the fact that they may not be not Markovian. If the observable state is sufficiently close to Markovian then this might perform well. However, performance may be arbitrarily poor in the general case. A more robust method is to use a model of the P O M D P (including state transition function, v, and observation function, w) to compute a belief state, which represents the probability of being in any state given past and current observations. The belief state is Markovian and so it can theoretically be used to compute the optimal policy using an value-based method for M D P s . However, the space of belief states will be much larger than the original state space. For example, given a discrete state space, S, the corresponding belief state space will be continuous with | 5 | — 1 dimensions. Finding the optimal policy for a P O M D P using belief states and dynamic programming can often be very computationally intensive or practically impossible. 2.3 Policy Search Although some dynamic programming algorithms offer guarantees of convergence to an optimal value function, it is yet to be shown that such algorithms can be applied to learning complex control in continuous state spaces of moderate-to-high dimension and continuous action spaces. Many motion control problems, such as the control of an articulated figure for animation or robotic simulation, fall into this category. A practical alternative to value-based methods is policy search, where a restricted set of policies is searched directly for an optimal policy, without computing a value function. In this setting, some prior knowledge of useful policy structure is used to define a fixed class of policies, n C II, to be considered. A vector of policy parameters, 0 , defines a specific policy within II. We then search LT for an optimal policy, 7r*, which is equivalent to learning the optimal policy parameters, O*. By defining a promising policy structure with a simple parameterization, it can be significantly more efficient to search n for an optimal controller 7r* than it is to find an adequate approximation to V* 7 If a state is Markovian, the successor state is determined independent of any previous states. Chapter 2. POMDP 20 and Policy Search Framework using dynamic programming. Of course, ft must be chosen carefully so that it includes satisfactory solutions. Furthermore, the parameterization and search algorithm must be chosen intelligently so that one of these solutions is found quickly and reliably. Usually it is difficult to guarantee that a policy search algorithm will find n* that is close to n* by some objective measure. For this reason, policy search methods are typically evaluated by the quality of the solutions computed in practise, while unfortunately remaining weak in theoretical guarantees. In Section 2.3.1, we consider examples of policy search being used to solve motion control problems. This is followed by a discussion of important aspects of the policy search method, including the policy representation, the optimization method, and other ways of shaping the search. 2.3.1 Previous Work Complex motion control problems have been solved using policy search. For example, a policy was designed for flying an autonomous helicopter[Ng03]. The state space of the helicopter was 12dimensional and the action space 4-dimensional. In order to learn a stable hovering behaviour, ft was defined to be a set of neural networks of a specific topology that map a specific choice of state variables and position errors to actions. The connection weights of the network were left for the policy search to determine. Prior knowledge was incorporated into the network structure by choosing useful observable state variables as input, appropriate computation (sum or tanh) at each network node, and only connecting state input to an action output if it was considered relevant. The learned policy was able to hover at a fixed target position. With a slightly modified network and by slowly varying the target position for the helicopter to create a target trajectory, another policy was learned that could perform several flying manoeuvres. In another example, a controller for robot weightlifting was learned using policy search and shaping techniques modelled after human motor learning [RB01]. The task was to lift a three jointed robot arm with a payload from straight-down equilibrium position to a straight-up unstable position by applying a torque to each joint. This is similar in concept to the classical pendulum swing-up problem. The task is made difficult when the joint torques are limited and payload mass sufficient such that the payload cannot be lifted by trivial motion of the arm. A priori structure was introduced into the policy by defining a via point, which is a useful part-way arm position for completing the task. The policy was then composed of three timed proportional-derivative (PD) controllers, one to drive the arm to the via point, one for the goal configuration, and one to hold the arm at the goal configuration. A matrix of weights was used to couple the torques applied to the joints. The timing parameters, P D parameters, and matrix weights were learned with a simple stochastic search algorithm. The payload mass was increased as policy learning progressed as a form of shaping. Chapter 2. POMDP and Policy Search Framework 21 In several instances, policy search has been used to learn policies for the motion of virtual characters with potential application to computer animation: • [vdPF93] used a randomized generate-and-test algorithm followed by fine-tuning using stochastic search to generate locomotion policies for a number of articulated virtual creatures. In this case the policies were structured as sensor-actuator networks (SANs), which are similar to artificial neural networks except that they have node delays. These delays give a S A N dynamic properties of its own, making it a purposeful policy with internal state as opposed to a reactive policy. • Policies based on stimulus-response mappings were optimized using genetic algorithms in [NM93]. The evaluation function rewarded a policy for making a character of a particular shape move as far as possible in one direction during a given evaluation period. Several different characters were taught various locomotion strategies using this technique. Our nearest-neighbour policy representation (NNPR) is similar to the stimulus-response policy representation used in [NM93]. A more detailed comparison is included in Section 3.1. • [Sim94] used genetic algorithms to evolve both the policies and morphologies of virtual creatures for various behaviours, such as swimming, walking, jumping. This work looked at a broader problem than an R L problem since not only the policy, or mapping from observable state to action, was learned. Sensors were evolved, optimizing the form of the observable state, and the creatures' bodies and potential actions were evolved, optimizing aspects of the system dynamics. Since parts of the entire system were being optimized, this problem was particularly suited to a standard optimization using genetic algorithms and it is difficult to see how this problem could be made to fit the R L framework. The policies evolved were purposeful because timed oscillators were an important component. Creatures were evaluated specifically for each action, e.g., using the distance travelled for walking and swimming behaviours. • A genetic algorithm was also used in [Gri97] to find policies to control the motion of an animated desk lamp character. The policy was intended to move the lamp forward a variable distance to a goal position. In this way, the motion of the learned policy was parameterized, i.e., an animator could specify the distance the lamp should move. The actions of the learned policy could be dependent on time, making it a purposeful policy. The evaluation function took into account the error from the goal position as well as some aspects of motion style. Shaping of the policy learning was achieved by slowly introducing style considerations into the evaluation function over successive generations of the algorithm. Chapter 2. POMDP 2.3.2 and Policy Search Framework 22 Policy Representation There are a variety of ways of incorporating knowledge of useful policy structure into the representation. Out of necessity, R L methods have imposed structure on solutions by using various function approximations for policies or value functions, such as grid discretizations [Lar68], neural networks [Tes95, Cou02], and normalized Gaussian networks [DoyOO]. Knowledge that optimal policies and value functions often have inconsistent variation through the observable state space has encouraged the use of variable-resolution methods [MA95, MM02], Genotype representations of policies [Sim94, Gri97] can help to reuse useful structures within a policy, while learning these structures only once. A l l these representations simplify policy learning partly through reducing the set of considered policies by making a coarse approximation of all possible policies. The main simplifying assumption that is typically made is that the policy to be approximated is mostly continuous over the state space. However, most of the above approximation methods still attempt to model general functions, without incorporating specific task knowledge into the policy. On the other hand, some policy search methods, such as [Ng03, RB01] have used prior knowledge about the control task to make the policy representation highly-structured and problem specific, thus significantly limiting the number of policy parameters to be learned. Certain properties of the policy representation may be useful to an R L method: • Compactness: Generally speaking, the fewer the policy parameters the easier the search for an effective policy. This also effects the efficiency of policy storage and algorithms that work directly with policy parameters. • Smooth Parameterization: If changes in parameters smoothly affect the policy, the policy search is generally made easier. • Nonparametric or semi-parametric: Free parameters in the policy representation can be added or removed to suit the complexity of the task being learned. This is in contrast to a parametric representation which has a fixed number of free parameters to be learned. A nonparametric policy representation typically stores experience data directly, whereas with a semi-parametric representation experience data is consolidated. • Adaptive refinement: The policy granularity can be made to vary across the observable state space, rather than being uniform. In other words, the policy can be refined further in some regions of the domain than others, as required. • Locality: Local regions of the policy can be updated without unwanted side-effects to other regions. Chapter 2. POMDP 23 and Policy Search Framework • Generalization: Aspects of the policy parameters should affect various regions of the policy when relevant. Particularly in high-dimensional state spaces, symmetries in the policy should be exploited as much as possible. • Conceptual simplicity: Whenever possible, a policy representation that can be readily understood by people is preferable. Of course, it can be very difficult to incorporate all of these properties into a single representation, and trade-offs must be made. Some properties, such as locality and generalization, often directly conflict with one another. We use the nearest-neighbour policy representation, defined and explained i n Chapter 3. A discussion of properties of the N N P R and how they may have affected the policy search for our various motion control tasks is in Section 6.1. 2.3.3 Evaluation In order to use policy search to find an optimal policy we must define a real-valued evaluation function, E(Q), that models how well the policy with parameter vector 0 solves a particular control problem . 8 The object of the policy search is to find the optimal parameters : 9 0* = argmaxQE(@). Typically, E(Q) evaluates a policy by executing the policy from one or more initial states and considering some success measure of the resulting trajectories . Since we use this type of evaluation 10 for all control problems considered in this thesis it is useful to establish a consistent notation. A policy is evaluated from p initial states, s\ , 1 < i < p for T i simulation time steps each. The set of all p nit initial states is Smit- eva This results in p state trajectories, <7*(0) = ( s ^ O ) = s\ , ^ ( O ) , . . . , nit «T „ , e a where 1 < i < p. Each of these trajectories is evaluated by a function e(<r (0)), which measures how I well the policy does from initial state s\ . We sum the performances of the policy from each initial nit position to obtain an overall evaluation metric p (2-3) T h e evaluation function, E(@), is distinct from the reward function, r, of a P O M D P , which measures the desirability of taking an action in a particular state. In conducting a policy search, we desire that an optimal policy as denned by E(@), is close to an optimal policy of the underlying P O M D P as defined in Section 2.1.2. However, it is difficult to obtain proven guarantees in this regard. Although we usually attempt to maximize the evaluation function, it is very common to minimize a cost function. These are equivalent and an evaluation function can be obtained by negating a cost function and vice-versa. With regard to optimization, we may use the term ascent for increasing the value of the evaluation function towards a maximum and descent for decreasing the value of the cost function towards a minimum. F o r example, the evaluation could start a virtual creature from a single position and evaluate how far it can walk in a particular direction. 8 9 10 Chapter 2. POMDP 24 and Policy Search Framework In some cases, we consider e(cr'(0)) to represent an error in the trajectory and the sum is negated in Equation 2.3. Although we use an L\ norm of the individual trajectory evaluations to calculate the overall evaluation, there are other possibilities that are reasonable, such as an L2 norm. It is unclear how the choice of norm would affect policy learning and the effects would likely be problem dependent. This is an interesting issue that is not addressed in this thesis. The evaluation of a trajectory, e(cr (©)), can be viewed as an estimation of the value (or cumulative l discounted reward) of the corresponding initial state, V*(s\ ). nit In this way, if provided with an M D P (S, O, A, v, u>, r, 7 ) , a reasonable trajectory evaluation function would be 6(^(9)) = £ 7^(4(0),^) j=i For such an evaluation metric, if Si i n t contained all states and T i eva was sufficiently large, 0* would specify the optimal policy, 7r*. However, in policy search we typically avoid evaluating all states for large values of T i eva because this is impractical. The choice of initial states, Sinit, is critical in policy search. Often the evaluation of a policy is computationally expensive because it involves simulation of many trajectories. Each simulation of potentially thousands of timesteps can be expensive in itself. It is useful to reduce much as possible without degrading the evaluation quality. The set Si u n p * T i eva as must be chosen so that the distribution of initial states and resulting trajectories is representative of state regions that are important for control. This means that the distribution should be more dense in states that are visited frequently or for which policy changes result in large differences in cumulative discounted reward, V (s). Often it is difficult to choose the set n Smit deterministically, and it is simpler to define a distribution D of potential initial states and randomly sample the states that form Si i n t from D. This method of choosing initial states is also described in [Ng03]. The choice of D can be critical for shaping the optimization, which is further discussed in Section 2.3.5. 2.3.4 Optimization Any number of search techniques can be used to find locally or globally optimal policies. For example, we extensively use variations of stochastic greedy ascent (SGA), a simple optimization technique. This method, outlined in Algorithm 1, perturbs parameters 0 by a random vector SQ and if an improvement is made keeps the change. Otherwise, the unperturbed parameters are kept and another random perturbation is tried. These perturbations and comparisons are applied iteratively until some convergence criterion is satisfied. Despite the simplicity of this technique, good solutions can be found if E(Q) is adequately shaped, as will be described further in Section 2.3.5. In this thesis, we focus Chapter 2. POMDP and Policy Search Framework 25 on the shaping of optimization problems so that a simple optimization technique, such as S G A , is adequate. Leveraging existing, more sophisticated optimization algorithms that are particularly suited to our problem would possibly improve the search performance, but as yet, we have not experimented in this direction. Algorithm 1 Stochastic Greedy Ascent (SGA) input 0 {policy parameters} input p {step size} input A {decay factor} Ebest *— E(Q) repeat for i < — 1... de do SQ[i] <— Rand(-l, end for &new <- Enein * if 0 + 1) {Assumes dimensions of the policy parameter space are normalized} 50 E(Q ) new Enevj then > Ebest 0 * 0netw Ebest * E n e w end if P «- V until convergence Optimization techniques such as genetic algorithms and simulated annealing can be used to find globally optimal solutions. These may prove considerably more effective than simple S G A if the optimization landscape has many local minima that are not satisfactory solutions. Gradient-based optimization techniques are another alternative. If it is possible to compute partial derivatives of E(Q) with respect to 0 then local maxima could be efficiently computed by steepest ascent or other numerical optimization techniques that utilize gradient information. However, for most policy parameterizations, E(&) does not vary smoothly with changes to 0 . For example, if E(Q) evaluates one or more trajectories, a small change to the policy parameters could result in a large jump in the policy evaluation. This may occur if there are discontinuities in the state transition function, v, the observation function, ui, or the reward function, r, which is common for R L problems. In [BM99], a method that can be used to conduct a policy search 11 using the gradient of an evaluation function is presented. The evaluation is based on the expected value of a trajectory error with respect to trajectory probabilities. A stochastic policy is used so that the distribution of policy actions and also the distribution of trajectories varies smoothly with changes to the policy parameters. T h e algorithm is sufficiently general that it can be instantiated as either a value-based or policy search algorithm, or some combination of the two. n Chapter 2. POMDP and Policy Search Framework 26 However, only finite state and action spaces are considered and it is not clear how this method would generalize to continuous state and action spaces, where the number of possible trajectories, even with a small time horizon, is infinite. It is also possible to estimate the gradient of E(Q), even if it is non-differentiable, and use the estimate to move in the direction of steepest descent (or ascent). For instance, approximate partial derivatives of E(Q) can be computed using finite differences (i,e., by evaluating one modified policy for each policy parameter, each with just a small change in that parameter). There are also methods for computing approximate gradients using stochastic perturbations to policy parameters. In [RB01], a stochastic search algorithm that blends a random walk with movement along a rough estimate of the gradient is used to find a policy for robot weightlifting. 2.3.5 Shaping We take shaping to mean guiding policy learning through introducing a priori structure into the policy search. In psychology, the term shaping has been used to refer to training a human or animal to perform a complex task by leading up to it with a sequence of progressively more difficult tasks. We include this kind of shaping in our definition of shaping for policy search. In [Ng03], reward shaping referred to choosing the rewards for a P O M D P to aid policy learning. Our definition of shaping includes the choice of evaluation function, which is related to the reward function, to guide the optimization of policy parameters. Finding good solutions to complex R L problems in high-dimensional or continuous state and action spaces can be computationally intractable if assumptions are not made with regard to policy learning. Making various assumptions about the types of policies to consider and how to learn a policy can drastically reduce computational effort in policy search. General Techniques One way shaping can be accomplished is by choosing a compact, smooth policy representation. Since the domain of the evaluation function, E(Q), is the set of possible policy parameters, 0 , the choice of parameterization is important for facilitating the search for an optimal policy. The policy search can also be shaped by choosing useful inputs and outputs for the policy. The representation of observable state and actions available to the policy can greatly affect policy learning. Observable state should be directly relevant to the choice of action necessary to receive reward. The action representation should be as simple as possible while allowing the capability to succeed at the R L problem. Careful representational choices can simplify the optimal policy, making it easier to approximate with a given policy representation. Changes to the observation function and actions can Chapter 2. POMDP 27 and Policy Search Framework either be viewed as modifications to the P O M D P or to the policy structure. If the R L problem is fixed, these changes must be limited to a mapping from observable states, O, to modified observable states, O', and a mapping from modified actions, A', to the original actions, A. W i t h modified observations and actions, the goal is to learn an optimal policy, TT* : O' —> A'. Another critical choice is how to evaluate policies. If the evaluation time, for each trajectory T i eva is too small, short-sighted policies may be favoured. If, however, initial states, Si i , n t are distributed densely enough that trajectories overlap then short-sightedness is less of an issue. The evaluation will focus on control in certain regions of the state space if the distribution of initial states is biased. Having many initial states in regions of critical control can help shape the policy search. This is because the search can first find a policy which solves these critical regions and then fine-tune the policy. It is also useful to have initial states with a range of control difficulty, so that, early on, the search can optimize the policy for the easy trajectories and progressively optimize for more difficult trajectories. Finally, the evaluation of individual trajectories depends on the choice of reward function. Rewards can be given for accomplishing known intermediate goals to guide policy learning. Since evaluations are of limited time, T i, eva it is critical that rewards are chosen such that the quality of each trajectory can be judged. If reward is only received at a goal state, and the trajectories cannot reach that goal state, they will be useless for the evaluation. 0inil ©* Policy Parameters 0 Figure 2.2: A poorly shaped optimization problem (top) and a well-shaped optimization problem (bottom) given initial parameters, 0 . t m t Choosing a good policy representation, observation and action representations, and evaluation function serves to shape the evaluation landscape and can significantly aid policy optimization. The evaluation landscape can be considered very well-shaped if a gradient ascent optimization can find a satisfactory solution (see Figure 2.2 (bottom)). This is generally true if the initial policy parameters, Chapter 2. POMDP ©mis, 28 and Policy Search Framework lie within the basin of a satisfactory optimum. A n optimization may be poorly-shaped if the evaluation landscape is plagued by poor local minima and Qi u does not lie within the basin of a n satisfactory local optimum (see Figure 2.2 (top)). Some optimization techniques allow the current solution to escape local minimum but this makes the optimization problem a more difficult one. When the optimization is poorly-shaped, it is necessary to use a global optimization technique, such as simulated annealing or genetic algorithms to find satisfactory optima, which can be a computationally intensive process. Of course, to make an optimization well-shaped it is possible to initialize Qi u to lie close to a n good solution. We call this technique bootstrapping . 12 In this way, another process could be used to find a very good estimate of policy parameters and then policy search could be used to refine them to a locally optimal solution. A n example of this is described in Section 3.3.3, where the optimization of a time-based policy is used to bootstrap the initial policy parameters for a policy search. Series Shaping We are particularly interested in using bootstrapping in a series of optimization episodes that progressively refines the policy, much in the same way that shaping (in the psychological sense) can be used to train animals. We call this type of shaping series shaping. A n optimization series, cj>i,..., <j> , m is conducted, where the policy parameters resulting from 4>i are used to initialize the parameters for the next episode of optimization, 4>i+\, as shown in Figure 2.3. This type of policy refinement is analogous to the way a beginner might learn to play a video game, by starting off with very basic missions and using the skills they have developed to attempt increasingly more difficult missions. Series shaping bears some resemblance to simulated annealing, where solutions to problems with local minima are also gradually refined. Simulated annealing performs a search to minimize a fixed objective function and gradually decreases the probability that changes which increase the objective function are accepted. On the other hand, series shaping gradually changes the objective (evaluation) function, increasing the difficulty of the optimization problem. Series shaping usually provides a way to introduce a priori knowledge into the optimization about what makes the problem difficult and how it could be solved in stages. Simulated annealing is suited for problems in which a global optimum is required but little is known about the optimization landscape, but it can be very computationally intensive. We use series shaping to learn policies for steering vehicles by increasing the free parameters available in the policy representation with each optimization episode. First, a coarse policy for Note that in [SB98], the term bootstrapping is used in the context of value function estimation to refer to "updating] estimates of the values of states based on estimates of the values of successor states", as opposed to estimating the value of a state independent of other state value estimates. 12 Chapter 2. POMDP and Policy Search Framework 29 ginil 4j Policy Parameters 9 Figure 2.3: Progressive refinement of parameters, 0 , using a series of progressively more difficult optimizations. Each optimization episode is bootstrapped using the result of the previous one. steering is learned, and then, the addition of policy nodes refines the policy in certain regions of the observation space, O. The difficulty of the optimization problem increases with the additional degrees of freedom. However, many of the parameters should be bootstrapped to reasonable values by the previous optimization (for more details, see Section 5.4). Series shaping can also be done by gradually changing the evaluation function and thus increasing the difficulty of the optimization problem. In other words, the criteria of what is considered a good solution is tightened as the series of optimizations progresses. Tevai, For example, the evaluation time, can be gradually increased, so that successively longer trajectories are optimized. Also, the set of initial positions, 5,„jt, can be progressively augmented to provide a denser sampling in interesting areas of the state space. A n early optimization episode would find a coarse policy that can handle some basic situations well. Later episodes would refine the policy to handle more situations, and Chapter 2. POMDP and Policy Search Framework 30 perhaps, more difficult situations than before. Moreover it is often useful to optimize a basic motion behaviour first and then gradually add more restrictive criteria. For instance, one might optimize a vehicle driving policy to first avoid crashing and later consider fuel consumption. In [Gri97], a policy is optimized first to accomplish a basic jumping motion and then style considerations are phased in. Finally, series shaping can be conducted by modifying the difficulty of the R L problem itself. This was done in [RB01], where the weight that the robot was required to lift was increased periodically during the learning process. Another example would be to train a vehicle steering policy on progressively more difficult tracks (e.g., by narrowing the track and adding more corners or making the corners sharper). 2.4 Summary In this chapter, we formalized the concept of the P O M D P , which we use to frame motion control problems. We also discussed value-based methods for solving R L problems, as well as their limitations. We suggested policy search as a promising alternative and covered some of the significant related work in this field. Lastly, we outlined some of the issues in successfully applying policy search to R L problems. Below, we specify how the P O M D P and policy search framework, as well as previous work in these areas, is relevant to our motion control work. 2.4.1 Relevance of Framework Although we use the P O M D P formalism to frame pur motion control problems, we do not attempt to find optimal or near-optimal solutions to the R L problems as is typically the case in R L research. Instead we are interested in finding satisfactory solutions. These are solutions that accomplish the general task that is specified and do so in a way that graceful, robust, and reasonably efficient . 13 Policy search is often used to find satisfactory solutions to practical problems with guarantees of near-optimality being difficult to obtain. Most aspects of the P O M D P formalism, including S, O, A, u>, 7r, and trajectories, will be di- rectly relevant to describing our motion control problems. Some aspects, such as the reward function, r, and the discount factor, 7 , are useful conceptually for constructing an evaluation function, E(&). Trajectory evaluation can be viewed as summing reward along the trajectory and thus approximating the value of the corresponding initial state. The values of other states along the trajectory are also Gracefulness can usually only be evaluated qualitatively, although it is very important for computer animation results. Robustness can be measured by evaluating the policy in a range of situations, particularly those that are not expected to occur during normal policy operation. Efficiency can be measured in terms of the energy used during policy actions. In computer animation, sometimes energy use is minimized with the intention of making motions more graceful. This is because of the reasoning that animals and humans tend to conserve energy in motion if possible. 13 Chapter 2. POMDP and Policy Search Framework 31 being approximated to a lesser degree. We do not use a discount factor for evaluation, but the evaluation time, T i, eva performs a similar function to 7 in that they both specify the short-sightedness of the policy evaluation. One reason that we do not use 7 in evaluating trajectories is that we want the evaluation of decisions at states toward the end of a trajectory to be given significant weight in the evaluation. In this way, a finite number of trajectories, can better evaluate the infinite number of states in the continuous state space. Most aspects of policy search discussed above are directly relevant to our work. We explain our choice of policy representation, the nearest-neighbour policy, in Chapter 3. Specification of the evaluation metric, particularly the trajectory evaluation function, initial states, and evaluation time, is critical to the success of our solution policies. We discuss the evaluation metric in more detail in Sections 3.3.2, 4.4, and 5.3 for the limit cycle tracking problem, the cart and pole problem, and the vehicle steering problem, respectively. The optimization technique used can largely affect the efficiency of convergence to a satisfactory optimum. However, we do not focus on developing or leveraging a sophisticated optimization technique. Instead, we use minor variations on a simple stochastic greedy ascent (SGA) optimization (1). We do, however, customize the algorithm to make local perturbations in the policy for the vehicle steering problem, which is described further in Section C.3. Shaping techniques are crucial for using prior knowledge to solve complex control problems efficiently and we demonstrate the use of a few of these. The choice of policy parameterization and evaluation metric serve to shape the optimization landscape. More interestingly, we adaptively refine policies for vehicle steering by adding free parameters to the policy representation in a series of optimization episodes. This technique, explained further in Section 5.4, achieves shaping by conducting a coarse-to-fine search for a policy. We also choose a vector of observable variables for the vehicle steering that is small and easy to compute and yet provides adequate information for the task. 2.4.2 Related Work We will restrict our discussion of related work to that which is most pertinent or directly influential to our work. The P O M D P and policy search framework that we use is very similar to that used in [Ng03]. In particular, our policy evaluation metric (Equation 2.3) is the same as the approximate utility for policies in [Ng03], except that we do not include the discount factor. However, in our work, we emphasize the choice of initial state distribution, D, as important for shaping the search in complex control. Series shaping has been used to learn motion control in [Gri97] and [RB01]. Shaping is accomplished by phasing style considerations into the evaluation of a hopping motion in the former. In the latter, the physical model is gradually modified by increasing the mass held by a robot arm in order Chapter 2. POMDP 32 and Policy Search Framework to shape the learning of a robot weightlifting policy. In our work, we use adaptive refinement of the policy through progressively adding free parameters into the representation to shape policy learning, as explained in Section 2.3.5. This topic will be further addressed in Section 5.4. Note that an adaptive resolution scheme has been used to partition the state space to find feasible trajectories to goal regions in [MA95]. Also, [MM02] adaptively refines a value function using a tree representation to solve continuous state R L problems. Furthermore, in [AM03], value functions and policies are stored using trajectories and the representation can be refined by adding trajectories to new parts of the state space. The policy search method used to learn walking controllers for a bipedal articulated figure in [Sha04] is similar to the work in this thesis in a few ways. For one, the N N P R is also used to represent policies for the walking problem. A similar evaluation metric that evaluates several trajectories from relevant initial states is used. The optimization technique is also a simple greedy algorithm, although it makes systematic deterministic perturbations, in contrast to the stochastic perturbations of our SGA. Shaping is accomplished by progressively increasing the evaluation time, T i, eva as opposed to progressively adding policy parameters, as we do for the vehicle steering problem. However, a walking policy for bumpy terrain is achieved by duplicating policy parameters in a single episode at the same time that the terrain bumps are introduced, in a similar form of policy refinement. Our N N P R is similar to the stimulus-response representation used in [NM93] and we compare the two representations in Section 3.1. We discuss work directly related to the cart and pole and vehicle steering problems in Chapters 4 and 5, respectively. Chapter 3. Nearest-Neighbour Control Policies 33 Chapter 3 Nearest-Neighbour Control Policies We represent policies using a semi-parametric nearest-neighbour function approximator (NNFA). This representation is local and conceptually simple. Also, we demonstrate the compactness of N N F A in Chapters 4 and 5, as it allows policies for complex control tasks to be modelled using few parameters. Moreover, NNFAs have an advantage over regular grids in that the resolution of the approximation can be varied over the function domain (i.e., they can be adaptively refined). In other words, representational complexity can be concentrated in more interesting or critical regions of the observable state space. Our work applies policy search within the set of policies, ft, that can be represented using an N N F A . The idea is to create a variable discretization of the policy domain, O, such that the policy can be adaptively refined in regions of particular importance . In this chapter, we formally define 1 the nearest-neighbour policy representation and go over some related work. As a concrete example, we present a policy that was synthesized to drive a point mass along a target trajectory and describe the method used to create it. 3.1 Policy Definition We define a policy 7r using a set of n nodes, with each node i having a location Q in the observable state space, O, and an action \n € A. The node locations are used to induce a Voronoi partitioning on O and each Voronoi cell is mapped to the action of its corresponding node. A policy 7r is thus defined by 7T(o) = tl ( ) c c{o) = argmini (\\o <=i<=n 0 - 0\\), (3.1) where c(o) is the active node, given an observation, o. Figure 3.1 shows an abstract diagram of a nearest-neighbour policy. A policy can be specified using the parameter vector, 0 = [Ci. • • •, Cn, Mi> • • • > Mn], consisting of all node locations and corresponding actions. Notice that the number of nodes and location of the In Section 5.4 of the chapter on vehicle steering, we explain how adaptive refinement through the addition of policy nodes can be used to shape the policy search. 1 34 Chapter 3. Nearest-Neighbour Control Policies observation space O action space A Hi Figure 3.1: A n abstract diagram of a nearest-neighbour policy of 3 nodes with a 2-dimensional input state space and 1-dimensional action space. nodes can be chosen to adequately represent the complexity of the required control. For example, a policy for the cart and pole problem was synthesized using just 2 nodes (Section 4.6), while the more difficult problem of steering a single-trailer truck backwards around a track was solved using a policy with 14 nodes (5.5). 3.2 Related Work As in [NM93], a stimulus-response metaphor can also be used to describe the N N P R . The current stimulus, Ot, is found to lie within a Voronoi cell, activating the corresponding node, c(ot), and triggering the associated response, / i ( ) . With the nearest-neighbour representation, the action Hi c 0[ is taken if the corresponding node location, has the minimum distance of any node location to the current state, s . t On the other hand, the stimulus-response (SR) representation used in [NM93] correlates each action with a stimulus function, which maps observable states to a stimulus value. The current action becomes that of the highest-valued stimulus function, only if that value is positive. If no stimulus function is positive the current action remains unchanged. The stimulus functions are positive only within a hyper-rectangle in state space and the maximum value is at the center of the hyper-rectangle. If a hyper-rectangle does not intersect with others any state within it will always map to the corresponding action. However, if two or more hyper-rectangles intersect, the action chosen in the intersecting region will correspond to the stimulus-function with highest value. The boundary between two neighbouring nodes in the N N P R will always be formed of a single hyperplane, Chapter 3. Nearest-Neighbour Control Policies 35 while the boundaries in overlapping hyper-rectangles in the SR representation are more complex. In the SR representation, it is also possible to have states which do not have a corresponding action because they are not within a stimulus hyper-rectangle. If there is no stimulus activated, the action corresponding to the last stimulus will be kept, meaning that the resulting policy is not entirely reactive. A n N N F A can be considered a simple form of locally weighted regression (LWR). A n L W R is a function approximation that fits a model to a local set of weighted data points, rather than attempting to fit a model to all data points. LWRs have been used to represent action-value functions in instancebased learning [SK01, FA02], In these cases, data points are stored for experiences that the R L agent encounters. A regression of neighbouring data points is conducted for each query of the action-value function. A n N N F A is an L W R where only the data point closest (using Euclidean distance) to the query point has a non-zero weight and the value of the data point is used as the constant function approximation in that neighbourhood. For our nearest-neighbour policy representation, we do not use agent experience for data points, but instead we try to optimize the position and value of these data points (which we call nodes) to find an optimal policy given the restrictions of the representation. We are not aware of previous work that uses an N N F A to represent policies. However, the concurrent work on walking policies in [Sha04] also uses the NNFA. 3.3 A 2D Example This example problem is useful for visualizing how a nearest-neighbour policy operates, because the state space, S, is two-dimensional. In this section, we present an example of a resulting policy and also describe the method used to synthesize the policy. Figure 3.2 shows a policy that was synthesized to control the motion of a point mass in one dimension. The goal of the policy is to drive the state of the mass along a cyclical position/velocity profile, shown in the figure as the target state trajectory. Examples of such cyclical one-dimensional motion are the height of a drumstick during a repetitive drumming motion or the height of a water surface at one point when there is a consistently repeating wave pattern. Such a limit cycle is also observed in the various degrees of freedom of a walking person. For example, the angle of the knee follows a consistent cyclical pattern during a walk. Using policy search, we have synthesized nearest-neighbour policies for many such user-specified limit cycles, one of which is shown in Figure 3.2. The algorithm takes a target trajectory as input and outputs a parameter vector, 0 , to represent the generated policy. The number of policy nodes, n, is problem dependent, and matches the representational com- 36 Chapter 3. Nearest-Neighbour Control Policies state trajectory current state (x,x) target state trajectory state flow field node position Q Voronoi cell boundary Figure 3.2: Nearest-neighbour policy for a point mass in one dimension with a 2D position-velocity state space. This policy drives the point mass towards a limit cycle which is meant to approximate the target state trajectory. plexity required to follow the specific target state trajectory . In the following, we discuss the system 2 dynamics, policy evaluation metric, and policy search method used to create this example policy. 3.3.1 Problem Formulation The dynamics for this problem are illustrated in Figure 3.3. The state of the point-mass is given by its position, x, and velocity, x, and this state is directly observable by the policy ir. Thus, o = s = (x, x) £ <5. The control action fit £ A associated with each Voronoi cell i are the parameters, (x, k , kd), for a proportional-derivative controller, used to drive the point mass towards the target p position, x. The force on the point mass is computed as F = k (x - x) - k x, p (3.2) d where k is the spring constant and kd the damping constant . The state transition function v, is 3 p thus given by Equation 3.2 in combination with the physics for a force acting on a point mass in one dimension. In this way, the P D control is considered part of the P O M D P dynamics, and the P D Appendix A explains how the number of nodes and initial node positions is chosen by approximating the target trajectory with a time-based policy. W e did not experiment with using other types of controllers (e.g, PID) to actuate the system, as we obtained successful results using this simple P D controller. In our experiments, the motion that resulted from a nearestneighbour policy composed of discrete PD control actions always converged towards either a single state or a limit cycle, a property useful for solving this particular problem. Interesting future work might involve proving why this is the case. 2 3 37 Chapter 3. Nearest-Neighbour Control Policies state transition function V PD control function —7K i i time step t-i t 1 i Figure 3.3: Dynamics for control of a point mass in one dimension. controller parameters, [x, k , kj), the policy output. Alternatively, one could view the force, F, as p the output of 7r and the P D control as part of the policy structure. 3.3.2 Policy Evaluation Given these system dynamics, we wish to find a nearest-neighbour control policy, n e ft, that moves the point mass in a path that is as close to the target trajectory as possible. We would like the generated policy to be both accurate and robust. When the state is on the target trajectory, it should continue to move along that trajectory. When the state is off the target trajectory, the actual trajectory should converge towards the target trajectory as quickly as possible. We do not impose any form of control energy cost. In the P O M D P framework, a reward function, r(s ,a ) t t = f(s ,^{s ,ai)) t t = f(s ,s i) t t+ 4 might reward the policy for how close s +\ is to the desired state, s +i, given an approximate previous t t state, s , on the target trajectory. This state, s , could be the closest point (e.g., by a Euclidean t t measure) on the target trajectory to s . Figure 3.4 shows graphically how such a reward metric would t be calculated. This reward function would reward the policy for removing error between the current state and the corresponding desired state on the target trajectory. Our policy evaluation function, E(Q), assigns a high utility to policies that drive states on the Note that with a deterministic transition function, v, the state st+i is determined by st and at, so we may use a reward function, f(st, « t + i ) , that depends on the state, st, and its successor, st+i. 4 38 Chapter 3. Nearest-Neighbour Control Policies actual state trajectory target state trajectory Figure 3.4: A reward function for a P O M D P framing of the 2 D trajectory tracking problem. The approximate previous state s is determined by s = o/rgmin s \\s — s \\, where S j is the set of states on the target trajectory. In the figure, d = \\s — s \\ is the distance between s and the closest state on the target trajectory, s . The desired state, s +i, is the state reached by following the target trajectory one time step from s . The reward r is given by r(s ,s i) = - | | s i - s || . t t s& traj t t t tra t t t t 2 t t+ t + t + 1 target trajectory toward their desired successor states. We evaluate the policy by computing trajectories from p initial states, s\ ,l nit < i < p, for T i simulation time steps. The initial states are eva positioned on the target trajectory, distributed at even time intervals, Ti rvai, nte as illustrated in Figure 3.5. The error of the i th trajectory, e(<7*(0)), is computed as: (<7 (0)) = | | 4 _ , ( e ) - 4 _ ( 0 ) | | , I e where sip around the trajectory, 2 1 (3.3) ( 0 ) is the desired final state, or the state that would be reached by following the target trajectory from initial state s\ for T i simulation time steps . The policy evaluation function is 5 nit eva defined as the negated sum of trajectory errors: E(0) = -J2e(* mi (3-4) i=l In this way, a policy is evaluated by how well it tracks the cyclical target trajectory from several initial states distributed on the trajectory. Performance from other regions could also be taken into account by evaluating from initial states off of the target trajectory. Although this was not tried, it would likely result in a policy that is more robust. Policy shaping could be achieved by first evaluating from only on the target trajectory and then phasing in initial states further off the trajectory to gradually incorporate robustness into the policy. However, the policies we generate are surprisingly robust to state perturbations, even though evaluation is only conducted from initial states on the target trajectory. Note that this distance metric is dependent upon the units used to measure distance and velocity. Ideally, the metric should use some kind of normalized coordinates for the state space. 5 39 Chapter 3. Nearest-Neighbour Control Policies target state trajectory (a) (b) Figure 3.5: (a) Initial states and evaluation trajectories. The initial states are Tintervai time steps apart along the target trajectory. Each trajectory is evaluated for T i time steps, (b) Evaluation of a single trajectory. The evaluation error for the trajectory, e(a (Q)), is the square of the distance between the actual final state, s ^ (0), and the desired final state, s ^ {Q), on the target trajectory. eva l z T al l T al The specific parameter settings for our results are time steps. This setting of Tintervai T i eva = 2000 and Ti n t e r v a i = 500 simulation results in about 20 initial states for a typical target trajectory. In other words, it takes about 10000 time steps to cycle once around a typical target trajectory, so T i eva is about g of the total cycle time. This seems to be enough initial states to evaluate the policy in sufficient detail on the entire trajectory. The size of T i eva appears to be a good compromise between consideration of short and long term consequences of policy actions. The result is that small details in the target trajectory may be ignored in favour of following the trajectory better in the long term. However, if the error was integrated over an evaluation trajectory the small details in the relevant area of the target trajectory would be considered. A metric which integrates the error would have an advantage over the metric that we employed in that it would not be as heavily dependent on the choice of Tintervai- 3.3.3 As of yet, we have not experimented with this alternative for evaluation. Policy Search Choosing good initial parameters, Qinit, is important for accelerating the search for a satisfactory policy, especially when the parameter space is large. For this example, the initial parameters are bootstrapped using a time-based policy generated to follow the target trajectory. A time-based policy is a policy for which actions are a function of time, rather than a function of the current 40 Chapter 3. Nearest-Neighbour Control Policies observable state. To avoid diversion from the main subject of the thesis, we defer a more detailed discussion of time-based policies to Appendix A , where we explain how such a policy is generated for the target trajectory, and how it is used to initialize the search. Careful bootstrapping using a time-based policy should give us initial parameters that are fairly close to an optimal n-node nearest-neighbour policy. This good initial starting point for the optimization is critical since the number of nodes, and therefore the number of policy parameters, can be quite large making a naive search of the parameter space nearly impossible . Furthermore, it is 6 difficult to estimate the number of nodes, n, needed to represent a policy that can successfully follow the target trajectory without the first step of finding a time-based policy. 3.3.4 Results We conduct a n S G A optimization to maximize the evaluation criteria, given by Equation 3.4. In this manner, our algorithm generates policies for moving the state of a point mass along a cyclical target trajectory, such as the policy in Figure 3.2. In the figure, note the successful tracking behaviour achieved with what is a sparse control policy representation. The example trajectory begins well off the target trajectory but is rapidly drawn to it. Also, the state flow field indicates the robustness of this policy to unexpected state perturbations, as the flow tends towards the target state trajectory. 3.4 Summary A l l of the motion control problems in this thesis, as well as the walking problem in [Sha04] use the nearest-neighbour policy representation. We have formally described this representation and presented a concrete example of the N N P R in use. In the next two chapters, we look at some positive results of the N N P R and policy search being applied to motion control. Chapter 4 addresses the cart and pole problem and Chapter 5 presents results for vehicle steering. A typical policy for this problem has around 10 nodes. Each node has 2 parameters to locate it within the state space and a 3 parameter action, so the total number of policy parameters is typically around 10 X (2 + 3) = 50. 6 Chapter 4. Cart and Pole 41 Chapter 4 Cart and Pole The cart and pole problem is well-known in the control and reinforcement learning disciplines because of its simple structure and inherent instability. This problem has 4 state dimensions, all of which are observable to the policy. We consider the problem as one that is more complex, in terms of observable state dimensions, than the 2D trajectory tracking problem of Chapter 3, but less complex than the vehicle steering problems described in Chapter 5, which have 5 to 7 dimensions. This chapter describes the cart and pole problem in detail and examines the results of using policy search with a nearest-neighbour policy representation to find a solution. 4.1 Problem Overview For this problem, an inverted pendulum, which is called the pole, is hinged onto a cart that can slide along a track in 1-dimension, as shown in Figure 4.1. The objective is to move the cart to a goal position and keep it there, while maintaining the balance of the pole. This must be accomplished by the careful application of a continuous-valued force, F, to the cart in either direction. Of course, the pole is unstable because gravity will act to increase any deviation from the upright position. If the pole is falling to the left, for instance, a force can be applied to push the cart to the left, which in turn applies a force to the bottom of the pole, acting to keep it upright. If the pole falls to the horizontal position, then it contacts the cart, and the balance of the pole cannot be recovered. This problem is similar to balancing a broomstick on a finger tip by attempting to keep the bottom of the broomstick underneath its center of gravity. However, in this broomstick task, there is no clear goal position and the fingertip can be moved in three spatial dimensions. Section 4.3 will define the problem more formally. As an extension to the cart and pole problem, we allow the cart goal position to be interactively changed by a user. In this way, the cart can be made to follow a trajectory of goal positions. The user can also apply force perturbations to the cart, in order to test the robustness of the learned policy. These interactive extensions are explained further in Section 4.8. Chapter 4. Cart and Pole 4.2 42 Related Work and Problem Variations A version of the cart and pole problem was first studied in the reinforcement learning framework by [BSA83]. In this version, called the pole-balancing problem, the objective was simply to keep the pole from falling below a certain angle to the vertical, while also keeping the cart within set track boundaries. This problem is simpler than ours in that it does not require the cart to be brought to a goal position and kept there. However, our problem does not have the track boundaries, which can serve to make control more difficult. Another difference is that the pole-balancing problem typically allows only a discrete left or right force to be applied to the cart (sometimes referred to as bang-bang control), while we allow a continuous range of forces that can be applied using a P D controller with some parameter restrictions (see Section 4.3). [And87] also looked at the pole-balancing problem, and extended the learning system in [BSA83] by using a feed-forward neural network to estimate value functions. Another version of the cart and pole problem was examined in [DoyOO]. The cart-pole swing-up task, as it is called, involves swinging the pole up to the vertical position from any arbitrary angle by applying forces to the cart. In this version, the pole is permitted to be in a hanging position, below the horizontal. This task is difficult because of its highly nonlinear nature. If the force that can be applied to the cart is limited, the pole must be swung back and forth to bring it to the upright vertical position. Doya used a continuous TD(X) formulation with a normalized Gaussian network to approximate the value function and policy for this problem. Coulom also solved the cart-pole swing-up task using the continuous TD(X) algorithm, but with a neural network representation of the value function[Cou02]. In the control literature, the cart and pole problem, which is often called the inverted pendulum problem, is usually viewed as the problem of removing error in the pole angle by pushing the cart with a real-valued force, similar to the pole-balancing problem described above except without track boundaries. It is considered a particularly interesting problem because of its instability, nonlinearity, and similarity to the problem of balancing a missile atop a booster rocket [DW91]. If the angle and angular velocity of the pole are assumed to be small then the problem can be approximated as a linear system and analyzed using linear control theory. For example, in [Oga70], conditions for constants of a P D controller that would insure stability of the pole for a small range of operating conditions were derived. In [DW91], the constants for a P D controller that was able to recover from a large range (up to 80 degrees from the vertical) of pole angles were determined experimentally. However, a pole-balancing problem does not consider simultaneously removing error in the cart position and pole angle, as does our version of the problem. [SSR99] solved this more difficult problem 43 Chapter 4. Cart and Pole using a nonlinear optimization technique on a fuzzy logic controller. The controller is bootstrapped using a optimal control table estimated by using dynamic programming on a cell discretization of the state space. The controllable region of the state space for their optimized controller was found to be significantly larger than that of a linear quadratic regulator (LQR)'that was analytically derived using a linearization of the dynamics. We have not undertaken a detailed comparison between the controllable regions of a L Q R or other control technique and our learned policy. Particularly with pole swing-up problems, nonlinear control must be employed to bring the state of the system close to the goal state, where a linear controller is capable of stabilizing the state of the system. For example, in both [Sti99] and [RK03], a pole is swung up from a hanging position by a nonlinear control technique and once the pole is near the standing position a L Q R is used to stabilize it. The cart and pole problem can be made even more difficult by attaching a second pole on top of the first. This inverted double pendulum system is very unstable in a similar way to backing up a double trailer truck, which is the problem we look at in Section 5.5 of the next chapter. In [RN0098], fuzzy control rules for controlling such a system are acquired automatically using genetic algorithms. 4.3 Problem Formulation The state, s, of the cart and pole is represented by the vector (x, x,a,a), where x is the position of the cart relative to a fixed reference position , x is the velocity of the cart, a is the angle of the pole 1 relative to the upright vertical position, and a is the angular velocity. This setup is illustrated in Figure 4.1. This state is fully observable to the policy, i.e., o = s. reference position ' x cart Figure 4.1: Setup of the cart and pole problem. In our problem formulation, a policy controls the cart indirectly through a P D controller. Thus, the action Hi € A of a policy node is the parameters, (x, k , kd), of the P D controller. The force, F, p 1 A n extension where the reference point can be interactively moved is discussed in Section 4.8 44 Chapter 4. Cart and Pole on the cart is then calculated as F = k (x — x) — kdi. p The force, F, acts to accelerate the cart. It also indirectly causes a horizontal force to be applied to the bottom end of the pole, which interacts with the force of gravity to determine the angular acceleration of the pole. The equations of motion of the cart and pole are given i n Appendix B . Figure 4.2 illustrates how the state of the cart-pole system will evolve over time. state transition function V (x,X, cart-pole equations of motion OC, Ci)f.j ^XyXy OC} C^^^^~ > observation function (0 = 1 policy 7t (x^ X OCj OC) t-j f (x,kp,kd)t-j time step t-l j Figure 4.2: Dynamics for the cart and pole system. The policy's objective is drive the state of the system towards the goal state, s* = (0,0,0,0), in minimal time. The goal state is characterized by having the cart stationary at the reference position with the pole upright and not falling in either direction. For the cart-pole system to be controllable with reasonable limits for F the pole should always be close to the upright position and without large d, especially in the direction the pole is leaning. If the pole angle reaches 90° from the upright position it hits the cart and cannot swing through. The simulation is ended as it is impossible for the pole to be pushed up from a horizontal position. 4.4 Policy Evaluation In practice, the goal state, s*, is unstable and the trajectory of a good policy will oscillate around it. In the P O M D P setting, it would be sensible to have the reward function, r, give positive rewards to i a region of states that is close to s* and zero reward to any state outside of this region. The reward in the goal region would be larger the closer the state is to s*. The policy could be encouraged to 45 Chapter 4. * Cart and Pole drive the state to the goal region quickly by making the discount factor, 7 , less than 1. Additionally, it would be useful to penalize the policy if the pole falls over . This would shape the problem by 2 encouraging the learning of pole-balancing explicitly. In unstable systems, such as the cart and pole, backwards truck-driving, or biped walking, balance is critical to success and should be learned by the policy early. Our policy evaluation metric, E(Q), is based on similar ideas as the above reward function . 3 A policy that drives the state close to s* within a fixed evaluation period, T i, eva is favoured. A n additional penalty is applied if the pole falls during this period. To encourage balancing the pole for as long as possible, the penalty is proportional to the time remaining i n the evaluation period when the pole falls. The policy is evaluated from p initial states, each resulting in a trajectory. The weighted error of the i th trajectory is given by e(cr (9)) = w u(T i l fa eva - tf ii) + w x* ^ a x T + Wii?^ ai + wa ^ l a T ai + Wad , z Teva[ where Wf ii, w , w±, w , and Wa are weights for the error terms and a x a feai« is the final state of the i th XT^i > T „ Q e a i , 4 evaluation trajectory . 4 e „ , ) = 4.„ a l (©) The variable tf u measures the time when a a reached 90°, if the pole fell during the evaluation period, and tj u = T i, otherwise. We define the a eva evaluation function to return the negated sum of all the trajectory errors just as in Equation 3.4: E{Q) = -JTe\Q). The p initial states are at fixed intervals across a range of cart positions, [—xu i ,xii i ], m t m t with x, a, and a always initialized to zero. The distance between two neighbouring initial cart positions is x p . S ace This simple distribution of initial states allows evaluation from a fairly broad range of states that can almost certainly be controlled. A typical issue for evaluating policies is the range and density of initial states from which to evaluate. Including states that are difficult or impossible to control not only increases the computation required for each evaluation but can also complicate the search process. We shape the policy search by phasing in more difficult initial states through a gradual increase to xu it m (see Section 4.5). Our evaluation does not consider the potentially more difficult initial states, where a or a are nonzero. Considering these states, at least later on in the In the original R L problem of pole-balancing [BSA83], the only reinforcement was a penalty for pole falling over Note that the specific policy evaluation parameters used to obtain our results are included in Table 4.1 Our policy search finds fairly robust policies (see Section 4.6) using a light-weight evaluation that considers only the final state of each trajectory. However, integrating the error over the entire trajectory might better ensure that the resulting policy brings that state of the system, s, to the goal state, s', as quickly as possible and stabilizes it there. We have not experimented with this alternative. 2 3 4 46 Chapter 4. Cart and Pole search process, would most likely result in a policy that is more robust (i.e., with a larger region of controllable states). However, currently our evaluation metric only considers the simple distribution of initial states described above. 4.5 Policy Search The policy search algorithm we employ is straightforward. The specific policy search parameters used to obtain our results are included in Table 4.1. The policy parameters, ®i it, n are given sensible but highly untuned initial guesses. We employ series shaping by increasing the range of initial states for the policy evaluation at each optimization episode. Within each episode, we conduct an optimization on the policy parameters using an algorithm very similar to the SGA, as presented in Algorithm 1 in Chapter 2. Throughout the entire search, the step size, p, of the stochastic perturbations in policy parameters is decayed. Pseudocode for the policy search is given in Algorithm 2. 2 Cart-Pole Policy Search i n p u t 7r {policy} i n p u t xumit {the limit on the initial position of the cart for evaluation} i n p u t Xi {the amount that xu i is incremented for each episode} i n p u t p {step size} i n p u t A {decay factor} i n p u t btotai {number of iterations per optimization episode} input c {number of iterations without improvement before p decay} i n p u t dtotai {total number of optimization episodes} define c < — 0 {number of iterations without improvement} Algorithm m t nc step f o r d <— 1 to Ebest dtotai <— do E(n.Q,Xu it) m f o r b * - 1 to btotai do ^new <- perturbationl(n, Enew if E E(^7T .0, < n e > Ebest w 7"* * p) Xii it) m new then l^new Ebest •* E n e w c<-0 else c <- c+ 1 end if i f c 7^ 0 and c tep = c mod s p = Xp end end ^limit end if for * for O u t p u t 7T %limit "f" Xi nc 0 then 47 Chapter 4. Cart and Pole We initially allocate 2 nodes to the policy and make reasonable guesses for the parameters, 5 . Qmtt In this way, we use some prior knowledge of solution structure to bootstrap the search. The values chosen for the parameters, are very approximate, since we rely on the policy search for Qmit, fine-tuning. Initial parameters for a successful search are shown in Table 4.1. W i t h only 2 nodes it is reasonable that one generally push the cart to the left and the other to the right . Thus the P D 6 target, x, of node 1 is initialized to be negative and that of node 2 positive. The P D constants, k p and kd, for both nodes are set to the same intermediate values. The only other knowledge built into the initial parameters is that extreme situations should be countered with a force in the reasonable direction. For this reason, we initialize the location, £i, of node 1, such that node 1 will be activated to push the cart to the left if the cart is positioned to the right and moving further right or the pole is leaning to the left and rotating further to the left. To do this, we set the node location, Ci, to have a positive cart position, 'x, and velocity, x, and a negative pole angle, a, and angular velocity, d. The initial location for node 2, is simply that of node 1 but mirrored about the state space origin. These initial node locations and actions, although very coarse, provide an estimate of a decent 2-node policy that can aid the beginning of the search. To shape policy learning, we conduct the search in a series of d tai optimization episodes. With to each episode, the range of initial cart positions, [—xii i ,xu it], m t increased by incrementing xu i m t m considered in the evaluation is by x , . In this manner, the initial episode focusses on states that n c are close to the goal state, s*, and relatively easy to control. Each subsequent episode adds states further away from the goal, thus increasing the difficulty of the control task. However, the policy parameters from the previous episode are carried over, providing a good initial starting point for the next episode. Another way to perform series shaping would be to refine the granularity of the policy representation by adding nodes at each optimization episode, as is done for the vehicle steering policy search and described in Section 5.4. For this problem, we do not experiment with adaptive refinement, so the number of nodes, n, remains 2 throughout the policy search. Each episode is conducted as a slight variation of SGA, which optimizes policy parameters 6 = [CiiC2,P-i, 1^2] with regard to the evaluation function, E(Q). A n episode corresponds to a single iteration of the outer loop in Algorithm 2. For this problem, the algorithm does not use a convergence check as in Algorithm 1, but instead runs for a fixed number of iterations, b tai- Also, the perturbation to step size, p, is not decayed every iteration, but only after c step iterations have elapsed since the last policy improvement or step size decay. Finally, the perturbation algorithm is slightly modified because T h e initialization of the policy parameters is not included in the Algorithm 2, since this could easily be replaced with another suitable initialization. Here, we use the term left to mean "in the negative x direction" and right to mean "in the positive x direction". 5 6 48 Chapter 4. Cart and Pole the policy parameters are not normalized and the details are included in Appendix B.2. 4.6 Results Our policy search algorithm can find a 2-node policy that works well for a limited range of initial states. We used the evaluation and search parameters shown in Table 4.1. The search required 16000 total policy evaluations. Figure 4.3 shows the best overall evaluation, E(Q), as the policy search progresses. For later episodes, E(Q), represents a more difficult evaluation that takes into account a broader range of initial states, which is why the best value of the policy may drop at the beginning of an episode. -o.ol- Episode 3 (x -0.1 Umit = 0.3) © W > o OH -10 Episode 2 (x limit Episode 4 (x , = 0.4) = 0.2) Umi -100 Episode 1 (x limit 2000 4000 = 0.l) 6000 8000 10000 12000 14000 1600C Policy Search Function Evaluations Figure 4.3: Policy performance versus evaluations during the policy search for the cart and pole system. Note that for each subsequent optimization episode the range of initial cart positions, [—xii it,xu it} is expanded, thereby making the control task more difficult. m m The parameters of a learned policy are also listed in Table 4.1. A state trajectory of this policy converging toward the goal state is shown in Figure 4.4. Figure 4.5 evaluates the robustness of a generated policy, by showing the range of controllable states, where the initial cart velocity, and the initial angular velocity, Xmit, are zero. A state, Si u, is considered to be controllable if after n 10 s of simulation time the policy has brought the system state from Si u to a goal region specified n 49 Chapter 4. Cart and Pole Vdues Problem Parameters Cart Mass (kg) Pole Mass (kg) Pole Length (m) 1 0.1 0.5 0.1-2.0 0.1-2.0 0.001 Allowed Range of Spring Constants (1/s ) Allowed Range of Damping Constants (1/s) Simulation Time Step (s) Evaluation Parameters Equation Time T i (s) Space between Initial Cart Positions x (m) Error Weight for Pole Falling w Error Weight for Cart Position w Error Weight for Cart V docity wError Weight for Pole Angle w Error Weight for Pole Angular Velocity Search Parameters Initial Action for Node 1 p., = (x,k ,k ) Initial Action for Node 2 ^ = (x,k ,k ) Initial Location for Node 1 = (x,x,a,a) Initial Location for Node 2 £ = (x,x,a,a) Step Size p Decay Factor X Total Iterations per Episode b i Iterations without Improvement before Decay c Total Episodes d Initial Cart Position Range x (m) Cart Position Range Increment x (m) Results Optimized Action for Node 1 \\, =(x,k ,k ) Optimized Action for Node 2 U2 = (x,k ,k ) Optimized Location for Node 1 = (x,x,a,a) Optimized Location for Node 2 £ = (x'x ,a,a) Total Policy Evaluations 15 0.01 1 1 0 1 0 ma space faU x K a p p d d 2 ata step mal iMt inc { p p r { 2 d d (-0.4, 0.5, 0.5) (0.4, 0.5, 0.5) (0.1,0.05, -0.1,-0.05) (-0.1, -0.05, 0.1,0.05) 1 0.91 4000 200 4 0.1 0.1 (-0.4037, 0.5844, 0.6894) (0.6832, 0.4297, 0.5086) (-0.0112, -01928, -01358, -0.1320) (0.0173, -0.1412, 0.2203, 0.0664) 16000 Table 4.1: Simulation parameters, evaluation parameters, policy search parameters, and numerical results for the cart and pole problem. by |a;| < 0.02, \x\ < 0.003, \a\ < 0.005, and | d | < 0.005. While the learned policy is quite robust in controlling a wide range of initial cart positions, it is less robust in controlling error in pole angle. B y comparison, the optimized fuzzy logic controller in [SSR99] was capable of controlling a much larger 50 Chapter 4. Cart and Pole angular error. However, their controller was allowed to apply a force of up to 50 Newtons (N) in either direction, while our policy was limited by the strengths of the component P D controllers, i.e., by the constraints on the constants, k and kd- The operation of our learned policy typically results p in a maximum magnitude of about 0.6 N being exerted by the P D controllers. •8 '3 0.1 Simulation Time t o Figure 4.4: Example state evolution for a learned policy controlling the cart and pole system from and initial state with x t = 0.230496, x t = 0.001754, a , i = 0.015482, and Q ; = 0.000626). This shows the cart converging towards the goal state, s*. x is measured in meters (m), x in meters/second(m/s), a in radians (rad), a i n radians/second (rad/s), and t in seconds (s). ini ini n t n i t 51 Chapter 4. Cart and Pole 0.1 t 1 1 1 1 1 1 1 1 r 0.08 Uncontrollable Region 0.06 0.04 ° 0.02 u ^ o Controllable Region ° -0.02 Ph -0.04 Uncontrollable Region -0.06 -0.08 -0.1 _1 -1 I -0.8 I -0.6 I I I -0.4 -0.2 0 I 0.2 I 0.4 Initial Cart Position 1 I 0.6 0.8 1 3 1 x init Figure 4.5: Region of initial cart positions and pole angles for which the system is controllable using the learned policy. For all initial states tested, Xi i = 0 and c\i i = 0. The cart position, x, is measured in meters (m) and the pole angle, a, in radians (rad). n t 4.7 n t Discussion and Future Work We looked at solving the cart and pole problem as a proof of concept of our nearest-neighbour policy representation and policy search algorithm. We were most interested in applying the N N P R to steering vehicles, as will be presented i n Chapter 5. We did not perform a thorough analysis of using nearest-neighbour policies for the cart and pole problem and we did not undertake a careful comparison with other control methods that solve a similar unstable, nonlinear control problem. It would be interesting to compare the performance of our policy representation with that of a simple linear controller with similar constraints on the force, F, that can be applied. A linear controller would probably be more efficient than our learned 2 node policy which relies on a rapid alternation between opposing forces, a behaviour which is described in Section 4.7.1 below. Our N N P R can be viewed as a mixture of limited linear controllers, each of which operates in a different 7 Voronoi region of the state space and has a distinct target cart position. Since our policy represenation T h e PD controller components are linear controllers with a force output that is only dependent on the cart position, x, and the cart velocity, i , rather than the full system state. 7 52 Chapter 4. Cart and Pole is richer than a single linear controller (with similar constraints on the observable variables and constants), we speculate it would be capable of performing better on the cart and pole task. However, this needs to be validated experimentally, especially since it is not clear that our search algorithm finds a globally optimal nearest-neighbour policy. Because we obtained a reasonably successful policy using only 2 policy nodes, we did not attempt to refine the policy using additional nodes. In future work, we might look at how policy refinement affects the range of controllable states (see Figure 4.5), as well as the efficiency of the policy operation. The following section discusses the learning and behaviour of the 2-node policy. 4.7.1 A 2-Node Policy It is interesting that a policy with just 2 nodes is able to solve a seemingly nontrivial problem like the cart and pole problem. The following is a qualitative description of its operation in driving the system state towards the goal, s*, from an initial state with x ^ 0, x = 0, a = 0, and d = 0. The policy begins by moving the cart directly away from the target position, so that the pole begins to fall towards the target position. During this period, typically only a single node is active. For the rest of the state trajectory, the policy rapidly alternates (chatters) between the action of the two nodes. The policy begins pushing the cart back towards the target position with the pole now leaning in the direction of motion. As the cart is approaching the target position, the policy will have accelerated enough so that the pole is now leaning away from the target position and against the direction of cart motion. This will allow the policy to decellerate the cart without the pole falling forward. The policy tends to overshoot the target position, and the cart begins to oscillate back and forth around the target position, with the pole counter-oscillating to lean towards the target position. The motion of the cart is damped until the oscillation around the target position is very small, i.e., within the numerical precision of the simulation. This description approximately matches the state trajectory shown in Figure 4.4 except that, in the figure, the pole begins leaning away from the target cart position, meaning that the policy must initially push even further away from the target position than if the pole began upright. Most of the time while the trajectory is converging on the goal state, s*, as illustrated in Figure 4.6, the policy is chattering between the actions of the two nodes. While this chattering occurs, the state trajectory is following the boundary between the two corresponding Voronoi cells . This boundary 8 is a 3-dimensional hyperplane in the 4-dimensional state space. So, altogether, a trajectory from an initial state to s* consists of the first section, where one node is activated to drive the state towards Note that a more energy efficient solution would better dampen the oscillation along the boundary and follow it more directly. For more discussion of chattering see Section 6.1. 8 Chapter 4. Cart and Pole 53 Figure 4.6: Trajectory following the Voronoi cell boundary to the goal region, (a) The state is first driven from the initial state towards the Voronoi cell boundary by the action of one Voronoi node, (b) Once at the boundary the state is pushed along the Voronoi boundary by actions that alternate between the two nodes. The state converges on the goal state via the Voronoi boundary. the cell boundary, and the rest, which follows along the boundary towards s*. It is suprising that it is possible to easily get from a range of controllable initial states to this hyperplanar boundary and then follow it all the way to the goal region . This means that this boundary must intersect the 9 goal region, lie within reach of all controllable initial states, and the trajectories taken through the boundary must all be in the region of controllable states. To test the conjecture that the s* lies close to the Voronoi boundary, we calculated the squared distance from the node locations to s* and found them to be near equal: | | d - s*|| = 0.073163 ~ |C - s*\\ = 0.73178. 2 2 2 The policy search arrives at polices with the above-mentioned strategy through perturbations of the policy parameters. Perturbing node positions, Q, usually moves the Voronoi cell boundary. The boundary must intersect the goal region, so s* can be reached by following the boundary. Perturbing action parameters, mainly affects how trajectories interact with the boundary. Actions are found so that the states close to the boundary are driven towards it. Of course, once the state is near the boundary chattering results in a trajectory along the boundary. The actions must be chosen so that this trajectory converges on the goal region. It would be interesting to investigate how this convergence from controllable states within the boundary to the goal region occurs. 9 B y goal region we mean a small neighbourhood of states near s*. 54 Chapter 4. Cart and Pole 4.8 Interactive Extensions We have developed a cart and pole simulation in a interactive G U I framework that allows the user to better explore the capabilities of the solution policy. For example, the reference position, as shown in Figure 4.1, can be changed interactively by the user and the policy will react by driving the system state towards the latest reference position. In this way, the cart can be made to track a trajectory of reference positions, all the time with the pole remaining upright . This sort of interactive control 10 would be very useful for a more complex domain, such as the animation of biped walking. The underlying policy would be responsible for controlling the balanced and physically realistic motion of the biped towards a reference position. The animator would then be able to interactively move the reference position so that the overall result would be a physically realistic walk that approximately follows the motion trajectory laid out by the animator. We note that the idea of tracking a trajectory of goal states is not new, particularly for robot motion execution. Another feature of our framework allows the user to apply random force impulses to the cart to interactively test robustness of the controller in this regard. The user is also able to change elements of the system state, such as the cart velocity or pole angle, simply by clicking and dragging on graphical indicators of these state variables. This allows the user to test policy robustness to various kinds of system state perturbations. A T h e pole will stay balanced as long as the user does not drag the reference position far enough away from the cart position that the system is no longer in a controllable state. 1 0 55 Chapter 5. Vehicle Steering Chapter 5 Vehicle Steering In this chapter, we describe the use of our policy search method to learn nearest-neighbour policies for steering cars and trucks both backwards and forwards down a winding track. To illustrate the type of steering problems we consider, Figure 5.1 shows the steering behaviour for policies trained to drive trucks backwards on a class of tracks. Such vehicle steering problems are part of a class of problems known as non-holonomic control problems because the instantaneous direction of the vehicle motion is constrained . The steering problems have from 5 to 7 observable state dimensions, 1 so in this regard, they are the most complex control problems examined in this thesis. (a) (b) Figure 5.1: Steering backwards-driving trucks along unfamiliar tracks: (a) One-trailer truck (b) Twotrailer truck. A car or truck is capable of only moving forwards or backwards, perhaps along a circular arc if it is turning, but not sideways. For a more detailed discussion of nonholonomic constraints, see [Lat91], p. 27 and 406. l 56 Chapter 5. Vehicle Steering The steering policies are provided with local observations of the track (see Figure 5.3) and must produce steering commands that will navigate the vehicle down the track without it crashing into track barriers. The fact that a policy is given only a local state representation is important for several reasons: 1. A reactive policy that uses only local state information is limited in anticipating future situations to decide on a current action. For example, a policy does not know what is coming up around a corner in deciding how wide to take the turn. 2. The limitation of the policy to fairly realistic sensory information makes it easier to apply to 2 . real world automatic steering problems. Also, if global state is not required then localization of the robot relative to the global coordinate frame is unnecessary. 3. A policy that relies only on local state is better able to generalize to similar situations on the same track or another track entirely. Furthermore, such a policy is better at reacting to unexpected changes in the environment because it does not base its control decisions on global environment information that may have become outdated. (b) Figure 5.2: (a) Jack-knifing of a truck driving backwards when the steering is kept fixed, (b) Jackknifing of a two-trailer truck driving backwards. Of the steering problems considered, the steering of a backwards-moving truck-with-trailer is particularly difficult because of the inherent instability in the motion of the trailer(s). Figure 5 shows Although our vehicle observations are realistic in that include only range data and internal angle measurements, we have not considered sensory noise, which is an important issue in robotics. 2 Chapter 5. Vehicle Steering 57 how backwards-moving trucks can jacknife without corrective control. The trailer is unstable in much the same way that the pole is unstable in the cart and pole problem. However, in the case of a truck, this instability must be controlled through setting the angle of the steered wheels on the cab of the truck. The requirement that the trailer instability must be handled at the same time as navigating the truck around sharp corners makes this problem a considerable challenge. Adding a second trailer to the truck increases the instability further, making the problem even more difficult. 5.1 Related Work Nonholonomic systems, such as the truck-and-trailer configurations with which we experiment, have been the focus of much research over the past 15 years. One common approach to controlling these systems is to use a trajectory-planning stage followed by a trajectory-tracking scheme. [Lat91] describes motion planning methods, which plan a trajectory that brings one or more objects from one configuration to another while avoiding obstacles and possibly subject to holonomic or nonholonomic constraints. Suchmotion planning techniques can be used to plan a trajectory for a nonholonomic vehicle that results in a desired state. [KN03] examines the problem of determining a control input in real time to bring a model of a nonholonomic vehicle from an initial state to a goal state. Errors in execution of the trajectory are not taken into account, but trajectories can be replanned in real time to consider new information in a changing or unknown envirionment. In [DW97], the problem of parallel parking or docking (see the "truck backer-upper" below) nonholomic vehicles with zero, one, or two trailers is solved by planning a trajectory offline and using a linear quadratic regulator to track the trajectory. The trajectory-tracking system is tested online using a real tractor-trailer robot. [ASW01] develops a controller to stabilize the motion of a real truck-and-trailer robot driving backwards along a path formed of lines and arcs of circles. A l l these methods are dependent on trajectory-planning, which requires a world model. With our reactive, sensor-based approach to steering we wish to avoid construction of a world model or localization relative to an a priori world model. Policy search is another approach to solving nonholonomic control problems. For example, policy search has been used to solve variations of the "truck backer-upper" problem presented in [NW89, Koz92, HFGS96, HGS97]. In general, the goal is to backup a one or two-trailer truck such that the end of the last trailer approaches a goal position, which represents a loading dock. Most versions of this problem assume knowledge of the global state of the truck[NW89, Koz92]. [NW89] used selflearning of a neural network policy and [Koz92] used genetic programming to solve this problem. [HFGS96, HGS97] does not assume global state but does allow the self-organizing neural network 58 Chapter 5. Vehicle Steering controller access to the angle of the last trailer with respect to the goal state. [HFGS96] describes learning a controller on a real tractor-trailer robot as well as in simulation, while [HGS97] solves the more difficult problem of backing-up a two-trailer truck, but only in simulation. We also use policy search to find controllers for backing up tractor-trailer vehicles but, in contrast to these examples, our steering problem is defined in terms of steering performance around a sharply-curved track rather than that of reaching a single well-defined goal state. Furthermore, we require our controller to work with only local sensory information instead of global state information. T D learning, a valued-based R L method, has been used to learn policies that manoever cars in the Robot Automobile Racing Simulation (RARS) setting [Cou02, PH98]. Table 5.1 compares the problem of car control in R A R S to our vehicle steering problem. The physical model of car motion and control in R A R S is similar to a point-mass space-ship model. The magnitude and direction of the car acceleration is controlled directly within constraints imposed by engine power and tire slippage . 3 In our problem formulation, we assume a fixed vehicle speed and no tire slippage. However, we assume strict nonholonomic constraints, which are neglected in the R A R S model. The tracks in R A R S have rounded corners of various radii while our tracks have sharp corners, which are generally right-angled. Policy Representation Policy Learning Vehicle Types Vehicle Motion Physical Model Vehicle Control Observation Model Track Style Track Generalization Our Vehicle Steering nearest-neighbour direct policy search car, single-trailer and double trailer trucks forwards or backwards constant vehicle speed, no tire slippage , steering angle distance sensors truck hitch angles sharp corners generalizes well Car Control in R A R S neural network approximation of value or Q function TD(X) value-based R L method car forwards point-mass space-ship model, frictional model of tires car acceleration car position and velocity relative to local track features round corners of various radii no mention of evaluation Table 5.1: Our vehicle steering problem versus car control for R A R S [Cou02, PH98]. In the R A R S problem, actions are learned based upon information about the car's position and velocity relative to local track features. In [Cou02], the car's curvilinear distance from the start line of the' track is also available to the policy. Both of these methods assume knowledge of the local track curvature and learned policies are only tested on the same tracks that were used for training. We develop solutions based on simpler sensory information provided by a set of distance A simplified model of the RARS dynamics is described in [Cou02], p. 110, while a more complete version of the RARS dynamics can be found at http://rars.sourceforge.net/. 3 Chapter 5. Vehicle Steering 59 sensors, and measurements of the current steering angle and internal hitch angles for the trucks. Also, we demonstrate that a learned steering policy is capable of generalizing to new tracks that are similar variations of the training track and coping with unexpected situations for which it was not trained. Moreover, we apply our steering method to significantly more challenging models, such as backwards-moving tractor-trailers. 5.2 Problem Formulation Figure 5.3: Truck sensory information. We work with several steering problems, including steering cars and trucks both forwards and backwards. For clarity, we will initially emphasize the specific problem of steering a truck-withtrailer backwards around a winding track. Appendix C.2 contains a detailed description of the vehicle dynamics. Physical constants and other important simulation and optimization parameters used for the various vehicle steering problems are included in Table 5.2. The truck observes a local model of the track in the direction of travel using an array of distance sensors, d\,.., ,d^. Each of these sensors has a sweep of 22.5° and returns the distance of the closest object (i.e., part of the track barrier) within this range. A diagram of the truck with sensors is shown in Figure 5.3. A truck observation, o, consists of the vector (a, (3, di, d%, d$, di), where a gives angle 60 Chapter 5. Vehicle Steering 0.8 0 20 40 60 80 100 120 140 160 180 200 Simulation Time Step Figure 5.4: Steering Angle versus Simulation Time Step for a forward-driving car steering policy. of the steered wheels (front wheels of the cab) relative to the long axis of the cab, and (3 gives the angle of the trailer relative to the cab. A truck action, a, consists of setting a desired steering angle, a for the steered wheels. The angle of the steered wheels, a, is not set directly, because this would cause an unrealistic jump in steering direction. Instead it is driven towards the desired angle a by the following dynamical system, which is the equivalent of a P D controller: a = k (a — a) — k^a, p where k p (5.1) and kj. are treated as constants for a particular steering problem. Figure 5.4 shows the relationship between a and a during the simulation of the steering of a forward-driving car by a learned policy. A truck-steering policy, ir : O —> A, maps an observation, (a, P,d\,d2,d^,d^), to a desired steering angle, a. Given the steering action of the policy, the simulation can determine the next system state by using Equation 5.1 to calculating the angular acceleration of the steered wheels, a, and integrating the vehicle dynamics, as illustrated in Figure 5.5. The truck dynamics assume that the front axis of the truck cab moves at a fixed speed in the 61 Chapter 5. Vehicle Steering state transition function V PD control function i i time step t-l 1 i t Figure 5.5: Dynamics for the vehicle simulation. backwards direction of the steered wheels. The tires of the truck cannot slip, so the speed of the truck is of no consequence with regard to traction during cornering. In fact, the speed is only important because of the discrete time approximation of the dynamics and also because of the delayed effect of steering actions. If the fixed speed parameter is increased the steering response will further lag behind the relevant track situation, increasing the difficulty of the problem. However, the steering response could be scaled to match the vehicle speed by adjusting the constants k and kd in Equation 5.1. p The truck continues at a fixed speed until it crashes into a track barrier or jack-knifes, at which time the truck's motion ceases. Both of these events are referred to as a collision. A truck is considered to have jack-knifed if a trailer angle exceeds 90°. 5.2.1 Vehicle Tracks The truck steering problem we address involves driving around a sharp-cornered track without a collision. The truck is always located between the two side barriers of a track. The track is a circuit, consisting of straight segments connected by right-angled corners, as shown in Figure 5.6 . 4 Our goal is that learned policies will be able to generalize their steering control to different tracks with similar properties to the track on which the policy was trained. In order to generate tracks of various classes, we use a parameterized track generator. The parameters that define a track class include the track width, Wtrack, the minimum track segment length, l in, and maximum track m A l l tracks that we have used for training have right-angled corners, although we have tested some of the learned policies on tracks with corners of varying angle, as is shown in Section 5.5 4 62 Chapter 5. Vehicle Steering 0 Figure 5.6: A n example of a complete track for backwards truck-steering. segment length, / m o x . For example, Figure 5.7 shows instances of 3 different track classes. We have also tested steering policies on tracks with varying width and varying turn angle. These track classes have parameters for minimum and maximum track width, as well as minimum and maximum corner angle. Although a detailed description of the track generation algorithm is beyond the scope of this thesis, the following is high-level overview of how a track with fixed width, w ck, and right-angle tra corners would be generated. The algorithm begins by sampling the length of the first segment from a uniform distribution over the range [l in> l ax\- The first segment is placed and a left or right corner m m is chosen with equal probability. Then the length of the next segment is sampled and it is attached to the first such that it points in the correct direction. The track is grown by recursively attaching track segments until the end of last segment is close to the first segment and perpendicular to it. The first and last segments are then stitched together to form a complete circuit. If a newly generated track segment intersects another during the track generation, that segment is removed and another segment is generated. If at any stage of the recursion it is found that the algorithm is failing to connect up the track after a fixed number of attempts, back-tracking is performed so that a different path of track segments may be tried. The entire algorithm may return failure after a number of attempts at generating a complete circuit has failed. 63 Chapter 5. Vehicle Steering _l n (a) (b) (c) 13 B Figure 5.7: Tracks from 3 different track classes, all with right-angled corners and fixed width: (a) wtrack — 1-2, l in = 0.1, and l = 2.0 (b) w = 1.2, l = 1.0, and l = 4.0 (c) IMtrack — 2.4, Imv m 5.2.2 max track min max Policy Representation We will be using the nearest-neighbour policy representation to define steering policies for this problem. Each node i will have a location Ci in the observation space, O. As an example, for the truck, C,i = (a,P,di,d,2, d3,d,4)i. Each node i will also have a corresponding action, fn G A, where m = dj sets the target angle for the steered wheels. This means that the observation space will be carved up into Voronoi cells, each cell i corresponding to the node i. When the current observation o lies t within a particular cell i, the policy will act by setting the target steering angle to d;. We enforce solutions to the vehicle steering problem to be left-right symmetric. O n any particular Chapter 5. Vehicle Steering 64 Figure 5.8: Symmetric observations of the truck policy. cyclic track it may be advantageous to steer asymmetrically, for example, if the track has a counterclockwise flow so that most corners are left-handed. However, we want steering policies that generalize to any track of the same class, including one that is an exact mirror image (i.e., all left-hand corners are replaced with right-hand corners, and vice versa) of the track on which the policy was trained. Since the dynamics of the vehicle are symmetric (see Appendix C.2), and the class of possible testing tracks is symmetric (it includes mirror images of all tracks), it makes sense to enforce left-right symmetry in the policy. For example, if the policy makes a particular left turn by executing a series of actions, it should make a symmetric right turn by executing the exact opposite actions, i.e. setting the target steering angle, d , to the negated values. More formally, a policy for truck-steering is left-right symmetric, if and only if, for all observations o = (a, f3, d±, cfo, 0I3, Ai), if 7r(o) = d then 7r(o). = — d , where 0 = (—a, —(3, d i , cfa, cfa, d\) is the mirrored observation of o. Figure 5.8 shows an example of a mirrored observation and gives some intuition as to why it takes this form and why a left-right symmetric policy is a useful constraint for steering policies that generalize to various tracks. In only considering left-right symmetric policies, we simplify the problem, since the search does not need to discover the benefit of this symmetry. Left-right symmetry is enforced through the pairing of policy nodes. Given n node pairs, every node j, 1 < j < n, has a partner node n + j, for a total of 65 Chapter 5. Vehicle Steering 2n nodes. If a node j has location Q = (a, f3, d\,d2,d , d ) and action p,j = a, then its partner node 3 4 n+j will have location Cn+j = {-a, —(5, d d , d , di) and action /j, j = - d . Appendix C . l contains it 3 3 n+ a proof that this representation ensures that the nearest-neighbour policy is left-right symmetric. 5.3 Policy Evaluation In general terms, we wish to find a policy that can steer the truck backwards as far as possible around the track in a fixed period of time. It must do this without jack-knifing or crashing it into the track barriers. To measure progress around the track we define a track center-line and compute the point, P, on the center line that is closest to the reference point, P, on the vehicle. We use P to measure the distance travelled by the truck along the track center-line, as illustrated in Figure 5.9. d(s,s') = d d l+ 2 + d 3 t Figure 5.9: Distance measured along the center of the track. The evaluation function, E(Q), should assign a high value to policies which steer the truck quickly around the track from a reasonable initial starting state. A n evaluation function that measures the policy performance from a single initial state is inadequate in that the solutions may become overly tuned to the situations encountered from that initial state. To overcome this, we evaluate the policy from p initial states, s\ ,\ nit states s\ nit < i < p, sampled from a initial state distribution, D. The initial are sampled once and then held constant throughout the optimization process in order to fix the evaluation function for convergence. The policy is executed from each of initial state, 66 Chapter 5. Vehicle Steering s\ , for nit simulation time steps, resulting in the corresponding trajectory, o- (@) = (s\(Q) = % Tevai s\ , s (&), • • •, s l nit l 2 s\ {&) for cMide Tcval tcoiude (©))• If a collision occurs at time < t <= Te atV t iude, co the simulation is stopped and s (Q) = l t The policy is evaluated for each trajectory, o- (Q), by using the 1 distance covered over the trajectory, d(s\ , s ^ (0)). The complete evaluation function is given l nit T ai by: E(e, Tevai) = f>(4»t> 4 . . . , (©)) - PerashV(sir. , (6)) m • (5.2) t=l where P ash cr is a constant collision penalty and n(s) is a crash indicator function that returns 1 if s is a collision state and returns 0 otherwise. Although a crash is implicitly punished because the vehicle stops and no longer can cover track distance, this punishment is often not significant when the crash occurs towards the end of the evaluation time period. The crash penalty is added to the E(Q, to more effectively deter crashes no matter when they occur. T i) eva Tevai choose defines the time horizon of the evaluation, which determines its short-sightedness. We Tevai to be of sufficient duration for the vehicle to navigate around at least two corners. This discourages the policy from making bad short-sighted choices. Initial State Distribution The specific choice of the initial state distribution, D, can strongly influence the learned policy. It can be used to manipulate the trade-off between providing control over a large domain versus providing higher-performance control over a smaller domain. In the former case, a learned policy may be able to guide not-often-seen but difficult initial states towards successful track navigation. In the latter case, a higher-performance solution could be achieved, one that perhaps does faster, more refined turns around corners at the expense of having to start the vehicle in a familiar situation, i.e., located near to the track center. The distribution D is defined by a initial state generation algorithm, which is parameterized for the specific steering problem. The following describes how initial states are generated for the backwards truck steering. For concreteness, the parameters for this problem are included. The algorithm parameters for the all problems are listed in Table 5.2. The angle, a, and angular velocity, d of steered wheels is always initialized to zero. The position of the center of the cab is uniformly distributed around the length of the track and uniformly distributed across 80% of the track width. The initial value for (3, the cab/trailer angle, is sampled uniformly in the range of -0.4 to 0.4 radians. However, any initial positions, which intersect with the track barrier or nearly do so are rejected. A near-collision is determined by computing a collision with an enlarged version of the truck, for which the back half of the trailer is 2.5 times as long as normal and the width of the truck is 1.4 times the Chapter 5. Vehicle Steering 67 Figure 5.10: Several initial states sampled from the distribution D for the single-trailer truck-backing problem. The evaluation for this problem uses 500 such initial states. normal width. Positions that are near-collisions typically result in crashes which the policy can do little to avoid or prolong. These near-collisions can distract the policy evaluation from its job, which is to reward policies that move the vehicle quickly around the track under reasonable conditions. Several legal initial states are displayed in Figure 5.10. 5.4 Policy Search In Chapter 4, we conducted a policy search using a nearest-neighbour policy with a fixed number of policy nodes in order to control a cart and pole system. The problem with fixing the number of policy nodes is that it is difficult to know a priori how much representational complexity is required for a satisfactory solution to the problem. Our policy search algorithm found a reasonable 2-node policy for the cart and pole problem. However, perhaps a much better solution could have been found among 4-node or 8-node policies. A n adaptive policy search allows nodes to be added to the policy if this results in a better solution, so that the number of nodes required to adequately solve the problem does not need to be guessed before the search begins. Another advantage of an adaptive policy search is that the easier task of finding a coarse solution can be conducted initially, and then that solution can be gradually refined. For the vehicle steering problem, initial experiments that used 68 Chapter 5. Vehicle Steering policy search with a fixed number of nodes, n > 3, discovered that the correspondingly large number of policy parameters made a simple optimization prohibitively difficult. W i t h fixed n > 3 the policy search was unable to find a reasonable solution and with fixed n < 3 the solutions generated were rather coarse. Adaptive refinement of a coarse solution seemed like an obvious way of improving such a steering policy. Adaptive refinement, as a way of adding representational complexity only where it is useful, has been used for grids [MM02, MA95] and growing algorithms for neural networks [Bis95]. We exploit the semi-parametric character of the nearest-neighbour policy representation, by conducting the policy search as a series of optimization episodes and adding a new node with each episode(as mentioned in Section 2.3.5). The pseudo-code for the optimization series is outlined in Algorithm 3. Algorithm 3 Optimization Series input 7r {policy} global T i {evaluation time} eva Ebest <— E(lT.Q, Tevai) repeat Knew add-node(n) Knew < — optimize(ir ) new E-new * E(lT . 0 , Tevai) if > Ebest then E n e w new Ebest * E ew n end if until convergence output policy 7T Policy nodes should be added in a location in O that will allow improvement to the evaluation, E(Q), of the policy. The location, Cnew, of a newly added node is drawn uniformly from the distribu- tion of observations encountered during the evaluation of the previous control policy. The location of the first-added node is sampled from the observations of a policy that always steers straight. This simple heuristic biases the refinement to regions in O that are encountered frequently. It discourages the addition of new nodes to regions of the observation space that are rarely or never encountered. We note that this heuristic could be improved as it does not consider locations which are less frequently seen but for which the policy could improve its choice of action considerably. However, this is only a starting point for the node location, which will be further optimized by the policy search. The action, /J. ew, n is initialized to be the same as that of the closest node, or in other words, the action that would be taken by the previous policy at the state Cnew This bootstraps the initial action of the new node to be a reasonable value and the optimization is used to further refine that value. The action of the first node is sampled from a uniform distribution on the range [-1.0,1.0] Chapter 5. Vehicle Steering 69 radians. The addition of a new node and bootstrapping of its parameters is done in the addjnode routine. After a node is added, an optimization on the augmented policy parameters is performed in the optimize routine. Notice that the new policy resulting from addjnode and optimize is only kept if its evaluation is improved over its predecessor. Otherwise, we revert to the predecessor and try another node addition and optimization. The optimize routine is a variation on the S G A algorithm, as defined in Section 2.3.4, and is outlined in Algorithm 4. We limit the total number of perturbations and the number of perturbations that occurred since the last improvement to the evaluation of the policy. This limits the computation used to optimize a policy after the addition of a new node. Sometimes the added node only interferes with the policy in the sense that any optimum that can be reached by our local optimization is worse than the policy value before the node had been added. In this case the policy node will not be kept and we would not want to unnecessarily waste computational resources on the optimization. A l g o r i t h m 4 optimize^) i n p u t 7T {policy} global T i {evaluation time} global p {step size} global A {decay factor} global b {maximum number of iterations allowed} global c {maximum number of iterations without improvement} global c {number of iterations without improvement before p decay} define b < — 0 {number of iterations} define c <— 0 {number of iterations without improvement} eva m a x max step Ebest T al) < — E(TT.@, eV while b < b and c < c do Knew *— perturbation2{tr, p) m a x Enew if 4 Enew max .0, E(^7T new 7T < T^new Ebest * E n e Tevai) then > Ebest w else c <- c+ 1 end i f if c / 0 and c mod p = Xp end i f b <- b+ 1 end w h i l e Output 7T c e st P = 0 then The perturbation routine, which is defined in Appendix C.3, stochastically perturbs policy parameters to create a new candidate policy. Several options for which policy nodes will be perturbed 70 Chapter 5. Vehicle Steering during the optimization are outlined in Figure 5.11. Though it is possible to perturb all policy parameters, in the search for an locally optimal policy, this may be impractical if there are many nodes so the dimensionality of the parameter space is large. Alternatively, we could restrict perturbations to just the parameters of the new node, given that with the addition of a new node, we are trying to refine the policy in a local region of the observation space. However, certain steering behaviours may require the coordination of actions in contiguous Voronoi cells. Therefore, a reasonable compromise might involve perturbing the parameters of the newly added node plus those of some of its neighbouring nodes, where the neighbourhood is denned according to the trajectories entering and exiting the cell. We take this final approach, since preliminary experiments indicated that the first two approaches were unsuccessful at refining the optimized one-node policy. (a) (b) (c) Figure 5.11: Options for perturbing policy parameters (a) Perturb all policy parameters (b) Perturb just the parameters of the newly added node (c) Perturb parameters of nodes in the newly added node's neighbourhood. 5.5 Results Using the policy search method described in the previous section, policies for various vehicle steering problems have been developed. For example, policies have been created for driving a car forwards and backwards; driving a truck with one trailer forwards and backwards; and driving a truck with two trailers backwards. A l l of these policies have been tested on various tracks of the same style, yet different from the tracks on which they were trained. Additionally, some of the policies have been tested on tracks which are quite different from the training track or which have obstacles that were not used in training. The results for a variety of steering problems follow. A comparison of simulation and optimization parameters, as well as some numerical results, of each steering problems is included in Table 5.2. 71 Chapter 5. Vehicle Steering 5.5.1 Backwards Driving Single-Trailer Truck We have been able to generate a number of steering controllers for backward driving trucks which have similar strategies. As is true of most optimization algorithms, some parameters must be hand-tuned, and our policy search algorithm is no exception. k X M Figure 5.12: Truck dimensions for the single-trailer truck backing problem. To give an idea of the difficulty of the problem, Figure 5.12 shows the dimensions of the truck and the track it must drive on. Tracks for both training and testing are generated using the algorithm described in Section 5.2.1. For this problem, the track is 1.8 units wide, which is 5.14 times the width of the truck. The straight segments between turns have a length uniformly distributed between 2 units and 4 units. Some physical parameters for the simulation must be chosen, as well. We take a simulation time step to be 0.01 s and the fixed speed of the truck to be 1 unit/s. The constants k and kd for the p 72 Chapter 5. Vehicle Steering dynamical system denned in Equation 5.1, which is used to drive the steered wheels, are 10 ^ and 3.5 i , respectively. We evaluate a policy from p = 500 initial positions for T i = 800 simulation time steps, which eva corresponds to about 8 s of simulation time and is typically enough time for the truck to round two corners. Initial states are generated by the algorithm outlined in Section 5.3. :rn: •'•fcC3-:-:.CX3--: "•'t3;_\CE3? c (a) (b) Figure 5.13: Steering a one-trailer backwards-driving truck along unfamiliar tracks of: (a) The same class as the training track (b) Wider and with shorter segments than the training track. We take the initial optimization step size to be p = 2.5. This defines the maximum magnitude of perturbations in the policy parameter space in a way that is elaborated in Appendix C.3. The decay factor is A = 0.9. The maximum number of iterations during an optimization episode is set to bmax = 150 and the maximum number of iterations allowed without improvement is c x = 50. The ma number of iterations without improvement before the step size p is decayed is c step = 10. W i t h these parameter settings for the simulation and policy search, a policy with 14 nodes (or 28 including symmetric nodes) has been developed to steer the truck backwards. Each policy node has 7 parameters (6 for the node location and 1 for the node action) so the total number of policy parameters is 98. Figures 5.1(a) and 5.13(a) shows this policy driving the truck around a track that has the same properties, yet is distinct, from the track on which the policy was. trained. Figure 5.13 73 Chapter 5. Vehicle Steering (b) shows the policy steering on a track that is significantly wider and with shorter segments. The policy appears to have difficulty navigating the u-turns for which it was not trained, although it does manage to stabilize its motion. Policy evaluations take the bulk of the computational resources during the policy search. There is one policy evaluation conducted for each of a number of iterations during an optimization episode. This policy search took 106 optimization episodes and 13476 policy evaluations (i.e., computations of E(Q)). The entire process took a total of 134877 s = 37.5 hr on a modern P C , without necessarily having sole access to the processor. Table 5.2 shows a summary of the parameters and some policy search statistics for this steering problem and others. *e - *© -1500 -5000 _1 1000 _J 1_ 2000 3000 4000 1_ 5000 Policy Search Function Evaluations 6000 # x O 7000 8000 9000 10000 Best Value for All Optimizations New Node Added Reverted to Previous Controller Accepted New Controller Best Value for Current Optimization Figure 5.14: Policy performance versus function evaluations during the policy search for a singletrailer truck driving backwards on a winding track. Figure 5.14 shows how the value of the best policy is improved over the course of a policy search. Each solid line in the figure correspond to a optimization episode. W i t h each optimization episode a 74 Chapter 5. Vehicle Steering node is added and the policy is optimized. If the resulting policy is better than the previous policy it is kept. Otherwise, we revert to the previous policy. Notice that most improvement in the policy evaluation, -E(O), takes place with the acceptance of the first 3 nodes. After that, additional nodes tend to add only slight improvements to the policy. This may correspond to the fact that during normal policy operation only 3 nodes plus their symmetric nodes are mostly used. The other nodes are activated only in extreme circumstances. It can be speculated that the very slight improvements are made by the addition of nodes that are activated in rare situations, perhaps to postpone a imminent crash slightly and thereby improve the evaluation. (a) (b) Figure 5.15: Driving a one-trailer truck backwards in unexpected situations: (a) Track with varying width and turn angles (b) Track with obstacles. The learned truck-steering policy demonstrated reasonable robustness in driving situations quite different from the class of tracks for which it was trained. For example, in Figure 5.15 (a) the policy is controlling the motion of the truck down a track with varied steering angles and track widths, although the policy was trained on a track with 90° corners and a fixed width of 1.8 units. Also, the policy was able to cope fairly well with obstacles on the track as shown in Figure 5.15 (b), even though obstacles were not used in training. The frequency of crashes does increase with the unfamiliarity of the situation but the policy generalizes suprisingly well. In order to test robustness with regard to errors in the truck model, we applied the computed policy to one-trailer trucks with the position of the rear trailer wheels varied. The truck policy still steers well when this wheel position is changed by as much as 10% as measured from the middle of the trailer. We ran the policy search algorithm 4 times with identical parameters but different random number Chapter 5. Vehicle Steering 75 initializations to check its robustness in this regard. The track instance used for training, the initial evaluation positions, and the policy perturbations are all dependent on the random number seed. The resulting policies all had different node layouts but were similar in their ability to navigate tracks of the specified class. Double-Trailer Truck Steering a two-trailer truck that is moving backwards is a particular challenge because of the considerably instability in the trailer motion. Either trailer can jack-knife if the swing of the trailer is not carefully controlled as shown in Figure 5 (b). The instability of this steering problem is similar to that of attempting to balance a double-inverted pendulum. Figure 5.16: Steering of a backwards-driving two-trailer truck around a previously unseen track. The two-trailer truck is just like the one-trailer truck but with an additional identical trailer. It is equipped with an additional sensor to measure the angle between the first and second trailers, (3 2 The observation space, O, of the policy is thus 7-dimensional, with o = (a, Pi,P2, di, di, d$, cLi) being an observation. A n action is the same as in the single-trailer problem and consists of setting the desired steering angle, d. The track for this problem is 2.7 units wide and the straight segments have a length uniformly distributed between 3 units and 4 units. The starting position of the cab center is in the center 40% of the track width. The initial trailer angles, P and P2, are uniformly sampled in the range of -0.2 and 0.2 radians. As with the single-trailer truck, initial states are pruned to remove Chapter 5. Vehicle Steering 76 collision states or near-collisions. The physical constants for the simulation, including kd and k for p the steering, are identical. The evaluation and optimization parameters are also the same as for the one-trailer case. (a) (b) (c) (d) Figure 5.17: Initial states resulting in a collision for two-trailer truck: (a)-(c) Jack-knifing of front trailer (d) Crash into barrier. Our algorithm was successful in learning a policy that can steer the truck backwards around a class of winding tracks. Figures 5.1(b) and 5.16 demonstrate the learned steering policy operating on such a track. The policy uses a total of 30 nodes (or 60 including symmetric nodes). Each policy node has 8 parameters (7 for the node location and 1 for the node action) so the total number of policy parameters is 240. As with the one-trailer truck policy, only about 3 pairs of nodes are used for the vast majority of steering manoevers. The rest of the nodes are almost always activated in unusual circumstances that often result in a crash. The policy search was completed in 129 optimization episodes with a total of 15482 policy evaluations. The process took 220922 s = 61 hr using comparable computing resources to that used for the one-trailer problem. See Table 5.2 for a summary of the problem parameters and some statistics for the policy search. The learned policy works well from some initial states, but others give the policy difficulty as it is not able to guide the state trajectory into a stable steering pattern. Examples of some difficult initial states and the collision trajectories that result are shown in Figure 5.17. Note for a trajectory such Chapter 5. Vehicle Steering 77 as (c) in the figure, the policy would likely have been able to steer the truck around the corner if not for exceeding the constraint of < 90° resulting in a jack-knifing of the front trailer. These trailer- angle constraints only compound the difficulty of the problem. As the complexity of the steering problem increases it becomes more difficult to determine whether a stable motion without a collision can result from a particular initial state. It may be that any given policy is doomed to crash or jackknife from this state making it uncontrollable. In many cases, the only feasable way to determine if a state is controllable is to generate by policy search or some other method a policy capable of controlling the state. Determining that a state is uncontrollable is considerably harder but this topic will not be discussed further in this thesis. The policy has not been tested as extensively as the policy for the single-trailer truck for robustness in situations for which it was not trained. However, it can be stated qualitatively that the double-trailer truck policy is not nearly as robust. Car Figure 5.18: Car driving backwards on an unfamiliar track. Since the car does not have any hitch angle sensors, the observation space, O, of the policy is 5-dimensional, with o = (a, d\,d,2,d , d$) being an observation. The policy search for the backwards3 driving car required 43 optimization episodes with a total of 3665 policy evaluations. The process took 84325 s = 23.4 hr using similar computing resources to the other steering problems. The resulting policy contains 22 nodes. Each policy node has 6 parameters (5 for the node location and 1 for the node action) so the total number of policy parameters is 132. The steering behaviour of the backwards-driving car policy on an unseen track of the same class as the training track is shown in Figure 5.18. This policy is particularly robust to changes in the track width and turn angles, as shown in Figure 5.19. Also, Figure 5.20 (a) demonstrates that the policy is reasonably capable at avoiding obstacles on the track, despite the fact that obstacles were never encounterd in the training. However, certain configurations of obstacles that are not shown 78 Chapter 5. Vehicle Steering (a) (b) Figure 5.19: Car driving backwards on two tracks with varying width and'corner angle. are obviously passable and yet cause the policy to crash, as might be expected since it has not been trained for these situations. This car policy can also successfully navigate a " Y " or "T" branch in the track, as illustrated in Figure 5.20 (b). This backwards car-steering policy was the best of all policies, including the forwards car-steering policy for generalizing to situations it had not seen in training. Figure 5.20: Car driving backwards in unexpected situations: (a) Track with obstacles, (b) Track with " Y " and "T" branches 79 Chapter 5. Vehicle Steering 5.5.2 Forwards Driving The task of forwards-driving around the track is simpler than the equivalent backwards-driving task because of the stability provided by having the steered wheels lead the motion. Because the goal is to travel around the track in minimal time, we would expect to see behaviors such as steering close to inside corners and steering directly (diagonally) between corners. A critical issue to be addressed is that of avoiding collisions with corners, which is especially interesting in the case of the trucks-with-trailers given that the trailers do not directly follow the path of the cab. For this reason, the cab must swing wide in a turn in order to provide sufficient corner clearance for the trailer. Steering close enough to the corner so that near-maximum progress around the track is made, while not approaching so close that a collision is risked is a compromise that is defined by the evaluation function and learned during the policy search process. Figure 5.21: Car policy trained to drive forwards on a narrow track. Figure 5.22: Car policy trained to drive forwards on a wide track. In Figures 5.21 and 5.22, we see the resulting steering behaviour of policies developed for forward Chapter 5. Vehicle Steering 80 car-driving on wide and narrow tracks, respectively. For the wide track, the path of the car cuts to the inside on corners to progress more quickly around the track. This policy uses 15 nodes and was computed with 27 optimization episodes and 1342 function evaluations in 66192 s = 18.4 hr. For the narrow track, the turns must be executed with precision in order to avoid collisions with the sides of the track. This policy uses 21 nodes and was computed with 47 optimization episodes and 3158 function evaluations in 70479 s = 19.6 hr. Figure 5.23: Truck driving forwards on an unfamiliar track. Finally, Figure 5.23 shows a forwards-driving single-trailer truck. Note the necessity of the truck cab to swing wide on turns in order to avoid the trailer clipping the corner. In contrast to the backwards-driving truck policies, this policy does not observe the hitch angle, as it is less necessary for control due to trailer stability. The policy has 20 nodes and required 37 optimization episodes, 2801 function evaluations, and 62234 s = 17.3 hr of computation. A l l the results shown are for tracks that are novel, but that belong to the same family of tracks used during training. To test for robustness with respect to modeling errors, we made alterations to the wheel-base of the car of up to 20% and found that the policy still steered well. 5.6 Summary and Future Work We have demonstrated the use of policy search using adaptive refinement to generate policies for a variety of steering tasks, including the difficult problem of steering a truck with one or more trailers Chapter 5. Vehicle Steering 81 down a sharply-cornered winding track with only local sensory information. However, during this process, a number of issues have come up which would benefit from further investigation. Nearly all of the steering behaviours for the backwards-moving vehicles arise from motion of the observation state along the boundary between symmetric nodes. The observable state, o, tends to bounce back and forth across the boundary between the two symmetric Voronoi cells, much the same as described with the cart and pole problem in Section 4.7.1. This chattering behaviour occurs not only when the vehicle is driving straight, but also as the vehicle is rounding a corner. It is evident that this type of bang-bang control is found by the policy search to be particularly useful at controlling the unstable backwards motion of the vehicles. Chattering is less prevalent in the forwards-driving vehicle policies which have inherently stable motion. Furthermore, the backwards-driving policies tend to be much more robust to changes in track width and corner angle, and are more capable at avoiding obstacles. It can be speculated that this robustness is somehow related to the chattering behviour, but further analysis would be required to understand why this might be the case. General policy chattering is discussed further in Section 6.1. No previous work focusses on this particular formulation of the vehicle steering problem so it is difficult to compare with other methods for finding steering controllers. However, considerable work has been done on other variations of the nonholonomic vehicle control problem, as noted in Section 5.1. Future work should involve more rigorous comparisons of the performance of our adaptive policy search method versus other control techniques. A strong point of our method is that it is capable of solving a wide range of steering problems automatically using only minor parameter modifications. However, a disadvantage is that our policy search typically takes on the order of a day to learn a good steering solution. It is likely that the method could benefit from a more principled optimization approach that utilizes gradient information or a richer policy representation, for example, with interpolation between policy node actions. Much further research could be conducted into the use of different optimization techniques or policy representations. Our vehicle steering problems were physically idealistic in a number of ways, including having a fixed vehicle speed, no tire friction model, and noiseless sensors and actuators. For the policies generated by our method to be applicable to real world control the physical model of the vehicle motion would need to be much more realistic. 82 Chapter 5. Vehicle Steering (a) Problem Parameters V ehicle Width (units) Track Width (units) Minimum Track Segment Length (units) Maximum Track Segment Length (units) Vehicle Speed (units/s) k (l/s ) k (l/s) Observable State Variables Blffiiati oir^prameters Evaluation Time T i (s) Number of Initial Positions Maximumlnitial Vehicle Angle (rad) Portion of Track Width for Initial State (%) Width Ratio for Near-Collision Test Length Ratio for Near-Collision Test Search Parameters Step Size p Decay Factor X 2 p d ma b max C max C step Results Nodes n Number of Policy Parameters Optimization Episodes Policy Evaluations Time to Conduct Search (h) 1 (b) (c)' () f 0.35 1.8 2 4 1 0.35 2.7 3 4 1 0.35 1.04 0.5 2.5 1 0.35 0.85 0.1 2.5 1 0.35 1.8 0.1 2.5 1 0.35 1.04 0.5 3.5 1 10 3.5 6 10 3.5 7 7.5 3 5 10 3.5 5 6 2.5 5 10 3.5 5 8 500 0.4 80 1.4 2.5 8 500 0.2 40 1.4 2.5 7 500 0.4 80 1.4 2.5 7 500 0.4 80 1.4 2.5 5 300 0.4 80 1.4 2.5 10 500 0.4 80 1.4 2.5 2.5 0.9 150 50 10 2.5 0.9 150 50 10 2 0.8 100 30 8 2 0.8 80 25 7 2 0.8 80 25 7 2 0.8 100 30 8 14 30 98 240 106 129 13476 15482 37.5 61 22 132 43 3665 23.4 21 126 47 3158 19.6 15 90 27 1342 18.4 20 120 37 2801 17.3 Table 5.2: Simulation parameters, policy search parameters, and numerical results for various vehicle steering problems: (a) One-trailer truck backwards (b) Two-trailer truck backwards (c) Car backwards (d) Car forwards (e) Car forwards on wide track (f) One-trailer truck forwards. Chapter 6. Discussion 83 Chapter 6 Discussion Evaluating a control problem solution is itself a difficult problem. This is because there are several common notions of what constitutes an optimal solution, including robustness, energy efficiency, and time efficiency. It is usually best to blend several of these notions of optimality into a single evaluation criteria. However, the choice of what weight to give each factor is difficult and highly problem specific. If a policy is capable of controlling a large range of intial states, we consider it to be robust. However, the resulting trajectories from those initial states may be highly nonoptimal in terms of the time or energy used to make progress towards a goal region or along a path. The evaluation metrics used to solve the control problems in this thesis considered a compromise of robustness and progress made during a fixed evaluation time. We did not consider energy used by the controller in evaluating policies. Other notions of optimality such as the smoothness of trajectories were not explicitly considered in the evaluation metric but may have been implicitly rewarded because trajectories that make maximum progress tend to be smooth. This chapter discusses some advantages and disadvantages of our choices of policy representation and policy search method and makes brief comparisons whith some alternatives. 6.1 Nearest-Neighbour Policy Representation When choosing a policy representation various factors can affect the shape of the optimization landscape. Ideally the policy parameterization should be compact and smooth, yet contain good solutions. In this section, we evaluate various properties of the nearest-neighbour representation. Arbitrary Function Approximation Our policy search method operates within the class of policies, II, which can be represented using a nearest-neighbour (NN) function approximator (FA). Ideally, we want n to contain the optimal policy 7T* or a good approximation of it. In other words, it would be good if the N N function approximator was capable of approximating any possible function. Indeed, it can be seen that as the number of nodes is increased towards infinity, and they are spread to cover the entire policy domain, they can make an arbitrarily fine discretization of the domain. This means that the N N F A can be used to 84 Chapter 6. Discussion approximate any function, and most importantly, the optimal policy. optimal policy n* nearest-neighbour policy 7t Voronoi cell boundary node location observation space O Figure 6.1: Poor approximation of a linear function using a nearest-neighbour function approximator. Efficient Parameterization of Function Approximator It is not enough to know that the optimal policy can be approximated; it is equally important that it be approximated efficiently For example, if the N N policy representation takes an inordinate number of nodes to approximate a simple optimal policy then it is not a good choice. The dimensionality of the space of policies is linear in the number of nodes, so this may make a search for a good approximation to the optimal policy prohibitively expensive to compute. It is instructive to discuss some simple policies for which the N N function approximation is poor so that we know where to avoid it. For instance, any function that is linear but not constant is poorly approximated by an F A with discrete values, which includes the N N F A and a discrete grid FA. A discrete F A must have a large number of discrete steps to approximate a function that can be exactly represented by a simple hyperplane. A n illustration of an inefficient N N function approximation of a linear optimal policy is shown in Figure 6.1. Interpolation between policy actions may help to better approximate some control policy functions. It is important to note, however, that linear controllers (or even other more complex control models) can be used as components that each operate within a Voronoi cell of the nearest-neighbour Chapter 6. Discussion 85 policy. In fact, the N N policies used to solve various control problems in this thesis use P D control actions, which correspond to linear combinations of 2 state variables. Even an optimal policy with discrete control may be poorly approximated by an N N F A . Such apolicy is one with curved boundaries between regions of discrete action. Since a discrete region of an N N F A is a Voronoi cell, whose boundaries are hyperplanes, it makes the approximation of discrete policies with curved boundaries difficult. Figure 6.2 shows an example of this. observation space O Figure 6.2: Poor approximation of a discrete function with curved boundaries using a nearestneighbour function approximator. Chattering and Energy Waste In our results for both the cart and pole (Chapter 4) and vehicle steering (Chapter 5), we have encountered a policy behaviour that involves chattering between neighbouring Voronoi cells using opposing actions. This behaviour is illustrated in Figure 6.3. The structure itself is not a cause for concern since often reasonable policies use alternating actions to maintain stability. For example, when balancing a pole restricted to a planar domain it is useful to alternate between pushing the pole one direction and the other, to counteract instability in the balance of the pole. However, because of the discrete approximation of the N N F A the opposition of the alternating actions can be quite strong, Chapter 6. Discussion 86 resulting in harsh chattering between the discrete action of two Voronoi regions, as with bang-bang control. Obviously, this chattering results in a unnecessary waste of energy. Since we are running in simulation and we do not consider energy use in evaluating policies this is not a concern, but it would be for engineers designing policies for real world control. Also policies that use less energy tend to appear more natural, which is a useful property for animation, particularly of animals and people. In future work, it would be valuable to examine the power/robustness tradeoff of the policies generated. Using a policy representation that allows for smoother variation in the policy ir : O —> A, would be useful for decreasing power use. This might be done by using smoother interpolation kernels for the policy representation, such as could be achieved by the k-nearest neighbour or radial basis network approaches. \ observation space O trajectory Figure 6.3: Chattering between the opposing actions of Voronoi cells. Smoothness of Policy Parameter Space Choosing a good policy representation can be critical for ensuring that the policy search is well-shaped. Typically, to make the search simpler, the policy function, ir : O —» A should vary smoothly as we move about in the policy parameter space. In other words, if a small change in policy parameters 0 results in a large change in TT : O —» A, it is also likely that the state trajectories for the evaluation will change drastically, and therefore there will be a large jump in E(Q). This means that discontinuities in the parameterization of the policy can cause discontinuities in the policy evaluation function, E(@), which increases the difficulty of the policy search. With the N N policy representation, moving within the policy parameter space mostly results in smooth change in 7r. However, an exception occurs when the locations of two nodes, Q and Q , cross directly over one another. In this case, the Voronoi cells 87 Chapter 6. Discussion of nodes i and j will be swapped, meaning that the actions, (ii and in those Voronoi cell regions will be swapped. This may result in a large jump in the policy function IT, which would presumably make for a discontinuity in E(@), and a more difficult policy search. Fortunately, in a random walk of the N N policy parameter space, the occurance of two nodes crossing directly over one another is quite rare, as long as the nodes are sparsely positioned. Effect of Redundant and Unnormalized Policy Domain Nearest-neighbour function approximators (NNFAs) use a distance metric which weighs all dimensions of the the policy domain (or observation space, O) equally. Lets assume that the optimal policy IT* : O —• A is fairly smooth, meaning that there is a rough corellation between the distance between two observations, |oi — 02I and the distance between the corresponding optimal actions, |7r*(oi) — ir*{o2)\If there is redundancy in (or a correlation,between) observation variables or these variables have significantly different ranges, the N N function approximation of IT will become less effective. This is because the redundant variables or variables with greater ranges will be weighted more heavily in the Z/2 distance metric used to determine the Voronoi cells. This tends to align Voronoi boundaries and stretch Voronoi cells in a certain direction, making them less efficient at representing a smooth policy. This problem may occur when observation dimensions are measured in different units that have different ranges, e.g., when one sensor measures the speed of a car in m/s while another sensor measures the steering angle in radians. Figure 6.4 illustrates the stretched shape of Voronoi cells when the range of two observation variables differs by an order of magnitude. In such problems it would be useful to normalize the sensory variables so that their ranges are approximately the same. Normalization of sensory variables is useful for other function approximators such as radial basis functions. A neural network function approximator normalizes input variables automatically with input weights. The nearest-neighbour policies we used did not require normalization since the ranges of input variables were comparable. As for redundant input variables, it would likely be beneficial to use a dimensionality reduction technique such as principal component analysis to create compressed observations for input to the nearest-neighbour policy. N N F A in High-Dimensional Spaces Although we have used a N N policy represenation to solve some difficult problems in policy domains with as many as 7 dimensions (eg. for the two-trailer truck), the N N F A will likely not work well in observation spaces of high dimension, unless it is known that a policy need only operate in a lowerdimensional manifold. Randomly-sampled points from a uniform distribution in a high-dimensional space tend to be spaced such that the distance between any two points is equal. So if nodes are 88 Chapter 6. Discussion 50- 40i i • • •••••••• mi 3 30- """""""""••mil,,,, > a o * • 2 — •• 20•" 1 1 " » minimi ••••••• iimiimm O 10- 1 1 1 2 1" 3 1 4 1 5 1 6 observation variable 1 Figure 6.4: Stretched Voronoi cells with unnormalized sensory variables. placed randomly in a high dimensional space they will likely have this property. Also, a randomly sampled state will tend to have the same distance to all such nodes. In other words, there would be a large region in the observation space that has nearly the same distance to all nodes. The choice of action in this region would be rather ambiguous. We might consider this the curse of dimensionality for NNFAs. If we know there is a low-dimensional manifold of normal operation in the observation space, NNFAs can still work fairly well in moderately high dimensional spaces. Consider, as an example the control of human walking [Sha04]. Although the state space of a human figure has many dimensions (i.e., all joint angles and angular velocities), we know that, as long as the walk is proceeding normally, the state will remain close to a 1-dimensional trajectory. For a N N walking policy that does not need to recover from abnormal states it is possible to place nodes along the normal walking trajectory, thus carving up the region of interest into discrete actions, as shown in Figure 6.5. A walking policy was generated in [Sha04], using such an initialization of node positions. Advantages of N N F A Despite the shortcomings of the N N policy representation, it has still proven to be a very useful tool for solving a variety of difficult control problems. For example, using such a representation we have 89 Chapter 6. Discussion observation space 0 Voronoi cell boundary * £ * • • * • node location \\valk trajectory Figure 6.5: Dividing up a 1-dimensional walking trajectory through a potentially high-dimensional observation space into the cells of a nearest-neighbour policy. The distance metric and Voronoi cells are still computed in the high dimensional space, because the actual state may not lie exactly on the manifold. developed policies for difficult vehicle steering tasks. There are a few reasons why an N N F A is effective as a policy representation for certain control problems. It is a semi-parametric representation, which allows the complexity of the representation to be augmented to fit the problem. In other words, the policy can be adaptively refined in regions of the observation space as needed. A n N N policy is an irregular represenation, unlike uniform grids, since nodes can be concentrated in specific regions. This allows the distribution of representational complexity through the policy domain to match that of the needed control complexity. Secondly, an N N F A efficiently represents a policy that requires an alternation between two opposing actions. This behaviour can be achieved by having the observation state bounce back and force between contiguous Voronoi cells with opposing actions. This is similar to bang-bang control and is useful for controlling certain unstable processes such as balancing a pole or steering a tractor-trailer backwards. Finally, an action is represented locally in a particular Voronoi cell, meaning that the policy can be adapted locally without any far-reaching side-effects. In general, N N policies can be a very compact representation. Interesting control problems can be solved using only a few nodes, which each have only a few parameters equal to do + d , where do and A dA are the dimensionality of the observation space and action space. Furthermore, it is impressive that a policy representation that is so conceptually simple, as is evident by Equation 3.1, is capable of handling rather complex control. It is also computationally simple, as a naive algorithm need only 90 Chapter 6. Discussion calculate and compare the distances between the current state and each node, which is linear in ndo, where n is the number of nodes. 6.2 Policy Search Method In Section 6.1, we mainly discussed features of the N N policy representation in terms of how well it could approximate IT*. However, even if ir* can be approximated, that does not mean a policy search algorithm will find a good approximation quickly. This discussion looks critically at our policy search algorithm and suggests some potential improvements. Adaptive Addition of Nodes As discussed in Sections 2.3.5 and 5.4, adaptive addition of nodes can be useful for shaping the search for a policy through progressive refinement. However, this method will only be effective if the number of nodes used for the initial optimization episode is adequate to roughly solve the control problem. If this number is not enough then often a poor initial solution to the problem will be found, one that achieves some short-term reward, with little consideration of the complexity of the problem as a whole. Of course, if the rough solution of the first optimization episode is poor, it is unlikely that refinement of that solution will result in a good approximation of the t t * . The reason we use a sequence of progressively more difficult optimizations is so that early ones can bias the later ones with a good starting points. If early optimization episodes have an inadequate number of nodes and thereby result in poor solutions, such biasing can only hamper later optimizations. Stochastic Greedy Ascent Optimization S G A optimization is but one of many possible optimization methods. Successful application of S G A to difficult control problems has demonstrated the effectiveness of our policy search shaping techniques. It would be beneficial to try other optimization techniques. Obvious examples include genetic algorithms and simulated annealing. A variation of the downhill simplex method proposed in [PTVF97], p. 451 solves some noted inefficiencies of typical simulated annealing techniques and may be a promising approach for policy search, particularly with control problems characterized by local minima. [RB01] uses a stochastic search algorithm biased by a rough estimate of the gradient. This is a alternative to our SGA with a simple model of the local landscape. If gradient information for £ ( 6 ) is available it can be used with a number of nonlinear programming techniques, such as line-search and trust-region techniques, to find local minima very efficiently. Our policy search could benefit significantly by using such techniques, as long as the evaluation function is adequately shaped. Chapter 6. Discussion 91 Value Function Approximation There are certain benefits to using value-based R L methods to compute control policies. The main advantage is that knowledge of the structure of a control problem is used to compute a value or Q function, which guides the search for an optimal policy. When our S G A optimization blindly perturbs parameters and tests if they result in a better policy, it is ignoring this inherent structure in the control problem. If we had access to a value function that assigned values to states, this could be used to alter a local region of the policy so that state trajectories passing through that region can be driven uphill on the value function landscape. The NNFA may provide a useful approximation of the value function. We might consider assigning values to policy nodes, as well as actions. The resulting N N approximation of the value function could be used to guide changes to the policy, during the policy search. In using policy search, we are losing the theoretical guarantee of convergence to an optimal policy that value-based R L methods can provide, although in practice such convergence guarantees are less meaningful, given that they typically have an embedded assumption that requires visiting every state infinitely often. Instead, we must resort to giving a good argument of why our policy representation and search methods are effective, and demonstrate some solutions to difficult control problems to back up our claims. Indeed, we have solved difficult problems using this policy search method, such as the assortment of steering results shown in Section 5.5. Chapter 7. Conclusion 92 Chapter 7 Conclusion We have demonstrated the effective use of a nearest-neighbour (NN) policy representation combined with direct policy search to solve control problems of varying difficult. Importantly, we have also presented a method for shaping the policy search by adaptively adding nodes to the policy in a series of optimization episodes (Section 5.4). The N N representation allows a sparse and non-uniform discretization of the policy function. The N N representation has been shown to model policies for nontrivial control problems in a compact manner (Sections 5.5 and 4.6). N N policies are conceptually simple and the control computation is linear in the number of nodes and the dimension of the observation space. This representation also ensures locality within Voronoi cells, permitting local modification of the control policy without side-effects. The variety of control problems that we have solved is a testament to the flexibility of the N N policy representation and our direct policy search method. We have developed policies that follow a user-specified limit cycle in a 2D state space and ones that can move a cart to a desired location, while simultaneously balancing a pole. N N policies have been found to steer a number of different vehicles around winding tracks. These steering policies are not specific to a track, but can generalize to a variety of tracks with similar properties. Future Work N N policies do have some drawbacks (Section 6.1) and it would be valuable to look at alternative representations to deal with these. Certain classes of optimal policies are not represented efficiently. Basis functions that provide a smoother interpolation between actions may provide a better representation for these cases. N N policies may be hampered by redundant or unnormalized observations. Perhaps the observation state could be preprocessed, so that the policy sees only state information that is compact and relevent to control. The N N representation does not provide the capability to generalize by reusing certain useful structures in different areas of the policy domain, as is possible with hierarchical representations like those used in genetic programming. It may be valuable to introduce hierarchical structure into an N N policy so that certain useful arrangements of policy 93 Chapter 7. Conclusion nodes could be reused and parameterized. Locality and generalization are conflicting goals in developing a policy representation and more investigation should go into effectively balancing these useful properties. Although many of our results have provided encouraging evidence of our method, it would be useful to derive some theoretical statements outlining under what conditions our method can find a reasonable solution and how close a solution must be to the optimal policy. However, as the complexity of the systems considered increases towards that of the real world, theoretical guarantees become exceedingly difficult to find. At some point it becomes prudent to evaluate a method as successful if it reliably generates useful results and it is simple enough to be understood and readily extended. How to validate and fairly evaluate developed control systems is an ongoing issue. Control researchers could benefit greatly from a standardized system for documenting and comparing the capabilities of controllers they design. Our policy search method could be applied to other interesting control problems. For example, we would like to develop N N control policies to control vehicle steering in fields of obstacles and vehicle parking. Some initial experiments with these problems have encountered some success. Bicycle steering and the control of a car on a slippery surface would also be interesting problems that could be applied to computer animation. We must admit that in comparison to real world control problems, like making a canine robot roll over, for example, the ones discussed in this thesis are quite simple. We also have the benefit of working in simulation, which allows our policies to observe whatever state we decide is useful. Furthermore, observations and actions are noiseless, which is typically not the case for robots in the real world. Reactive policies, such as those used in this thesis, are usually not adequate for an environment where observations are ambiguous. Investigation into the use of memory to model and contextualize observations would help to bridge the gap between our work and real robotics. Appendix 94 A. A 2D Example: Time-Based Policy Appendix A A 2D Example: Time-Based Policy A.l Constructing a Time-Based Policy The initial parameters for the policy search are bootstrapped using a time-based policy generated to follow the limit cycle. We use the term time-based policy to refer to a policy that chooses actions 1 based on simulation time elapsed, t, as opposed to choosing actions based on the observable state, o , as is the case with ordinary policies. Of course, if t was added to the observable state then a t time-based policy would be ordinary. Time-based policies are very effective at following a specific trajectory from a single starting state if the dynamics are deterministic. However, if a time-based policy starts from any other state or is bumped off its familiar trajectory it will not be able to react appropriately. A time-based policy is the extreme in purposeful policies; it operates completely open loop. In other words, the observable state of the system has no effect on the action choices of the policy. The time-based policy is constructed in a piece-wise manner. We begin at a state on the desired limit-cycle and try to find the P D controller parameters that track the limit cycle for as long as possible, while the accumulated error of the actual trajectory remains under a specified threshold. Once the P D parameters and resulting trajectory for the first piece have been determined, we optimize the parameters of a second P D controller to take over and track the desired limit-cycle from the end state of the trajectory for the first P D controller. In this way, several P D controllers can be used to approximately track the desired limit cycle, each activated in sequence to control the trajectory of the point-mass for a specific amount of simulation time. More formally, let fii = (x, k , kd)i be the parameters of the i th p P D controller activated and let a' = (s{, s\,..., s\.) be the trajectory produced by that controller, where s\ = s\ nit is the starting point of the trajectory and U is the trajectory length. A diagram of a constructed time-based policy with corresponding labels is shown in Figure A . l . We begin by setting s\ nit to some state on the desired limit cycle and optimize m using stochastic greedy descent (SGA) such that the length, Zi, of trajectory, a , is as large as possible while the error remains under a given threshold, ip. The 1 trajectory error, e(a ), is the sum-squares error between the trajectory and the desired limit cycle, 1 1 Time-based policy is a synonym for open-loop policy, which is used to refer to a policy without state feedback. Appendix 95 A. A 2D Example: Time-Based Policy velocity x Figure A . l : A time-based policy approximating a desired limit cycle. analogous to that given in Equation 3.3. If two sets of parameters, fii and / i ^ , result in trajectories of equal length, then the tie is broken by rewarding the least error. Once the optimization for the first P D controller has converged, we optimize a second P D controller, with parameters ^2- The initial state, s , mit for trajectory o 1 is set to be the last state, of trajectory a . The second 1 optimization similarily tries to maximize I2, while ensuring e{a ) < ip- We continue in this way, until 2 a chain of trajectories makes its way around the limit cycle, ensuring that the ends of the trajectory chain are sufficiently close (i.e., \\s^ — s\\\ < e). Thus, piece-by-piece, we construct a time-based policy that approximates the full limit cycle with a series of trajectories, a , a ,... ,a . 1 delegates control to the P D controllers given by parameters fi2, • • •, 2 n The policy in sequence for li, I2, •. •, l n simulation time steps, repectively. A.2 Bootstrapping a Nearest-Neighbour Policy Now that we have a time-based policy that approximates the desired limit cycle, from it we need to derive an initial nearest-neighbour policy 7r t n , t with parameters Q that follows roughly the same trajectory. The policy ir mlt m t = [ d , . . . , £ , MI, . . . , N p] mxt n will have n nodes, where n is the number of P D controllers used in the time-based policy. Of course, the actions for the n nodes will simply be the P D controller parameters /Uj optimized for the time-based policy. Now it remains to determine the locations of the the nodes, HI, . . . , p . Intuitively, it would be ideal if the nodes were positioned n such that each Voronoi cell i covered exactly the corresponding trajectory, a of the time-based policy. 1 If this was true, then executing the nearest-neighbour policy from any position on the time-based trajectory should continue to follow that trajectory, thus mimicking the behaviour of the time based Appendix A. A 2D Example: Time-Based Policy 96 policy. We first initialize the node location using, & <- |(si+sj.) to be half way between the beginning and the end of the corresponding time-based trajectory. Then we perform a S G A optimization on the node locations to minimize an error function which penalizes a trajectory transition that is not exactly half way between its neigbouring nodes or that has any node closer than its neighbouring nodes. This optimization attempts to find the ideal node positions described above, thus completing the parameters Q mlt of the initial nearest-neighbour policy. Appendix B. Cart and Pole: Additional 97 Information Appendix B Cart and Pole: Additional Information B.l Equations of Motion The motion of the cart and pole is modelled using the following differential equations [Pas98]. mg sin a — cos a(F + m la 2 p sin a) / ( | m — m cos a) 2 p F + m l(a x = — 2 p where g = 9.81 m s - 2 sin a — a cos a) -, m is gravitational accleration, m c = 1.0 kg is the cart mass, m p pole mass, I = 0.5 m is half the pole length, and m = m + m . c p = 0.1 kg is the The dynamics of the cart and pole system is computed using Euler integration with a time step of 0.001 s. B.2 Perturbation Algorithm Algorithm 5 perturbation^, input 7T {policy} input p {step size} for i <— 1... de do 89[i] <end for p) -K.w\i\Rand(-\,l) 7T.0 <— 7T.0 + (50 clip 7T.0 to [Tr.min,7t.max] O u t p u t 7T Algorithm 5 outlines the perturbation algorithm for the cart and pole policy search. In calculating the direction of the perturbation in the policy parameter space, the size of the perturbation in each parameter i is weighted by 7r.w[z]. The parameter weights, TT.W, are chosen by hand based on the type of parameter (e.g., k of a node action or a of a node location) to be approximately proportional p to a reasonable range of values for that parameter. After the perturbation is applied to 7T.O, each parameter 7r.0[i] is clipped to be within the range [7r.min[i], 7r.maa;[i]]. The values in ir.min and Appendix K.max 98 B. Cart and Pole: Additional Information are also chosen manually and most parameters are not clipped, i.e., [i.mm[i], 7r.maa;[i]] = [—00,00]. Table B . l lists the values that are used in K.W, K.min, and -K.max for each type of policy parameter. TT.W •K.min •K.max 0.5 0.5 0.5 —00 00 0.1 0.1 2.0 2.0 —00 00 —00 00 —00 00 —00 00 action /J. a hp kd location £ X X a a 1.0 1.0 0.1 0.1 Table B . l : Constants used for the cart and pole perturbation algorithm. Appendix 99 C. Vehicle Steering: Additional Information Appendix C Vehicle Steering: Additional Information C.l Left-Right Symmetry Proof for Steering Policy Assume that a truck steering policy 7r contains n pairs of nodes or 2n nodes in total. For 1 < j < n, let node j and node n + j form a pair of nodes. For each node i, 1 < i < 2n, we define i to be the index of the partner node of node i. Let = (a;, Pi, d\^, d i, d i, di i) be the location of node i and 2i 3< t Hi = &i be its action. Furthermore, let Q = ( Q J , /?;, d - , d - , d j , c? j) = (—a*, l and /xj = i 2 i z d j, a^,, d , di^) 4 4i 2ti -Hi . 1 We wish to show that for any observation, o = (a, P,di,d ,d ,d ), 2 3 if 7r(o) = a then TT(O) 4 = —a, where 5 = (—a, — d , d , cfo, di). Alternatively, we can show that if o lies in the Voronoi cell of node 4 3 k then 5 lies in the Voronoi cell of node k, the partner of node k. If an observation, o, lies in Voronoi cell k this implies that for all i, such that 1 <= i <= 2n and i y£ k, \o — Ck\ < \o — Ci\- This means that: Vi, ( Q - a ) + (p- p ) 2 + (d - d ) + {d - d , f + (P- Pi) + (di - d ) + (d - d ,i) 2 k 2 k (a - ) 2 x ltk 2 ai 2 u 2 + (d - d , ) 2 2 k 3 2 2 2 3 k + (d - d ) 2 3 3A + (d - d , ) 2 4 4 + (d - d 4 k < ) . 2 4 ] i B y multiplying the first two terms on either side of the inequality by 1 = (—l) and reversing the 2 order of the last four terms on each side we get: Vi, (-a - (-a )) + (-p - (-p )) 2 + (d - d^) 2 k 2 (-a - (-at)) k 2 4 + (-p - (-P,)) 2 But this simply states that for all i, |6 + (d - d , ) + (d - d , ) + (d - d ) + (d - d ) + (da - d ) + (d, - + (d - d ) 2 4 — C/il < 2 3 4ii \o — 3 k 2 3 Cili 3il 2 2 2 k 2 2A < 2 1 which is the same as saying that lik d ). 2 hi 0 lies in the Voronoi cell of node k. This is exactly what we set out to show, so the symmetric node policy representation that we are using, indeed ensures a left-right symmetric policy. It is easy to show that similar symmetric node representations for the observation spaces of the car and two-trailer truck also ensure left-right symmetric policies. Note that this definition is not contradictory, since the location and action of a node are the same as the location and action of a node's partner's partner. 1 Appendix C.2 C. Vehicle Steering: Additional 100 Information Equations of Motion This section describes how we obtain the truck state at simulation time step, s .= t from the state at the previous time step, s ~i = (x -i,yt-i, t (x , yt, Ot, o-t, d , fit) t t #t-i, c*t-i, &t-i, Pt-i), where (x , yt) = Pt t t is the position of the truck cab center, Ot is angle that the long axis of the truck cab makes with the positive x-axis, at is the angle of the steered wheels, a is the angular velocity of the steered wheels, t and p , is the hitch angle, all at discrete time step t. Let T t t s ep = 0.01 s be the duration of a time step and v = 1.0 units/s be the speed of the vehicle. The following equations of motion are for the forward-driving truck. They can easily be modified to remove the trailer or add more trailers. If the vehicle is to drive backwards, the speed, v, can be changed to a negative value, but otherwise the same equations of motion can be used. If the steered wheels are pointed straight ahead, i.e, a -\ = 0, the new truck cab position, (x ,yt) t t is calculated simply, as follows: x <— x + vT te cos(# -i) t t s P t Vt *-Vt + vT tep sin(0 _i). s Otherwise, if at-i t i= 0, the new position of the point between the front wheels, Pf t = {xf,t,yf,t) : and the new position of the point between the back wheels, Pb,t = (xb,t,yb,t) is computed, as illustrated in Figure C . l . In the figure, the trailer of the truck is not shown for clarity. It is assumed that the point between the front wheels will move in the direction that the steered wheels are pointing: f,t x <— f,t + vT x step cos(0 _i + Vf,t *~'Vf,t + vT epSm(0 -i st a -i) t t + t a -i). t It is also assumed that the point between the back wheels will move in the direction that truck cab is pointing. The point, (xt,^,yb,t), is thus found by computing a point that lies on the long axis of the car a distance of df + db away from {xf t,y/ t), t t where df and db are the distances from the center of the car to the front and rear axles, respectively. A quadratic equation that encodes these constraints can be solved to get {xb,t,yb,t)- The new cab position, (x ,yt) is then determined by finding the t appropriate point on the line segment between Pf t and Pf, : t D i \ Pt = (x ,y )* t t it dbPj,t + dfPb,t J]Tdb~^- The angle B can be computed as the angle that vector, P; t t x / r i 1 ( C 1 ) — Pb t, makes with the a;-axis. t The motion of the trailer is calculated using a method similar to that which is used to compute the motion of the cab. The new position of the hitch is given by Pb,t = (xb,t,Vb,t)- The point between Appendix C. Vehicle Steering: Additional Information 101 y /K Figure C . l : Determining the motion of the truck during a simulation time step. the wheels of the trailer is constrained to move along the direction of the trailer, and the new position of this point can be found by solving a quadratic equation. Given this point, it is simple to determine Pt, the new angle of the trailer relative to the cab. Given the angular acceleration of the steered wheels, d, Euler integration is used to calculate the new angular velocity, d , and angle, a , of the steered wheels. t C.3 t Perturbation Algorithm Algorithm 6 outlines the perturbation routine for the vehicle steering policy search. This is distinct from Algorithm 5 in that the parameters for each policy node are perturbed separately. If a node has a large energy, as stored in the energy noa e vector, it is more likely to be perturbed and have its parameters modified to a larger degree. The action, fi = d, of a node is perturbed by the d step and clipped to within the range [—1,1] radians. The location, £, of a node is perturbed by moving it ^ ' " ^ closer to a sample observation encountered during the previous policy evaluation and within the node's Voronoi cell. The call to observationsample(i) provides such a sample from Voronoi cell i. Perturbing node locations in this manner has the effect of keeping them within regions of the observable state space, O, which are visited regularly while still allowing the locations and actions Appendix 102 C. Vehicle Steering: Additional Information Algorithm 6 perturbation2(-K, p) input 7r {policy} input p {current optimization step size and total perturbation energy} global n {number of nodes and index of the newly added node} global pi it {initial optimization step size before decay} define energy d {vector - perturbation energy of each node} define d d {step for current node} define (sample {sample observable state within Voronoi cell of node - vector of size de> observable state mapped onto location parameters} energy <— 0 energy de <— propagate_perturbation(n, p, energy„ode) for i <— 1... n do if Rand(0,1) < ^ " ' ^ " ^ ' ' 1 then n no no e e node no dstep = energy^de [i] Rand(-1,1) 7T.0 < — 7T.0 + d in dimension of p.% (sample *~ observation_sample(i) for j <— each location parameter index for node i do stev n.Q[j] - TT.QlJ} + ^A(( [j] sample - n.e[j}) end for end if end for clip 77.0 to [n.min, n.max] O U t p u t 7T to be optimized. The node location parameters are not clipped to a particular range, but they still remain close to the typical region of operation of the policy in O. The energynode value for each node is determined by the propagate-perturbation recursive routine (see Algorithm 7), which propagates the perturbation energy specified by the energy parameter from node inode to neighbouring nodes and accumulates the results in the energy de no vector. Of the energy that comes into node i de, portions may be propagated to each neighbouring node, while the rest no is kept to that node. The portions that are kept or propagated depend on the transitions between Voronoi cells during the previous evaluation of the policy, ir. These transitions are recorded in the transitions matrix, where for each time step t during the evaluation, transitions[c(o )][c(o +\)] t incremented . The constants used to obtain our results are fraction i 2 m n = 0.1, fraction x = 40, and energythresh = 0.05. 2 t Recall from Equation 3.1 that c(o) is the index of the active node given observation, o. max is = 1.0, Appendix 103 C. Vehicle Steering: Additional Information Algorithm 7 propagatejperturbation(i d , energy, energy d ) input i {node index} input energy {energy entering node} input energy de *- P {total perturbation energy} global transitions {matrix of transitions between Voronoi cells} global fraction in global fractionmax global x global energythresh define fractionk t {fraction of energy kept by node i e} define connection {vector - the transitions between i de and each node} for i <— 1... n do connection\i] <— transitions[i de\[i] + transitions[i][i de\ connection otai <~ connection tai + connection[i] end for fractionkept <— fraction + (fraction - /raetion i )( °™^',°^^ ) fraction energy energy de[inode] <— energy de[inode\ + energy energy <— energy energy t connectiontotai <— connectiontotai — connection\i de] for i «— all node indices except i de do connectionli] energyportion <- energy if energy rtion > energythresh then energy ode < — propagate.perturbation(i, energyportion, energy d ) else energy de\inode] *- energy' de[inode} + energyportion end if end for output energynode no e no e no m ep nod no no t no to c min max m x n kept no no kept kep no no c o n n e c t i o n p0 n no no no e energy kept <- 104 Bibliography Bibliography [AM03] Christopher G. Atkeson and Jun Morimoto. Nonparametric representation of policies and value functions: A trajectory-based approach. In S. Thrun S. Becker and K . Obermayer, editors, Advances in Neural Information Processing Systems 15, pages 1611-1618. 2003. [And87] Charles W . Anderson. Strategy learning with multilayer connectionist representations. In Proceedings of the Fourth International Workshop on Machine Learning, pages 103-114. Morgan Kaufmann, 1987. [ASW01] C. Altafini, A . Speranzon, and B . Wahlberg. A feedback control scheme for reversing a truck and trailer vehicle. IEEE Transactions on Robotics and Automation, 17(6):915-922, December 2001. [Bel57] Richard Bellman. Dynamic Programming. Princeton University Press, 1957. [Bis95] Christopher M . Bishop. Neural Networks for Pattern Recognition. Oxford University Press, 1995. [BM99] L . Baird and A . Moore. Gradient descent for general reinforcement learning. In Advances in Neural Information Processing Systems 11, pages 968-974, 1999. [BSA83] A . G . Barto, R. S. Sutton, and C. W . Anderson. Neuronlike adaptiveelements that can solve difficult learning control problems. IEEE Transactions on Systems, Man, and Cybernetics, 13,5, pages 834-846, 1983. [BT96] Dimitri P. Bersekas and John N . Tsitsiklis. Neuro-Dynamic Programming. Athena Scientific, 1996. [CKL94] Anthony Cassandra, Leslie Pack Kaelbling, and Michael Littman. Acting optimally in partially observable stochastic domains. In Twelfth National Conference on Artificial Intelligence, (AAAI) Seattle, WA, 1994. [Cou02] Remi Coulom. Reinforcement Learning Using Neural Networks, with Applications to Motor Control. P h D thesis, Institut National Polytechnique de Grenoble, 2002. 105 Bibliography [DoyOO] Kenji Doya. Reinforcement learning in continuous time and space. Neural Computation, 12:243-269, 2000. [DW91] Thomas L . Dean and Michael P. Wellman. Planning and Control. Morgan Kaufmann Publishers, San Mateo, California, 1991. [DW97] A . Divelbiss and J . T. Wen. Trajectory tracking control of a car trailer system. IEEE Transactions on Control Systems Technology, 5(3):269-278, May 1997. [FA02] J. Forbes and D. Andre. Representations for learning control policies. In Proceedings of the ICML-2002 Workshop on Development of Representations, pages 7-14, 2002. [Gri97] Larry Gritz. Genetic programming evolution of controllers for 3-d character animation. Genetic Programming 1997: Proceedings of the 2nd Annual Conference, pages 139-146, 1997. [HFGS96] D. F . Hougen, J . Fischer, M . Gini, and J . Slagle. Fast connectionist learning for trailer backing using a real robot. In IEEE International Conference on Robotics and Automation, pages 1917-1922, 1996. [HGS97] D. F . Hougen, M . Gini, and J . Slagle. Rapid, unsupervised connectionist learning for backing a robot with two trailers. In IEEE International Conference on Robotics and Automation, 1997. [HKLR02] David Hsu, Robert Kindel, Jean-Claude Latombe, and Stephen Rock. Randomized kinodynamic motion planning with moving obstacles. Int. J. of Robotics Research, 21(3):233255, March 2002. [KLM96] Leslie Pack Kaelbling, Michael L . Littman, and Andrew W . Moore. Reinforcement learning: A survey. Journal of Artificial Intelligence Research, ^-.237-285, 1996. [KN03] A . Kelly and B . Nagy. Reactive nonholonomic trajectory generation via parametric optimal control. The International Journal of Robotics Research, 22(7):583-601, July 2003. [Koz92] J . R. Koza. A genetic approach to finding a controller to back up a tractor-trailer truck. In Proceedings of the American Control Conference, 1992. [Lar68] R. E . Larson. State Increment Dynamic Programming. Elsevier, New York, 1968. [Lat91] Jean-Claude Latombe. Robot Motion Planning. Kluwer Academic Publishers, 1991. Bibliography 106 [MA95] Andrew Moore and Chris Atkeson. The parti-game algorithm for variable resolution reinforcement learning in multidimensional state-spaces. Machine Learning, 21:1-36, 1995. [MM02] R. Munos and A . Moore. Variable resolution discretization in optimal control. Machine Learning, 49, Numbers 2/3:291-323, November/December 2002. [MPKK99] Nicolas Meuleau, Leonid Peshkin, Kee-Eung K i m , and Leslie Pack Kaelbling. Learning finite-state controllers for partially observable environments. In UAI1999, pages 427-436, 1999. [Ng03] Andrew Y . Ng. Shaping and policy search in Reinforcement learning, P h D thesis, University of California, Berkeley, 2003. [NM93] J . T. Ngo and J . Marks. Spacetime constraints revisited. Proceedings of ACM SIGGRAPH '93, pages 343-350, 1993. [NW89] D. H . Nguyen and B . Widrow. The truck backer-upper: A n example of self-learning in neural networks. In Proceedings of the International Joint Conference on Neural Networks (IJCNN89), pages 357-363, 1989. [Oga70] Katsuhiko Ogata. Modern Control Engineering. Prentice Hall, Inc., Englewood Cliffs, N.J., 1970. [Pas98] F . Pasemann. Evolving neurocontrollers for balancing an inverted pendulum. Network: Computational Neural Systems. 9, pages 495-511, 1998. [PH98] L . D. Pyeatt and A . E . Howe. Learning to race: Experiments with a simulated race car. In 11th International Floria Artificial Intelligence Research Society Conference, 1998. [PTVF97] William H . Press, Saul A . Teukolsky, Willaim T. Vetterling, and Brian P. Flannery. Numerical Recipes in C: The Art of Scientific Computing. Cambridge University Press, 1997. [RB01] M . T . Rosenstein and A . G . Barto. Robot weightlifting by direct policy search. In Proceedings ofUCAI 2001, pages 839-844, 2001. [RK03] S. Ramamoorthy and B . Kuipers. Qualitative heterogeneous control of higher order systems. Hybrid Systems: Computation and Control, Lecture Notes in Computer Science, 2003. 107 Bibliography [RN0098] Muchammad Romzi, Junji Nishino, Tomohiro Odaka, and Hisakazu Ogura. Refining fuzzy control rules for the inverted double pendulum system based on a transformation-type genetic algorithm. Systems and Computers in Japan 29(14), pages 50-55, 1998. [SB98] Richard S. Sutton and Andrew G . Barto. Reinforcement Learning: An Introduction. M I T Press, 1998. [Sha04] Dana Sharon. Synthesis of stylized walking controllers for planar bipeds. Master's thesis, University of British Columbia, 2004. [Sim94] Karl Sims. Evolving virtual creatures. Proceedings of ACM SIGGRAPH '94, pages 15-22, 1994. [SK01] William D. Smart and Leslie Pack Kaelbling. Reinforcement learning for robot control. Mobile Robots XVI, 2001. [SSR99] Feijun Song, S.M. Smith, and C . G . Rizk. A fuzzy logic controller design methodology for 4d systems with optimal global performance using enhanced cell state space based best estimate directed search method. IEEE International Conference on Systems, Man and Cybernetics, pages 138-143, 1999. [Sti99] Andrew K . Stimac. Standup and stabilization of the inverted pendulum. Master's thesis, Massachusetts Institute of Technology, 1999. [Tes95] G . Tesauro. Temporal difference learning and td-gammon. Communications of the ACM, 38(3):58-67, 1995. [vdPF93] Michiel van de Panne and Eugene Fiume. Sensor-actuator networks. Proceedings of ACM SIGGRAPH '93, pages 335-342, 1993.
- Library Home /
- Search Collections /
- Open Collections /
- Browse Collections /
- UBC Theses and Dissertations /
- Shaping and policy search for nearest-neighbour control...
Open Collections
UBC Theses and Dissertations
Featured Collection
UBC Theses and Dissertations
Shaping and policy search for nearest-neighbour control policies with applications to vehicle steering Alton, Ken 2004
pdf
Page Metadata
Item Metadata
Title | Shaping and policy search for nearest-neighbour control policies with applications to vehicle steering |
Creator |
Alton, Ken |
Date Issued | 2004 |
Description | The graceful animal motion we see in nature has proven extremely difficult to reproduce algorithmically. There is a need for further research into motion control techniques to address this problem adequately for computer animation and robotics applications. In this thesis, we describe a novel method for the synthesis of compact control policies for a variety of motion control problems. Direct policy search is applied to a nearest-neighbour control policy, which uses a Voronoi cell discretization of the observable state space, as induced by a set of control nodes located in this space. Such a semi-parametric representation allows for policy refinement through the adaptive addition of nodes. Thus, a coarse-to-fine policy search can be performed in such a way that the problem is shaped for easy learning. We apply our method to developing policies for steering various vehicles around a winding track. In particular, a policy is learned to steer a double-trailer truck backwards, a problem of considerable difficulty given the instability of the trailers. We also generate policies for the problems of balancing an inverted pendulum on a moving cart and driving the state of a point mass around a user-specified limit cycle. We examine these motion control results critically and discuss the limitations of the nearest-neighbour policy representation and our policy search method. |
Extent | 5695597 bytes |
Genre |
Thesis/Dissertation |
Type |
Text |
File Format | application/pdf |
Language | eng |
Date Available | 2009-12-02 |
Provider | Vancouver : University of British Columbia Library |
Rights | For non-commercial purposes only, such as research, private study and education. Additional conditions apply, see Terms of Use https://open.library.ubc.ca/terms_of_use. |
DOI | 10.14288/1.0051749 |
URI | http://hdl.handle.net/2429/16091 |
Degree |
Master of Science - MSc |
Program |
Computer Science |
Affiliation |
Science, Faculty of Computer Science, Department of |
Degree Grantor | University of British Columbia |
Graduation Date | 2004-11 |
Campus |
UBCV |
Scholarly Level | Graduate |
Aggregated Source Repository | DSpace |
Download
- Media
- 831-ubc_2005-0001.pdf [ 5.43MB ]
- Metadata
- JSON: 831-1.0051749.json
- JSON-LD: 831-1.0051749-ld.json
- RDF/XML (Pretty): 831-1.0051749-rdf.xml
- RDF/JSON: 831-1.0051749-rdf.json
- Turtle: 831-1.0051749-turtle.txt
- N-Triples: 831-1.0051749-rdf-ntriples.txt
- Original Record: 831-1.0051749-source.json
- Full Text
- 831-1.0051749-fulltext.txt
- Citation
- 831-1.0051749.ris
Full Text
Cite
Citation Scheme:
Usage Statistics
Share
Embed
Customize your widget with the following options, then copy and paste the code below into the HTML
of your page to embed this item in your website.
<div id="ubcOpenCollectionsWidgetDisplay">
<script id="ubcOpenCollectionsWidget"
src="{[{embed.src}]}"
data-item="{[{embed.item}]}"
data-collection="{[{embed.collection}]}"
data-metadata="{[{embed.showMetadata}]}"
data-width="{[{embed.width}]}"
async >
</script>
</div>
Our image viewer uses the IIIF 2.0 standard.
To load this item in other compatible viewers, use this url:
http://iiif.library.ubc.ca/presentation/dsp.831.1-0051749/manifest