1. Home
  2. Explore
  3. Computer Science
  4. Automata Theory and Reinforcement Learning

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Automata Theory and Reinforcement Learning

Transcript

[SHEILA MCILRAITH] Yeah. Okay good. Can [RUPAK MAJUMDAR] You share your screen? [SHEILA MCILRAITH] So, good. So oops. So, so, hello everybody, my name is Sheila McIlraith, I'm from the Department of Computer Science at the University of Toronto. [RUPAK MAJUMDAR] Oh, we cannot see your screen. Do you want to share the screen first? Oh you [SHEILA MCILRAITH] Can't see it? Oh okay. I thought I'd already shared it. Just a sec. Yeah, Rupak was going to introduce you after you shared it. [RUPAK MAJUMDAR] Yeah, I mean, I can, maybe I do the introduction, yeah. Okay. So hello everyone. It's my pleasure to introduce Sheila McIlraith from the University of Toronto, and she's gonna talk about connections between formal languages and automata theory and efficient reinforcement learning. So please, take it from here. Thank you for coming.

You're muted now. [SHEILA MCILRAITH] Thanks. Uh thanks Rupak. And people can feel free to interrupt me if they have questions, I'm not watching the chat But, But I know Rupak said that he would, so, so indeed my talk is about the opportunities and some work that we've done on exploiting formal languages and automata for both reward specification and efficient reinforcement learning. And before I, I jump into the details, I wanted to acknowledge my graduate student, Rodrigo Torroecarta, who, who is the, the lead author on much of the work that I'm going to be discussing today. He's, some of the work though is in collaboration, or all of the work is in collaboration with Elise, Torin Klassen and Rick Valenzano who and who are students that are postdoc with me, and I'll also be mentioning work by Alberto Comacho, Leona Lannes, and some of the other co-authors that,

that you see on here, all of whom are students or former students of mine. So, I wanted to motivate this notion of using formal languages for reward specification by really sort of stepping back and thinking about a motivating end task, which is really to address this problem of how we might be able to advise, instruct, or actually task, request our agent to do something for us, or impart knowledge to some sort of an reinforcement learning agent. And you can imagine a robot in your home that you might hire or that you might bring into your home that has some set of skills, but you'd still like to be able to tell it what you want it to do, you wanna have some sort of communication with that agent. And how do we go about doing that? So I know that I have a varied audience here, so I wanted to just step back for a minute and talk about reinforcement learning. I think many of the people who are here are used to using linear temporal logic or some sort of,

or MDPs or some sort of other formalism to construct models and then solve these sort of program synthesis or policy generation problems, strategy generation problems using games or some sort of other formalism. The paradigm that we're looking at here today is reinforcement learning, and in particular model-free reinforcement learning. And the idea here is that we have an agent, and the agent just has a set of actions that it can perform in the world, and what it wants to do is it wants to learn a policy, a mapping from state to action, or action distribution, that will maximize its expected cumulative reward. So the agent performs an action in the environment, and the environment tells it what state it's in and what reward it gets. And it does another action and the environment tells it what state it's in and what reward it gets. So the agent knows the actions that it can perform, but it doesn't know the transition system and it doesn't know

the probability distribution of the transition system. Similarly, it doesn't know the reward function, so it's just, it's like walking around in the dark, trial and error trying to figure out what you want to do through some sort of reward signal that you're receiving from the environment. So just very quickly, one way of doing model-free reinforcement learning is through an algorithm called Q-Learning which I'll refer to a little bit later, and I just wanted to give you the, the 20-second view of it. So Q stands for quality. A Q function talks about the quality of a particular state and a particular action, and as we're learning, as we're performing experiences in the world, as the agent is performing experiences in the world, it's going to update, it's going to learn more

about the quality of each state action pair and it's going to update those values. So it's gonna start, and that update is gonna be a function of what it, what it, its current belief about the quality of that state action pair plus that alpha is a learning rate, how much it wants to consider what it's just experienced in terms of updating its quality assessment for that state action pair. And so the alpha is the learning rate, it's somethin--

