multi-agent machine · multi-agent machine learning a reinforcement approach howard m. schwartz...

26

Upload: others

Post on 29-Sep-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University
Page 2: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University
Page 3: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

Multi-Agent MachineLearning

Page 4: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University
Page 5: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

Multi-Agent MachineLearning

A Reinforcement Approach

Howard M. SchwartzDepartment of Systems and Computer Engineering

Carleton University

Page 6: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

Copyright © 2014 by John Wiley & Sons, Inc. All rights reserved

Published by John Wiley & Sons, Inc., Hoboken, New JerseyPublished simultaneously in Canada

No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form orby any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except aspermitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the priorwritten permission of the Publisher, or authorization through payment of the appropriate per-copy fee tothe Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978)750-4470, or on the web at www.copyright.com. Requests to the Publisher for permission should beaddressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030,(201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts inpreparing this book, they make no representations or warranties with respect to the accuracy orcompleteness of the contents of this book and specifically disclaim any implied warranties ofmerchantability or fitness for a particular purpose. No warranty may be created or extended by salesrepresentatives or written sales materials. The advice and strategies contained herein may not be suitablefor your situation. You should consult with a professional where appropriate. Neither the publisher norauthor shall be liable for any loss of profit or any other commercial damages, including but not limited tospecial, incidental, consequential, or other damages.

For general information on our other products and services or for technical support, please contact ourCustomer Care Department within the United States at (800) 762-2974, outside the United States at (317)572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print maynot be available in electronic formats. For more information about Wiley products, visit our web site atwww.wiley.com.

Library of Congress Cataloging-in-Publication Data:

Schwartz, Howard M., editor.Multi-agent machine learning : a reinforcement approach / Howard M. Schwartz.

pages cmIncludes bibliographical references and index.ISBN 978-1-118-36208-2 (hardback)

1. Reinforcement learning. 2. Differential games. 3. Swarm intelligence. 4. Machine learning. I. Title.Q325.6.S39 2014519.3–dc23

2014016950

Printed in the United States of America

10 9 8 7 6 5 4 3 2 1

Page 7: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Chapter 1 A Brief Review of Supervised Learning . . . . . . . . . 1

1.1 Least Squares Estimates . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2 Recursive Least Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.3 Least Mean Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

1.4 Stochastic Approximation . . . . . . . . . . . . . . . . . . . . . . . . . 10

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Chapter 2 Single-Agent Reinforcement Learning . . . . . . . . . . 12

2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2.2 n-Armed Bandit Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

2.3 The Learning Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2.4 The Value Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

2.5 The Optimal Value Functions . . . . . . . . . . . . . . . . . . . . . . . 18

2.5.1 The Grid World Example . . . . . . . . . . . . . . . . . . . . . 202.6 Markov Decision Processes . . . . . . . . . . . . . . . . . . . . . . . . 23

2.7 Learning Value Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 25

2.8 Policy Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

2.9 Temporal Difference Learning . . . . . . . . . . . . . . . . . . . . . . 28

2.10 TD Learning of the State-Action Function . . . . . . . . . . 30

v

Page 8: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

vi Contents

2.11 Q-Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

2.12 Eligibility Traces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Chapter 3 Learning in Two-Player Matrix Games . . . . . . . . . . 38

3.1 Matrix Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

3.2 Nash Equilibria in Two-Player Matrix Games . . . . . . . 42

3.3 Linear Programming in Two-Player Zero-Sum Matrix

Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

3.4 The Learning Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

3.5 Gradient Ascent Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 47

3.6 WoLF-IGA Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

3.7 Policy Hill Climbing (PHC) . . . . . . . . . . . . . . . . . . . . . . . . . 52

3.8 WoLF-PHC Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

3.9 Decentralized Learning in Matrix Games . . . . . . . . . . . 57

3.10 Learning Automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

3.11 Linear Reward–Inaction Algorithm . . . . . . . . . . . . . . . . . 59

3.12 Linear Reward–Penalty Algorithm . . . . . . . . . . . . . . . . . . 60

3.13 The Lagging Anchor Algorithm . . . . . . . . . . . . . . . . . . . . . 60

3.14 LR−I Lagging Anchor Algorithm . . . . . . . . . . . . . . . . . . . . 62

3.14.1 Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

Chapter 4 Learning in Multiplayer Stochastic Games . . . . . . 73

4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

4.2 Multiplayer Stochastic Games . . . . . . . . . . . . . . . . . . . . . . 75

4.3 Minimax-Q Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

4.3.1 2 × 2 Grid Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804.4 Nash Q-Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

4.4.1 The Learning Process . . . . . . . . . . . . . . . . . . . . . . . . . 954.5 The Simplex Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

4.6 The Lemke–Howson Algorithm . . . . . . . . . . . . . . . . . . . . 100

4.7 Nash-Q Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

4.8 Friend-or-Foe Q-Learning . . . . . . . . . . . . . . . . . . . . . . . . . . 111

4.9 Infinite Gradient Ascent . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

Page 9: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

Contents vii

4.10 Policy Hill Climbing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

4.11 WoLF-PHC Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

4.12 Guarding a Territory Problem in a Grid World . . . . . . 117

4.12.1 Simulation and Results . . . . . . . . . . . . . . . . . . . . . . . 1194.13 Extension of LR−I Lagging Anchor Algorithm to

Stochastic Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

4.14 The Exponential Moving-Average Q-Learning

(EMA Q-Learning) Algorithm . . . . . . . . . . . . . . . . . . . . . . . 128

4.15 Simulation and Results Comparing EMA

Q-Learning to Other Methods . . . . . . . . . . . . . . . . . . . . . . 131

4.15.1 Matrix Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1314.15.2 Stochastic Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

Chapter 5 Differential Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

5.2 A Brief Tutorial on Fuzzy Systems . . . . . . . . . . . . . . . . . 146

5.2.1 Fuzzy Sets and Fuzzy Rules . . . . . . . . . . . . . . . . . . . 1465.2.2 Fuzzy Inference Engine . . . . . . . . . . . . . . . . . . . . . . . 1485.2.3 Fuzzifier and Defuzzifier . . . . . . . . . . . . . . . . . . . . . . 1515.2.4 Fuzzy Systems and Examples . . . . . . . . . . . . . . . . . . 152

5.3 Fuzzy Q-Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

5.4 Fuzzy Actor–Critic Learning . . . . . . . . . . . . . . . . . . . . . . . 159

5.5 Homicidal Chauffeur Differential Game . . . . . . . . . . . . . 162

5.6 Fuzzy Controller Structure . . . . . . . . . . . . . . . . . . . . . . . . . 165

5.7 Q(𝝀)-Learning Fuzzy Inference System . . . . . . . . . . . . . 166

5.8 Simulation Results for the Homicidal Chauffeur . . . . 171

5.9 Learning in the Evader–Pursuer Game with Two

Cars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

5.10 Simulation of the Game of Two Cars . . . . . . . . . . . . . . . 177

5.11 Differential Game of Guarding a Territory . . . . . . . . . . . 180

5.12 Reward Shaping in the Differential Game

of Guarding a Territory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184

5.13 Simulation Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

5.13.1 One Defender Versus One Invader . . . . . . . . . . . . . 1855.13.2 Two Defenders Versus One Invader . . . . . . . . . . . . 191References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197

Page 10: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

viii Contents

Chapter 6 Swarm Intelligence and the Evolutionof Personality Traits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

6.2 The Evolution of Swarm Intelligence . . . . . . . . . . . . . . . 200

6.3 Representation of the Environment . . . . . . . . . . . . . . . . 201

6.4 Swarm-Based Robotics in Terms

of Personalities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203

6.5 Evolution of Personality Traits . . . . . . . . . . . . . . . . . . . . . 206

6.6 Simulation Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207

6.7 A Zero-Sum Game Example . . . . . . . . . . . . . . . . . . . . . . . . 208

6.7.1 Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2086.7.2 Simulation Results . . . . . . . . . . . . . . . . . . . . . . . . . . . 214

6.8 Implementation for Next Sections . . . . . . . . . . . . . . . . . . 216

6.9 Robots Leaving a Room . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

6.10 Tracking a Target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

6.11 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

Page 11: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

Preface

For a decade I have taught a course on adaptive control. The course focused onthe classical methods of system identification, using such classic texts as Ljung[1, 2]. The course addressed traditional methods of model reference adaptivecontrol and nonlinear adaptive control using Lyapunov techniques. However,the theory had become out of sync with current engineering practice. As such,my own research and the focus of the graduate course changed to include adap-tive signal processing, and to incorporate adaptive channel equalization andecho cancellation using the least mean squares (LMS) algorithm. The coursename likewise changed, from “Adaptive Control” to “Adaptive and LearningSystems.”My research was still focused on system identification and nonlinearadaptive control with application to robotics. However, by the early 2000s, Ihad started work with teams of robots. It was now possible to use handy robotkits and low-cost microcontroller boards to build several robots that couldwork together. The graduate course in adaptive and learning systems changedagain; the theoretical material on nonlinear adaptive control using Lyapunovtechniques was reduced, replaced with ideas from reinforcement learning. Awhole new range of applications developed. The teams of robots had to learnto work together and to compete.

Today, the graduate course focuses on system identification using recursiveleast squares techniques, some model reference adaptive control (still usingLyapunov techniques), adaptive signal processing using the LMS algorithm,and reinforcement learning using Q-learning. The first two chapters of thisbook present these ideas in an abridged form, but in sufficient detail to demon-strate the connections among the learning algorithms that are available; howthey are the same; and how they are different. There are other texts that coverthis material in detail [2–4].

ix

Page 12: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

x Preface

The research then began to focus on teams of robots learning to work together.The work examined applications of robots working together for search andrescue applications, securing important infrastructure and border regions. Italso began to focus on reinforcement learning and multiagent reinforcementlearning. The robots are the learning agents. How do children learn how toplay tag? How do we learn to play football, or how do police work togetherto capture a criminal? What strategies do we use, and how do we formulatethese strategies? Why can I play touch football with a new group of peopleand quickly be able to assess everyone’s capabilities and then take a particularstrategy in the game?

As our research team began to delve further into the ideas associated withmultiagent machine learning and game theory, we discovered that the pub-lished literature covered many ideas but was poorly coordinated or focused.Although there are a few survey articles [5], they do not give sufficient detailsto appreciate the different methods. The purpose of this book is to introducethe reader to a particular form of machine learning. The book focuses onmultiagent machine learning, but it is tied together with the central theme oflearning algorithms in general. Learning algorithms come in many differentforms. However, they tend to have a similar approach. We will present the dif-ferences and similarities of these methods.

This book is based onmy ownwork and the work of several doctoral andmas-ters students who have worked under my supervision over the past 10 years. Inparticular, I would like to thank Prof. Sidney Givigi. Prof. Givigi was instru-mental in developing the ideas and algorithms presented in Chapter 6. Thedoctoral research of Xiaosong (Eric) Lu has also found its way into this book.The work on guarding a territory is largely based on his doctoral dissertation.Other graduate students who helped me in this work include Badr Al Faiya,Mostafa Awheda, Pascal De Beck-Courcelle, and Sameh Desouky. Withoutthe dedicated work of this group of students, this book would not have beenpossible.

H. M. SchwartzOttawa, CanadaSeptember, 2013

References

[1] L. Ljung, System Identification: Theory for the User. Upper Saddle River, NJ: Prentice Hall,2nd ed., 1999.

Page 13: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

Preface xi

[2] L. Ljung and T. Soderstrom, Theory and Practice of Recursive Identification. Cambridge,Massachusetts: The MIT Press, 1983.

[3] R. S. Sutton and A. G. Barto, Reinforcement learning: An Introduction. Cambridge, Mas-sachusetts: The MIT Press, 1998.

[4] Astrom, K. J. and Wittenmark, B., Adaptive Control. Boston, Massachusetts:Addison-Wesley Longman Publishing Co., Inc., 2nd ed., 1994, ISBN = 0201558661.

[5] L. Busoniu and R. Babuška, and B. D. Schutter, “A comprehensive survey of multiagentreinforcement learning,” IEEETrans. Syst.Man Cybern. Part C, Vol. 38, no. 2, pp. 156–172,2008.

Page 14: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University
Page 15: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

Chapter 1

A Brief Review of Supervised Learning

There are a number of algorithms that are typically used for system identi-fication, adaptive control, adaptive signal processing, and machine learning.These algorithms all have particular similarities and differences. However, theyall need to process some type of experimental data. How we collect the dataand process it determines the most suitable algorithm to use. In adaptive con-trol, there is a device referred to as the self-tuning regulator. In this case, thealgorithmmeasures the states as outputs, estimates the model parameters, andoutputs the control signals. In reinforcement learning, the algorithms processrewards, estimate value functions, and output actions. Although one may referto the recursive least squares (RLS) algorithm in the self-tuning regulator as asupervised learning algorithm and reinforcement learning as an unsupervisedlearning algorithm, they are both very similar. In this chapter, we will presenta number of well-known baseline supervised learning algorithms.

1.1 Least Squares Estimates

The least squares (LS) algorithm is a well-known and robust algorithm forfitting experimental data to a model. The first step is for the user to definea mathematical structure or model that he/she believes will fit the data. Thesecond step is to design an experiment to collect data under suitable conditions.“Suitable conditions” usually means the operating conditions under which the

Multi-Agent Machine Learning: A Reinforcement Approach, First Edition. Howard M. Schwartz.© 2014 John Wiley & Sons, Inc. Published 2014 by John Wiley & Sons, Inc.

1

Page 16: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

2 Multi-Agent Machine Learning: The Reinforcement Approach

system will typically operate. The next step is to run the estimation algorithm,which can take several forms, and, finally, validate the identified or “learned”model. The LS algorithm is often used to fit the data. Let us look at the case ofthe classical two-dimensional linear regression fit that we are all familiar with:

y(n) = ax(n) + b (1.1)

In this a simple linear regression model, where the input is the sampled sig-nal x(n) and the output is y(n). The model structure defined is a straight line.Therefore, we are assuming that the data collected will fit a straight line. Thiscan be written in the form

y(n) = 𝜙T𝜃 (1.2)

where 𝜙T =[x(n) 1

]and 𝜃T =

[a b

]. How one chooses 𝜙 determines the

model structure, and this reflects how one believes the data should behave.This is the essence of machine learning, and virtually all university studentswill at some point learn the basic statistics of linear regression. Behind thecomputations of the linear regression algorithm is the scalar cost function,given by

V =N∑n=1

(y(n) − 𝜙T (n)��)2 (1.3)

The term �� is the estimate of the LS parameter 𝜃. The goal is for the estimate ��to minimize the cost function V . To find the “optimal” value of the parameterestimate ��, one takes the partial derivative of the cost function V with respectto �� and sets this derivative to zero. Therefore, one gets

𝜕V

𝜕��=

N∑n=1

(y(n) − 𝜙T (n)��)𝜙(n)

=N∑n=1

𝜙(n)y(n) −N∑n=1

𝜙(n)𝜙T (n)�� (1.4)

Setting𝜕V

𝜕��= 0, we get

N∑n=1

𝜙(n)𝜙T (n)�� =N∑n=1

𝜙(n)y(n) (1.5)

Page 17: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

A Brief Review of Supervised Learning 3

Solving for ��, we get the LS solution

�� =

[N∑n=1

𝜙(n)𝜙T (n)

]−1 [ N∑n=1

𝜙(n)y(n)

](1.6)

where the inverse,[∑N

n=1 𝜙(n)𝜙T (n)]−1

, exists. If the inverse does not exist, thenthe system is not identifiable. For example, if in the straight line case one onlyhad a single point, then the inverse would not span the two-dimensional spaceand it would not exist. One needs at least two independent points to draw astraight line. Or, for example, if one had exactly the same point over and overagain, then the inverse would not exist. One needs at least two independentpoints to draw a straight line. Thematrix

[∑Nn=1 𝜙(n)𝜙T (n)

]is referred to as the

information matrix and is related to how well one can estimate the parameters.The inverse of the information matrix is the covariance matrix, and it is pro-portional to the variance of the parameter estimates. Both these matrices arepositive definite and symmetric. These are very important properties which areused extensively in analyzing the behavior of the algorithm. In the literature,

one will often see the covariancematrix referred to asP =[∑N

n=1 𝜙(n)𝜙T (n)]−1

.We can write the second equation on the right of Eq. (1.4) in the form

𝜕V

𝜕��= 0 =

N∑n=1

(y(n) − 𝜙T (n)��)𝜙(n) (1.7)

and one can define the prediction errors as

𝜖(n) = (y(n) − 𝜙T (n)��) (1.8)

The term within brackets in Eq. (1.7) is known as the prediction error or, assome people will refer to it, the innovations. The term 𝜖(n) represents the errorin predicting the output of the system. In this case, the output term y(n) is thecorrect answer, which is what we want to estimate. Since we know the correctanswer, this is referred to as supervised learning. Notice that the value of theprediction error times the data vector is equal to zero. We then say that theprediction errors are orthogonal to the data, or that the data sits in the nullspace of the prediction errors. In simplistic terms, this means that, if one haschosen a good model structure 𝜙(n), then the prediction errors should appearas white noise. Always plot the prediction errors as a quick check to see howgood your predictor is. If the errors appear to be correlated (i.e., not whitenoise), then you can improve your model and get a better prediction.

Page 18: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

4 Multi-Agent Machine Learning: The Reinforcement Approach

One does not typically write the linear regression in the form of Eq. (1.2), buttypically will add a white noise term, and then the linear regression takes theform

y(n) = 𝜙T (n)𝜃 + 𝑣(n) (1.9)

where 𝑣(n) is a white noise term. Equation (1.9) can represent an infinite num-ber of possible model structures. For example, let us assume that we want tolearn the dynamics of a second-order linear system or the parameters of asecond-order infinite impulse response (IIR) filter. Then we could choose thesecond-order model structure given by

y(n) = −a1y(n − 1) − a2y(n − 2) + b1u(n − 1) + b2u(n − 2) + 𝑣(n) (1.10)

Then the model structure would be defined in 𝜙(n) as

𝜙T (n) =[y(n − 1) y(n − 2) u(n − 1) u(n − 2)

](1.11)

In general, one can write an arbitrary kth-order autoregressive exogenous(ARX) model structure as

y(n) = −a1y(n − 1) − a2y(n − 2) − · · · − amy(n − k)

+ b1u(n − 1) + b2u(n − 2) + · · · + bn−ku(n − k) + 𝑣(n) (1.12)

and 𝜙(n) takes the form

𝜙T (n) =[y(n − 1) · · · y(n −m) u(n − 1) · · · u(n −m)

](1.13)

One then collects the data from a suitable experiment (easier said than done!),and then computes the parameters using Eq. (1.6). The vector 𝜙(n) can takemany different forms; in fact, it can contain nonlinear functions of the data,for example, logarithmic terms or square terms, and it can have different delayterms. To a large degree, one can use ones professional judgment as to what toput into 𝜙(n). One will often write the data in the matrix form, in which casethe matrix is defined as

Φ =[𝜙(1) 𝜙(2) · · · 𝜙(N)

](1.14)

and the output matrix as

Y =[y(1) y(2) · · · y(N)

](1.15)

Page 19: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

A Brief Review of Supervised Learning 5

Then one can write the LS estimate as

Θ = (ΦΦT )−1 ΦY (1.16)

Furthermore, one can write the prediction errors as

E = Y − ΦTΘ (1.17)

We can also write the orthogonality condition as ΦE = 0.

The LS method of parameter identification or machine learning is very welldeveloped and there aremany properties associatedwith the technique. In fact,much of the work in statistical inference is derived from the few equationsdescribed in this section. This is the beginning of many scientific investigationsincluding work in the social sciences.

1.2 Recursive Least Squares

The LS algorithm has been extended to the RLS algorithm. In this case, theparameter estimate is developed as the machine collects the data in real time.In the previous section, all the data was collected first, and then the para-meter estimates were computed on the basis of Eq. (1.6). The RLS algorithmis derived by assuming a solution to the LS algorithm and then adding a singledata point. The derivation is shown in Reference 1. In the RLS implementa-tion, the cost function takes a slightly different form. The cost function in thiscase is

V =N∑n=1

𝜆(N−t)(y(n) − 𝜙T (n)��)2 (1.18)

where 𝜆 ≤ 1. The term 𝜆 is known as the forgetting factor. This term will placeless weight on older data points. As such, the resulting RLS algorithm will beable track changes to the parameters. Once again, taking the partial derivativeof V with respect to �� and setting the derivative to zero, we get

�� =

[N∑n=1

𝜆(N−t)𝜙(n)𝜙T (n)

]−1 [ N∑n=1

𝜆(N−t)𝜙(n)y(n)

](1.19)

The forgetting factor should be set as 0.95 ≤ 𝜆 ≤ 1.0. If one sets the forgettingfactor near 0.95, then old data is forgotten very quickly; the rule of thumb isthat the estimate of the parameters �� is approximately based on 1∕(1 − 𝜆) datapoints.

Page 20: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

6 Multi-Agent Machine Learning: The Reinforcement Approach

The RLS algorithm is as follows:

��(n + 1) = ��(n) + L(n + 1)(y(n + 1) − 𝜙T (n + 1)��(n))

L(n + 1) = P(n)𝜙(n + 1)𝜆 + 𝜙T (n + 1)P(n)𝜙(n + 1)

P(n + 1) = 1𝜆

(P(n) − P(n)𝜙(n + 1)𝜙T (n + 1)P(n)

𝜆 + 𝜙T (n + 1)P(n)𝜙(n + 1)

)(1.20)

One implements Eq. (1.20) by initializing the parameter estimation vector ��to the users best initial estimate of the parameters, which is often simply zero.The covariance matrix P is typically initialized to a relatively large diagonalmatrix, and represents the initial uncertainty in the parameter estimate.

One can implement the RLS algorithm as in Eq. (1.20), but the user should becareful that the covariance matrix P is always positive definite and symmetric.If the Pmatrix, because of numerical error by repeatedly computing the RLS,ceases to be positive definite and symmetric, then the algorithm will diverge.There are a number of well-developed algorithms to ensure that the P matrixremains positive definite. One can use a square-roots approach whereby the Pmatrix is factored into its Cholesky factorization or the UDU factorization.Such methods are described in Reference 1.

Let us examine Eq. (1.20) and notice that the update to the parameter estimateis the previous estimate plus a matrix L(n) times the current prediction error.We will see this structure in almost every algorithm that will be described inmachine learning. In this case, we have an actual correct answer, which is themeasurement y(n), and we call such algorithms supervised learning.

1.3 Least Mean Squares

In the field of signal processing, there are a few commonly used techniques tomodel or characterize the dynamics of a communications channel and thencompensate for the effects of the channel on the signal. These techniques arereferred to as channel equalization and echo cancellation. There are numerousbooks on adaptive signal processing and adaptive filtering [2]. Most of thesetechniques use the least mean squares (LMS) approach to identify the coeffi-cients of a model of the channel. Once again, as in the LS andRLS algorithms,we must choose an appropriate model structure to define the communicationchannel dynamics. In the field of signal processing, one would typically usewhat is known as a finite impulse response (FIR) filter as the underlying model

Page 21: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

A Brief Review of Supervised Learning 7

structure that describes the system. To maintain consistency with the previoussection, one can write the channel dynamics as

y(n) = b0u(n) + b1u(n − 1) + · · · + bku(n − k) + 𝑣(n) (1.21)

where y(n) is the output of the filter, or the communications channel, at timestep n, bi are the filter coefficients that we want to estimate or learn, and u(n)is the input signal. Typically, the signal u(n) is the communication signal thatwe want to recover from the output signal y(n). We define an error signal

𝜖(n) = y(n) − y(n) (1.22)

where y(n) = 𝜙T (n)��. This is the same signal as the prediction error in Eq. (1.8).The LMS algorithm defines the cost function as the expected value of the pre-diction errors as

J(n) = E[𝜖2(n)] (1.23)

We can write the squared error term as

𝜖2(n) = (y(n) − 𝜙T (n)��)2

= y2(n) − 2y(n)𝜙T �� + ��T𝜙(n)𝜙T (n)�� (1.24)

We take the expectation and get

E[𝜖2(n)] = E[y2(n)] − 2��TE[y(n)𝜙(n)] + ��TE[𝜙(n)𝜙T (n)]�� (1.25)

We then define the variance 𝜎y = E[y2] as the mean squared power, and thecross-correlation vector is defined as p = E[y(n)𝜙(n)]. Thenwe define the infor-mation matrix, which is almost the same matrix as in Section 1.1, as R =E[𝜙(n)𝜙T (n)]. If the system statistics are stationary, that is, the statistics donot change, the terms 𝜎y, p, and R, are constants and the cost function, as afunction of changing ��, will have the shape of a bowl. The cost function J(n)can be written as

J(n) = 𝜎2y − 2��Tp + ��TR�� (1.26)

Once again, as in Eq. (1.4), to find the optimal parameter estimate �� to mini-mize the cost function, we take the partial derivative of the cost function J(n)with respect to ��, and determine the value of �� that sets the partial derivativeto zero. We can take the partial derivative of J(n) as

𝜕J(n)𝜕��

=𝜕𝜎2

y

𝜕��− 2

��Tp

𝜕��+ 𝜕��TR��

𝜕��(1.27)

Page 22: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

8 Multi-Agent Machine Learning: The Reinforcement Approach

We then compute the partial derivative for each of the terms on the right-handside of Eq. (1.27). Taking each term separately, we get

𝜕𝜎2y

𝜕��= 0

2��Tp

𝜕��= 2p (1.28)

𝜕��TR��

𝜕��= 2R��

Substituting into Eq. (1.27), we get

𝜕J(n)𝜕��

= −2p + 2R�� = 0 (1.29)

Solving for ��, we get the solution for the optimal parameter estimate as

𝜃∗ = R−1p (1.30)

Equation (1.30) is the well-knownWiener solution. However, theWiener solu-tion in Eq. (1.30) requires the computation of the inverse of a large matrix R.Notice the similarity between the Wiener solution and the LS solution in Eq.(1.6). Let us say that we want to estimate the expectations in Eq. (1.25); thenwe would get the average by computing

Ravg =

[1N

N∑n=1

𝜙(n)𝜙T (n)

]

pavg =

[1N

N∑n=1

𝜙(n)y(n)

](1.31)

Substituting the above values into Eq. (1.30), we get the LS solution givenby Eq. (1.6). In essence, the LMS Wiener solution and the LS solution areessentially the same.

In the world of signal processing and in particular adaptive signal processing,the processing speed is very important. Furthermore, the model structure usedin adaptive signal processing, especially for communication applications, canhave many parameters. It would not be unusual to have 200 terms in the 𝜙(n)vector, which means the term k in Eq. (1.21) would be k = 200. In that case,the R matrix will be 200 × 200, which would be prohibitively large to take the

Page 23: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

A Brief Review of Supervised Learning 9

inverse of in Eq. (1.30). As such, a gradient steepest descentmethod is normallyimplemented. This is a very common technique throughout the fields of engi-neering and is very similar to the well-known Newton–Raphson method offinding the zeros and roots of various functions. The steepest descent methodis an iterativemethod. The idea is to start with an initial guess of the parametervalues: often one will simply choose zero for the parameter values. In the lex-icon of signal processing, one would refer to the parameters as tap weights.Then one iteratively adjusts the parameters such that one moves down thecost function along the gradient. Let us say that the current estimate of theparameter vector is 𝜙(now); then we compute the next value of the parametervector as

��(next) = ��(now) − 𝜇g (1.32)

where g is the gradient and is given by the derivative of the cost function withrespect to the parameter estimation vector, �� as defined in Eq. (1.29). Then,substituting for g in Eq. (1.32), we get

��(next) = ��(now) − 𝜇2p − 𝜇2R��(now) (1.33)

In recursive form, it is written as

��(n + 1) = ��(n) − 𝜇2p − 𝜇2R��(n) (1.34)

We can also write Eq. (1.34) in the form

��(n + 1) = (I − 𝛼R)��(n) − 𝛼p (1.35)

where 𝛼 = 2𝜇. One may recognize, from systems theory, that if the eigenvaluesof (I − 𝛼R) are less than 1, then the recursion in Eq. (1.35) will converge. Thisplaces a limit on the step size of the steepest descent method. We will comeback to this point in the next section when we look at the stochastic approxi-mation methods. The effect of step size is an important parameter in machinelearning algorithms.

The difficulty in computing the recursion in Eq. (1.34) is the computation ofthe statistical terms R and p, where R is the information matrix or the auto-correlation matrix, and p is the cross-correlation matrix. Their statistics areoften unknown and have to be estimated as we did in Eq. (1.31). However,these estimates are computationally intensive and one has to wait untilN datapoints are collected. Instead, the LMS algorithm proposes that one estimate

Page 24: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

10 Multi-Agent Machine Learning: The Reinforcement Approach

these matrices based on a single data point at each sampling time, as

R(n) = 𝜙(n)𝜙T (n)

p(n) = 𝜙(n)y(n) (1.36)

This is sometimes referred to as the dirty gradientmethod or the stochastic gra-dientmethod. The idea is that one has to descent in the general direction of thegradient and not exactly along the gradient. Think of yourself walking downa hill; you can either go straight down or, if it is really steep, you may chooseto go back and forth traversing the hill, much the same way as a skier. Eitherway, you end up at the bottom of the hill. Now we substitute the estimates forR and p given by Eq. (1.36) into the recursive equation given by Eq. (1.34) andwe get

��(n + 1) = ��(n) + 2𝜇𝜙(n)y(n) − 2𝜇𝜙(n)𝜙T (n)��(n) (1.37)

Now we factor out the term 2𝜇𝜙(n) and get the standard LMS recursive algo-rithm as

��(n + 1) = ��(n) + 2𝜇𝜙(n)(y(n) − 𝜙T (n)��(n)) (1.38)

Recall that the term in brackets on the right-hand side, given by (y(n) −𝜙T (n)��(n)), is the prediction error or the innovation. The term 𝜙(n)��(n) is thecurrent prediction of the output y(n). If we compare the RLS algorithm inEq. (1.20) to Eq. (1.38), we see that the update has a similar form. The updateto the parameters is the previous estimate plus a matrix vector times theprediction error. In fact, it can be shown that at the stationary point, or thevalue at which the covarinace matrix update takes the value P(n + 1) = P(n)in Eq. (1.20), the LMS algorithm is equivalent to the RLS algorithm for aparticular set of parameters.

There is a vast literature on various implementations and convergence resultsassociated with the LMS algorithm, but the key element for this book is thatthemachine learns the parameters of a preconceivedmodel of the systembasedon the available experimental data and knowledge of the correct answer givenby y(n). The new parameter is the old parameter plus a vector based on thedata times the known error in the predicted output.

1.4 Stochastic Approximation

The method of stochastic approximation is an older method of system iden-tification. In fact, it is a method of finding the zeros of a function and is verysimilar to both the RLS and LMS methods, and it is the fundamental struc-ture for the Q-learning algorithms associated with reinforcement learning and

Page 25: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

A Brief Review of Supervised Learning 11

much of the machine learning literature. The early work in stochastic approx-imation comes from the work by Robbins and Monro [3] and Wolfowitz [4].A good textbook on the topic is byKushner andYin [5].Monro formulated theproblem as finding the level at which a continuous functionM(𝜃) = 𝛼. Writingthe problem in the formM(𝜃) − 𝛼 = 0 converts it into the problem of findingthe zeros of a function. If one knows the gradient of the function, then one canuse thewell-knownNewton–Raphsonmethod to find the zeros, but in this caseone takes the noise-corruptedmeasurements of the function at different valuesof 𝜃. One then makes small corrections to 𝜃 in the estimated direction of zero.

The method of stochastic approximation and the theoretical proofs of stabil-ity are used in the proofs of convergence for several fundamental algorithmsin reinforcement learning. Formulating the problem in a similar form to theprevious sections, we get the function M(𝜃) = (y(𝜃) − 𝜙T𝜃) = 0 and we canwrite the prediction error and the error in getting to zero as 𝜖 = (y − 𝜙T𝜃).The stochastic approximation algorithm is

𝜃(n + 1) = 𝜃(n) − an(y − 𝜙T𝜃) (1.39)

where an is a variable step size that goes to zero such that

0 <

∞∑1

a2n = A < ∞ (1.40)

References

[1] L. Ljung and T. Soderstrom, Theory and Practice of Recursive Identification. Cambridge,Massachusetts: The MIT Press, 1983.

[2] B. Farhang-Boroujeny, Adaptive Filters: Theory and Applications. New York: John Wiley &Sons, Inc., 1998.

[3] H. Robbins and S. Monro, “A stochastic approximation method,” Annals of MathematicalStatistics, vol. 22, no. 3, pp. 400–407, 1951.

[4] J. Wolfowitz, “On the stochastic approximation method of robbins and monro,” Annals ofMathematical Statistics, vol. 23, no. 3, pp. 457–461, 1952.

[5] H. J. Kushner and G. G. Yin, Recursive Approximation and Recursive Algorithms and Appli-cations. New York: Springer-Verlag, 2nd ed., 2003.

Page 26: Multi-Agent Machine · Multi-Agent Machine Learning A Reinforcement Approach Howard M. Schwartz Department of Systems and Computer Engineering Carleton University

Chapter 2

Single-Agent Reinforcement Learning

The objective of this chapter is to introduce the reader to reinforcement learn-ing. A good introductory book on the topic is Reference 1 and we will followtheir notation. The goal of reinforcement learning is tomaximize a reward. Theinteresting aspect of reinforcement learning, as well as unsupervised learningmethods, is the choice of rewards. In this chapter, we will discuss some of thefundamental ideas in reinforcement learning which we will refer to in the restof the book. We will start with the simple n-armed bandit problem and thenpresent ideas on the meaning of the “value” function.

2.1 Introduction

Reinforcement learning is learning to map situations to actions so as to max-imize a numerical reward [1]. Without knowing which actions to take, thelearner must discover which actions yield the most reward by trying them.Actions may affect not only the immediate reward but also the next situationand all subsequent rewards [1]. Different from supervised learning, which islearning from examples provided by a knowledgeable external supervisor, rein-forcement learning is used for learning from interaction [1]. Since it is oftenimpractical to obtain examples of desired behavior that are both correct andrepresentative of all the situations, the learner must be able to learn from its

Multi-Agent Machine Learning: A Reinforcement Approach, First Edition. Howard M. Schwartz.© 2014 John Wiley & Sons, Inc. Published 2014 by John Wiley & Sons, Inc.

12