it's a number between zero and one round bracket and that's comprised in turn of the current reward that it just got from the experience that it had, plus some discounted, gamma's a discount factor discounted expectation of future reward that it's going to get in the environment. So that's how it, it, it, it how Q-Learning integrates these experiences to update these Q-values and eventually we'll get some, and we can, that Q-value tells us how good uh, each state action pair is, and of course when we're in a particular state we just, we just pick the, the action, the policy is the action that has the highest Q-value.

So, the dirty little secret around reinforcement learning and something that really motivates the work that we're doing here is that, unlike you and me who are wired for pleasure and pain and who experience the world and experience what makes us happy, maybe sunshine makes you happy and maybe stubbing your toe makes you unhappy, with reinforcement learning when we're building these RL agents, somebody has to, program the reward function. And in particular, it's usually some poor graduate student that has to take some sort of complex behavior and map it into this reward function, which is either a mapping from state to some scalar value, or a mapping of a state action, state-- successor state triple into some sort of scalar value, and that can be really, really hard as we'll discuss, and what motivates, I think, some of the work that I'm talking about today. So returning to this aspiration of wanting to be able to advise, instruct, and task our RL agents,

and actually, as an aside, maybe you don't care about this, maybe you care about artificial general intelligence, there's a lot in here that is for you as well, so stay tuned. Don't stop listening if this is not your aspiration, but this is just motivating. So there's a big disconnect between this RS and imagining sitting on your sofa talking to your robot. And so, you don't need a PhD to raise a child, and you shouldn't need a PhD to task an RL agent. And so we should be able to specify in some sort of more compelling language, ideally, eventually natural language, but for now, a formal language that has a well-defined syntax and clearly defined semantics is our language of choice. Interestingly, there's a very nice paper that I wanted to give a shout-out to by Dulac-Arnold and his co-authors about challenges of real-world RL, and I re-- it's a quick read. I recommend that you look at it. But some of the challenges that they identify are

indeed safety constraints, reward specifications, and that many of the tasks are partially observable, and that means that they need some sort of memory in order to operate in the environment. And what we'll see is that the-- that these formal languages and automata provide a way of doing that. They also he also-- they-- the authors also note that reward specifications, reward functions are underspecified, which can cause problems and certainly there's a whole discussion around AI safety related to that, and also that we want to be able to explain our policies. And so having a formal language and something that is interpretable also will address some of those real-world challenges. But what I want to focus on today is two challenges. Reward specification, which is that it's really hard to define a reward function for complex tasks, and sample efficiency. Reinforcement learning agents might require billions of interactions with the environment to learn good policies.

So returning to our example, let's look at the-- some of the types of rewards that we-- reward functions that we might want to express. So here are a few that I just made up imagining my life sitting on the-- sitting on my couch with a robot to do my doing. Run the dishwasher when it's full or when dishes are needed for the next meal. Make sure the bath temperature is between 38 and 43 Celsius immediately before letting someone enter the bathtub. That would be great for a healthcare robot or some-- a robot that is watching an elderly person or a child in your home. Do not vacuum while someone is sleeping in the h-- is in the house just sleeping.

Or my favorite, this is my-- I'm-- I've said this before, I'm running this little reinforcement learning experiment in my house to see how with two agents who s-- and trying to see what their learning rate is, here's my specification. When getting ice cream, please open the freezer, take out the ice cream, serve yourself, put the ice cream back in the freezer, and close the freezer door. This is a behavior that I want to reward, but I only want to reward it when it's completed. I don't want to reward it when it's half done. I don't want the freezer to be left open. In fact, that would be something that I would want to penalize heavily. And so this-- what you'll notice about all of these rewards is that they're temporally extended, they are conditional, and they're quite rich in terms of their syntax, and yet we have to write those things as a mapping R of S or RSAS prime. So what we are going to appeal to and what we've done in some

of our work is to appeal to linear temporal logic, which is, of course a propositional modal logic with temporal modalities that talk about properties of traces, of traces over time that are either interpreted over finite or infinite traces. And I think many of the people who are here listening to this talk are familiar with LTL, but just to again And you'll see it in a minute and in some examples, but it has the basic logical connectives that we have, and,

or, and not and of course we can define implication from there. It also has these special modal operators. Circle phi is next, week next, until, and we can define these very powerful operators eventually, always, and release. And of course linear temporal logic is used very commonly in verification and in synthesis and a variety of other tasks, and we're going to appeal to it here. And if you're not familiar with LTL, and I think everyone here probably is,

an important property of LTL is is that LTL be transformed into automata different types of automata. Sometimes deterministic, sometimes non-deterministic, sometimes buchi automata, depending upon the variant of Linear Temporal Logic that we're talking about. And I-- I want you to remember this point because I'm going to return to it later. So going back to our examples, and just to give a flavor for those who are less familiar with LTL, I might write do not vacuum while someone is sleeping is always not vacuum when sleeping, and I might write my ice cream example is always get ice cream implies eventually open the freezer, and next eventually remove the ice cream from the freezer, and next serve the ice cream, and so on. Again, a temporally extended formula that is only going to receive reward when that full property interpreted over a trace is satisfied.

So how do we communicate this to a reinforcement learning agent when we've got that narrow signal, that R of S? Um, that's what I'm going to talk about in the rest of the talk. Again, the challenges are reward specification how we specify these functions, and also sample efficiency because many of these temporally extended rewards, if, if we only get a reward at the end, we're doing a lot. We're trying to learn a very complex pattern that leads to a reward, and we need billions and billions of interactions in order to ever get those rewards, or ever be successful at learning. So throughout this talk, I'm going to give a-- I'm going to use a very simple running example. It's an office world domain where we have four different locations, A, B, C, and D. We have two coffee stations designated by the coffee cups. We have a mail room designated by the envelope, and we also have an office designated by this little O. And for starters,

our task is going to be to visit A, B, C, and D in that order as a simple sequential task, but, but what I'm going to show you later are some other tasks in this environment. Oh, yes, I should also mention that these little stars are furniture or fragile things that we do not want to bump into. So this these look like toy problems, and certainly they're easy problems for us to describe, but they do challenge state-of-the-art reinforcement learning techniques, as I will show you in our experiments later on.

So here's an interesting observation. As I alluded to in, in talking about our poor graduate students, it's really important to note that someone always has to program the reward function, and they typically do it in, in Python. So for, for our task of visiting A, B, C, and D, we might write some Python code that looks like the code on the right. And this is true even when we have a robot operating in the environment because although the robot is operating in the environment rather than in a simulated environment it still does not know what reward-worthy behavior is because it has no signal for that.

So and again, as we see, and if we perform this, the reward function is a black box. It's just part of the environment. So as the agent moves in the world, and our agent is this little purple triangle, the agent might go up, and it tells, and the reward function takes its state and returns a reward of zero, it might go right, and so on and so forth, and it's just really this black box. So one of the simple and most important ideas behind our work is that we should give the agent access to the reward function. Somebody has to program the reward function. It's not top secret. We know what it is. So why not take that reward function and give it to the reinforcement learning agent so that it can learn more quickly, and indeed, so that it can exploit reward function structure in learning? And that's what I'm going to talk to you about, and that's where the use of formal language and automata,

which is structured by its syntax has really paid off in terms of, of, of learning and sample efficiency. So here we go. So looking at our running example, the agent can exploit the structure in the reward function in order to learn. And so what we're actually going to do is instead of having the reward function on the right as it is here in terms of, in this black box, we're gonna decouple the transition in the reward function, and we're going to give the reward function to the agent. So this is what I'm going to talk about in the next, rest of the talk. I'm going to talk about this notion of reward machines, which is an automata-based representation of reward functions. I'm going to tell you how we can exploit that reward machine structure in learning, show you some experiments, and then at the end, I'm going to talk to you about different ways in which we can create reward machines besides the, the obvious way of just writing the re-- the automata structure yourself.

So, reward machines. So we're going to define a reward function using a reward machine, and we're gonna because you know, the premise, at least at the outset is that a human is going to write this, we need a human interpretable vocabulary. Here in our example, the vocabulary P is going to be coffee, the coffee stations, the mail room, the office, the furniture, and A, B, and C and D. That's our vocabulary over which we're going to construct this reward machine, but it's going to be an

automata-like structure. And so the vocabulary can comprise human interpretable events or properties realized via detectors over the environment state, or it can conceivably be learned, and I'll return to that discussion at the end. But for a human being, we want it to be something that a human can talk about. So here's our reward machine pictorially. It's comprised of a finite set of states, here for our patrolling task U0, U1, U2, U3, an initial state, U0, a set of transitions that are labeled by a logical condition or a guard, here, you know, A, comma, and as well as two things, the label is this logical condition, which is an arbitrary logical formula, as well as a reward function. And here in these examples, the reward functions are just scalar values, a constant, but they could be in its most generality, it could be an actual reward another function.

So a simple reward function is just a Mealy machine the one displayed here, over the inputs of the, of the various truth assignments of these propositions. Um, and the alphabet is a set of Markovian reward functions. More generally, we've got you know, nice, more, for those who are interested in a precise definition, we've had several more precise definitions that have evolved over time in our, in our work, and I would recommend we have a journal paper that's coming out.

This is from that journal paper but and it captures this sort of general notion that a reward machine is comprised of a tuple that has these states, an initial state a finite set of terminal states, which can be the empty set if we want this reward machine to operate into perpetuity to have no terminal state and then two different functions delta U, which is the state transition function which maps you to another state in that reward function structure,

reward machine structure, or to recognize the terminal state, as well as this reward function, which maps your position in the reward machine to some sort of complex reward function. And again, the simple reward machine that I showed you in my picture was just one that maps to a scale or value, that maps to the reals as a function of two to the P, as opposed to mapping to a, a family of different reward functions.

So returning to our reward machines, we can see what happens in action using this reward machine, and again watch the little agent in the, who's the purple triangle down here. The agent moves and we're in U0, the agent moves, it tells the reward function where it is, and the reward function returns transitions in the reward machine and then returns some sort of reward, and here we got a reward of zero. Now, the agent goes to A. We see that A actually satisfies the logical condition on the

first edge between U0 and U1, so the reward machine is actually, it tells the reward machine, the agent tells the reward machine what it's-- the action that it's performed, and we transition to U1, and, but we still get no reward. We still get a reward of zero. And on and on we go, moving around and transitioning through it. You can see the agent moving through the space and transitioning within the reward machine. It's now in state three, so it, which remembers that it's gotten from A, it's gone to A, it's gone to B, it's gone to C, it's now in this U3, and it's, but D is not true yet. It has not yet reached D, and when it finally reaches D, it transitions back to U0 and gets a reward of one. So the reward machine is actually keeping track of, of this reward function for us, and, and, and yet the individual rewards in here are Markovian.

We can define all sorts of other reward machines, deliver the coffee to the office while avoiding furniture. Again when we were in U-- we start in U0, when we've gone to the coffee machine and we haven't hit any furniture, we get a reward of zero, and when we subsequently, after having gotten coffee, go to the office, we transition to U3 and get that reward of one. If at any point in time we hit the furniture we transition to a sink state which we stay in in perpetuity where we get a reward of zero.

Similarly, we can deliver coffee and mail to the office, and of course we haven't stipulated what order we want to do it in, so it could be that we get the coffee and then, and the mail, and then go to the office, or we can get the mail and then the coffee and then go to the office, and both of those pathways are captured within our reward machine structure. So now that you've got some sense of what a reward machine looks like, and its formal structure, I wanna talk to you very importantly about how we can actually exploit that reward machine structure in learning.

And I'm going to talk to you about it in the context of, of three of, of five different approaches. Three of them were things that we considered to be baselines but they were all of our creation, and then two more that showcase special purpose algorithms that we were using that really exploit the reward machine structure that we have embodied in our reward machines. So the first baseline, which is our baseline, is, is the Q-learning baseline, and again, I g-- explained Q-learning to you previously. An important thing to observe is that a reward machine may define a non-Markovian reward function. Sorry about that. And that's exemplified by the picture that you can see here. So if my little agent the triangle here, is adjacent to D, but it's, and it goes to D, then what, the reward that it's going to get is going to be different depending upon its history.

So the reward function is actually non-Markovian. If it's gone to A, B, C already And then it goes to D from that square, it will get a reward of one, but otherwise if it hasn't passed through A, B, C first, it'll get a reward of zero. So let's see what that looks like. If it just-- if it was in U1 and it just moved to D, it's going to stay in U1 and get a reward of zero, whereas if it was in U3, which meant that it had passed through A, it had passed through B, and it had already passed through C, and it moved from that square to the right And it was in U3, then it would get a reward of one. So different, same move, different reward. And again, these reward functions are non-Markovian. So the obvious baseline to do is just to do this obvious cross product. So we're gonna cross product the, the the state of the system with the, the reward machine and we're going to be able to, to try to do basic Q-learning with that baseline, and we're

gonna use Q-learning on the resulting MDP that is the cross product. The second thing that we wanted to try was something called hierarchical reinforcement learning, which is abbreviated to HRL. Hierarchical reinforcement learning learns a set of options and a meta-controller, and the options are basically like macro actions or pre-learned or learned sub-policies that can be composed together in order to perform tasks in a hierarchical manner as alluded to by the name. So in this context what we're gonna do is we're gonna learn

one option policy for each proposition mentioned in the reward machine. So since the reward machine refers to A, B, C, and D, we're gonna learn a policy, πA for a mapping from any state to get to, with the objective of getting to A. πB, πC, and πD. And then what we're going to do is we're going to optimize which πi we're going to apply to satisfy our objective ideally optimally.

The third And so you can see here the way that hierarchical HRL works is that in addition to having these policies, these options that it learns, πA, πB, πC, and πD, it also has to learn a better controller. So it's simultaneously going to learn how to use each of the option policies taking input from both the reward machine and from the environment to learn a good meta-controller. That's option two. Our third option is hierarchical reinforcement learning with reward machine-based pruning, and the simple observation here is that, you know, a reward machine tells us by virtue of what state it's in, U0, U1, U2, or U3, which policy it should be applying at that state. So if we actually use the state of the reward machine to better inform the meta-controller, then we can actually prune policies that are not relevant at a particular time. So for example, when we're in U0,

we know that the first thing we have to do is get to A, and so we should be applying the πA policy. When we're at U1, we should be applying the πB policy, and so on. So we use-- we learn a policy using this pruning from our reward machine structure. And an interesting thing about reward machines or about hierarchical reinforcement learning that I wanted to mention to you as a sidebar is that hierarchical reinforcement learning approaches find locally optimal solutions. Because they are myopic, because they are optimizing each of those policies in isolation, the policy to get to A, the policy to get to B, the policy to get to C, it isn't necessarily that even though those individual policies are optimal, they may not be optimal in aggregate.

And a great example of that is the example that I have here, which is the delivering coffee to the office example. So if I wanna deliver coffee to the office, you can see the office here in --as the O. We can go to either one coffee station or another, and our system will choose which one to go to. So in hierarchical reinforcement learning, wha-- um, this is-- this is the-- the-- this first policy, this first path which I've shown you is-- is the optimal policy.

It takes 10 steps to get to or 13 steps, excuse me, to get to the office after having picked up the coffee. But what's interesting about this is that to get from A to the coffee machine is actually 10 steps, whereas the other pathway, which goes through this other coffee station is one, two, three, four, five, six, seven, I think eight steps, and so the optimal policy to get to coffee, if you look at it myopically, is to go to this coffee station. But then having committed to that coffee station

unfortunately there's a very long pathway to get to the office. Unfortunately, HRL will always take the optimal the locally optimal step and so it will choose this longer pathway to get to the to realize this task. And you'll see this borne out in some of our results. In contrast, Q-learning actually preserves optimality. So our fourth algorithm, which is our QRM algorithm that I wanna talk to you about is the algorithm that we created in order to exploit the reward machine structure to learn more efficiently. And uh, just a-- a-- a heads-up, I didn't create new slides but we do have a journal paper coming out where we have a variant of QRM called CRM, which stands for Counterfactual Reward Machines which a-- is a-- a-- an-- a new improved version of QRM that actually doesn't produce separate policies.

It produces one large policy which we believe is going to be better for generalization. And you can see that paper if you're interested in this, but the results are as good and better than the QRM results in all cases. So here's the way that QRM works. Remember what we wanna do is we're going to-- The first step is that we're gonna learn one policy or Q-value per state in the reward machine. So a Q-value for U0, a Q-value for u-- uh, a Q-value for U1, for U2, and for U3.

Then we're going to select actions using the policy of the current reward machine. So when we're in U0, we're going to use the policy or the Q informed by the Q function that we've learned for Q0. When we're in U1, we're gonna learn the Q function for being in state U1 and so on. U0, Q0, U1, Q1, and so on. And then, but-- but the-- the most important thing that we're going to do, and I think this is the power of our learning, is that we're going to

use off-policy learning to reuse experiences to update all of our Q-val-- Q-value functions simultaneously. It's really a form of counterfactual reasoning, and I'm going to elaborate upon this in in the slides that follow. But this is the secret sauce, or one of the secret sauces, that makes our-- our learning so effective because we're getting multiple bi-- by decomposing our reward function into into a bunch of different Markovian reward functions separate reward functions, or-- or by making it Markovian decomposition, excuse me, of this reward function, and by exploiting this reward machine structure, we're-- we're able to learn different piece-- Even though we're not at one particular state in the-- the reward machine, we can learn and update our Q-values for the-- all the different states simultaneously by a form of counterfactual reasoning. Here we go. Let's say we're in U0 And we're going to move.

We can see where we're gonna update each Q value as if the reward machine was in each of the corresponding states. So, even though we're actually in U0, we're going to pretend that we're in each of these U1, U2, and U3, and update all of the corresponding states. So let's see what that looks for. So if we take an action and we move, and we get a reward, and we're, and we were in U0, then we're going to get a reward of 0. And the update of our Q function our quality of that state and

that action, is going to be 0, which is the reward we got, plus the discounted future reward that we're going that we expect to get being in for Q0. If we are instead in U1, we're going to do a similar sort of, where, and we move to D, to that position. We're similarly going to get a reward of 0 and we're going to update again, we're gonna stay in U1 and we're gonna our expected future reward is going to be with respect to Q1.

When we're in U2, similarly we're going to get a reward of 0 and we're gonna update the expected future reward with respect to being in U2. And finally, this is the one that's different. When we're counterfactually, you know, we're imagining this in our mind, if we had been in U3 instead and we had performed this action of moving to D, what would have happened is that we would have transitioned in the reward machine from U3 to U0, and we would have gotten a reward of 1.

And the update, therefore, for this particular state, Q3, is that we're gonna get a reward of 1 and we're gonna add that to our discounted expected future reward, which is going to be with respect to Q0 not with respect to-- because we've moved within the reward machine. So this is how we're learning using this reward machine, and this is how we're doing this, it's a form of counterfactual reasoning. So for every move we make, we just move that one spot from, to the right, that A that we see in our office diagram, we're able to get a huge bang for our buck because we can counterfactually imagine that we were in these other states within our reward machine and update the experiences as if we were in that state instead.

So recall we had these different techniques that I outlined. The last one, I've just explained four to you, the last thing I want to explain is, is QRM, this algorithm that I just told you about, with reward shaping. So some of you may know something about reward shaping, others don't. One of the things that I alluded to at the beginning was that a huge problem with sample efficiency, a huge problem with reinforcement learning is that a lot of the time there's no signal, there's no reward. So the agent will be moving around and trying to figure out what to do and it will get 0, 0, 0, 0, 0, 0, 0. And that can be very problematic and cause it to have to have a lot of experiences in order to learn the function.

And indeed what I did not mention previously is that if Q Learning is guaranteed to converge to the optimal policy with tabular learning when we're not using any sort of a function approximation, and that's a really important step because eventually it will learn the optimal policy, it just needs a lot of samples. So the idea behind reward shaping is a very intuitive one. If you imagine you're going to perform this long, arduous journey, at the end you're gonna

get a chocolate chip cookie, then instead what you're gonna do is something like Hansel and Gretel. Reward shaping takes that cookie and sort of spreads it along the path so that the cumulative reward you get in the end is the same, but it's shaping the reward function in a way that gives you some intermediate reward. And this notion of reward shaping is one that's very popular in reinforcement learning. It was I believe, first proposed by Andrew Ng Harada and Stuart Russell in 1999.

I think that's the earliest citation. But it's based on this notion of having a, defining a potential function, and so the reward function that you have, this RSAS prime or RS is augmented with this, you know, adding and deleting of this extra cookie that you've spread that allows for a shaping of the reward. So the important thing about reward shaping is that it does not compromise your ability to still learn the optimal policy, and it learns it more quickly.

So we're guaranteed that the found policies are still optimal with respect to the original unshaped reward function, so that's a very powerful property and one that, that Ng and Harada and Russell showed. So here's an example of our coffee delivery reward machine which we saw before, and in red what you'll see is the augmentation of those rewards those rewards, those scale of rewards that we were getting that are the labels for our edges augmented with reward shaping.

And the interesting thing was the way that we did reward shaping is as described in an IJCAI '19 paper, was that we basically did value iteration over the reward machine in order to figure out what that reward shaping was, and then we applied that, and then we applied QRM to the shaped reward machine. So we've taken our original reward machine and we've just changed around the numbers a little bit. So a nice thing and again, I alluded to this, that Q learning preserves in the tabular case has optimality guarantees. It's guaranteed to converge to the optimal policy in the limit, and so both the application of our two algorithms, QRM and QRM with reward shaping, preserve those optimality guarantees for us, which is very nice.

So now I've told you about defining what a reward machine is, an automata structure for a re-- Sorry, may I ask a [RUPAK MAJUMDAR] Quick question, please? Oh. Yeah. If you go back to the slide with the reward shaping. So it seems that now you have rewards both on the states and on the actions, right? And, um-- Yeah, that's [SHEILA MCILRAITH] Right. [RUPAK MAJUMDAR] --how should I read this? So as, let us say, if you started the initial state marked with the arrow, then every time you take an edge, you get the corresponding reward on the edge. But then do you also get a penalty for being in that state? So How does it-- Yes, [SHEILA MCILRAITH] That's right. You get a penalty so that it incents you to move on. It incents you not to stay in that state.

[RUPAK MAJUMDAR] I see. Okay. Okay. Thanks. Thanks. [SHEILA MCILRAITH] Okay. So, so those were our Yeah, So now I'm gonna th-- thank you for the question. So now we're going to go on to our experiments and to see how this has worked in, for us in practice. And the experiments were comprised of two domains with a discrete actions and state space, and one domain with a continuous state space, a deep learning space. And in our, our journal paper, we have some nice experiments with Half Cheetah as well, and we've integrated our, our code with the, with OpenAI Gym.

So that's something else for people to look at if they're interested, but I don't, I didn't add those results here. The again, we testivated, tested all five approaches that I've just discussed with you and the table at the bottom provides a little bit of a summary. So we've got QRM, hierarchical reinforcement learning, hierarchical reinforcement learning where we were doing that reward machine pruning of the policies. Um, QRM, which was our, our, our out Q-learning algorithm that exploited the, the reward machine structure by doing off-policy learning, and then QRM with reward shaping. And again, as we see in the tabular case with these discrete domains, optimality is preserved with Q-learning and with our two QRM-based algorithms and reward shaping, and, and indeed our our bi-- our automata structure, our reward machine structure does provide for a decomposition as does hierarchical reinforcement learning. The original Q-learning algorithm does not.

So we can see those two things influencing what we did. And so here's our example. Again, we're in this office world setting. We've got in the graph that you're about to see on the x-axis, the horizontal axis, we have the number of training steps and it goes up to 50,000. On the y-axis, the vertical axis, we have the normalized discounted reward. So the reward, the optimal reward is always one. We just normalized it for comparison purposes. And you can see the legend on the right-hand side.

All of the four first algorithms are here. I'm going to show you the reward shaping algorithms afterwards. So here we go. Our algorithm, our QRM algorithm is the, the red is the red line and we can see that it very quickly in about 15,000 training steps or actually maybe 13,000 training steps, it hit the optimal policy and converged to it. Both hierarchical reinforcement learning with reward, with reward machine pruning which is the light blue line and

just hierarchical reinforcement learning both did quite well. You can see the blue one with the reward machine pruning also learned quite quickly but they plateaued to a suboptimal solution in some of our examples. We had four tasks and we did 30 independent trials per task. Um, and whereas the Q-learning, the blue l-- the, the sort of royal blue line that I-- that is at the bottom which is performing least well did make some progress But, But again it, and it achieved the state that, that the HRL achieved. And eventually with enough samples that Q-learning algorithm, that royal blue line will eventually get to one but s-- this speaks to the, the gain in sample complexity from using our QRM algorithm because, because compared to Q-learning without that reward machine function structure.

We did a second set of discrete-- Sorry [RUPAK MAJUMDAR] There's another question if I may interrupt you. [SHEILA MCILRAITH] Yeah. Yeah. Uh, [RUPAK MAJUMDAR] It's from one of it's from Kishore. So it says, "It appears that the shaped rewards are sparse in the sense that the agent is rewarded for a subtask only at the end of the subtask and in the meantime receiving constant rewards. Is this sufficient in environments with continuous states and actions?" [SHEILA MCILRAITH] So Yeah, so, so if you don't mind, I'll, I'll post-- there's no reward shaping in these results and I'm gonna get to the reward shaping in a minute so, so maybe I'll, I'll show you the reward machine results and then I will a-- answer that question And I think that the person who asked the question will like to see the graphs as well. So-- Okay. Yeah. Good. So, so we're still in tabular domains so we're s-- we're not using function approximation yet

And we did some experiments on these, these Minecraft-like domains a craft world, um-- where we had 10 tasks over 10 random maps, three independent trials per combination. Some of the tasks were similar to the ones that Jakob Andreas had used in his ICML 2017 paper, and again, you know, making, you know, you, you collect ore and you, you collect wood and you make an ax or you, you m-- s-- so our little agent Luigi is moving around in this environment making different things.

And again we have the same graph where we have the number of training steps on the X axis up to 10 to the 6th, so many more training steps, and on the vertical Y axis we have the normalized discounted reward, and it goes to, again, to one. Same four of our first approaches, not the reward shaping approach yet, and we can again see the, the, the, our QRM algorithm, which is the red line converges reasonably quickly f-- with far more sample efficiently to the optimal reward, whereas HRL,

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent