10.1 Reinforcement Learning Introduction | What is Reinforcement Learning? -[ML |Andrew Ng]
 Welcome to this final week of the machine learning specialization. It's a little bit bittersweet for me that we're approaching the end of this specialization, but I'm looking forward to this week sharing with you some exciting ideas about reinforcement learning. In machine learning, reinforcement learning is one of those ideas that, while not very widely applied in commercial applications yet today, is one of the pillars of machine learning and has lots of exciting research backing it up and improving it every single day. So let's start by taking a look at what is reinforcement learning. Let's start with an example. Here's a picture of an autonomous helicopter. This is actually the Stanford autonomous helicopter, weighs 32 pounds and is actually sitting in my office right now. Like many other autonomous helicopters, it's instrumented with an onboard computer, GPS, accelerometers, gyroscope, and magnetic compass, so it knows where it is at all times quite accurately. And if I were to give you the keys to this helicopter and ask you to write a program to fly it, how would you do so? Radio-controlled helicopters are controlled with joysticks like these, and so the task is 10 times per second you're given the position and orientation and speed and so on of the helicopter, and you have to decide how to move these two control sticks in order to keep the helicopter balanced in the air. By the way, I've flown radio-controlled helicopters as well as quad-rotor drones myself, and radio-controlled helicopters are actually quite a bit harder to fly, quite a bit harder to keep balanced in the air. So how would you write a program to do this automatically? Let me show you a fun video of something we got the Stanford autonomous helicopter to do. Here's a video of it flying under the control of a reinforcement learning algorithm, and let me play the video. I was actually the cameraman that day, and this is a helicopter flying under computer control, and if I zoom out the video, you see the trees planted in the sky. So using reinforcement learning, we actually got this helicopter to learn to fly upside down. We told it to fly upside down, and so reinforcement learning has been used to get helicopters to fly a wide range of stunts, or we call them aerobatic maneuvers. By the way, if you're interested in seeing other videos, you can also check them out at this URL. So how do you get a helicopter to fly itself using reinforcement learning? The task is, given the position of the helicopter, to decide how to move the control sticks. In reinforcement learning, we call the position and orientation and speed and so on of the helicopter the state s, and so the task is to find a function that maps from the state of the helicopter to an action a, meaning how far to push the two control sticks in order to keep the helicopter balanced in the air and flying and without crashing. One way you could attempt this problem is to use supervised learning. It turns out this is not a great approach for autonomous helicopter flying, but you could say, well, if we could get a bunch of observations of states and maybe have an expert human pilot tell us what's the best action y to take, you could then train a neural network using supervised learning to directly learn the mapping from the state s, which I'm calling x here, to an action a, which I'm calling the label y here. But it turns out that when the helicopter is moving through the air, it's actually very ambiguous what is the exact one right action to take. Do you tilt a bit to the left or a lot more to the left or increase the helicopter stress a little bit or a lot? It's actually very difficult to get a data set of x and the ideal action y. So that's why for a lot of tasks of controlling a robot like a helicopter and other robots, the supervised learning approach doesn't work well and we instead use reinforcement learning. Now, a key input to a reinforcement learning is something called the reward or the reward function, which tells the helicopter when it's doing well and when it's doing poorly. So the way I like to think of a reward function is it's a bit like training a dog. When I was growing up, my family had a dog and it was my job to train the dog or the puppy to behave. So how do you get the puppy to behave well? Well, you can't demonstrate that much to the puppy. Instead, you let us do a thing and whenever it does something good, you go, oh, good dog. And whenever it did something bad, you go, bad dog. And then hopefully it learns by itself how to do more of the good dog and fewer of the bad dog things. So training for reinforcement learning is like that. When the helicopter is flying well, you go, oh, good helicopter. And if it does something bad, like trash, you go, bad helicopter. And then it's a reinforcement learning algorithm's job to figure out how to get more of the good helicopter and fewer of the bad helicopter outcomes. One way to think of why reinforcement learning is so powerful is you have to tell it what to do rather than how to do it and specifying the reward function rather than the actual action gives you a lot more flexibility in how you design the system. Concretely, for flying the helicopter, whenever it is flying well, you may give it a reward of plus one every second that is flying well. And maybe whenever it's flying poorly, you may give it a negative reward. Or if it ever crashes, you may give it a very large negative reward, like negative one thousand. And so this will incentivize the helicopter to spend a lot more time flying well and hopefully to never crash. But here's another fun video. I was using the good dog, bad dog analogy for reinforcement learning for many years. And then one day I actually managed to get my hands on a robotic dog and could actually use this reinforcement learning good dog, bad dog methodology to train a robot dog to get over obstacles. So this is a video of a robot dog that using reinforcement learning, which rewards it moving toward the left of the screen, has learned how to place his feet carefully or climb over a variety of obstacles. And if you think about what it takes to program a dog like this, I have no idea. I really don't know how to tell it what's the best way to place his legs to get over a given obstacle. All of these things were figured out automatically by the robot just by giving it rewards that incentivizes it, making progress toward the goal on the left of the screen. Today, reinforcement learning has been successfully applied to a variety of applications ranging from controlling robots. And in fact, later this week in the practice lab, you implement for yourself a reinforcement learning algorithm to land a lunar lander in simulation. It's also been used for factory optimization. How do you rearrange things in the factory to maximize throughput and efficiency as well as financial stock trading? For example, one of my friends was working on efficient stock execution. So if you've decided to sell a million shares over the next several days, well, you may not want to dump a million shares on the stock market suddenly because that will move prices against you. So what's the best way to sequence out your trades over time so that you can sell the shares you want to sell and hopefully get the best possible price for them? Finally, there have also been many applications of reinforcement learning to play in games, everything from checkers to chess to the card game of bridge to go as well as for playing many video games. So that's reinforcement learning. Even though reinforcement learning is not used nearly as much as supervised learning, it is still used in a few applications today. And the key idea is rather than you needing to tell the algorithm what is the right output, why for every single input, all you have to do instead is specify a reward function that tells it when it's doing well and when it's doing poorly. And it's a job of the algorithm to automatically figure out how to choose good actions. With that, let's now go into the next video where we'll formalize the reinforcement learning problem and also start to develop algorithms for automatically picking good actions.
[{"start": 0.0, "end": 6.0, "text": " Welcome to this final week of the machine learning specialization."}, {"start": 6.0, "end": 10.0, "text": " It's a little bit bittersweet for me that we're approaching the end of this specialization,"}, {"start": 10.0, "end": 15.0, "text": " but I'm looking forward to this week sharing with you some exciting ideas about reinforcement learning."}, {"start": 15.0, "end": 20.0, "text": " In machine learning, reinforcement learning is one of those ideas that,"}, {"start": 20.0, "end": 24.0, "text": " while not very widely applied in commercial applications yet today,"}, {"start": 24.0, "end": 29.0, "text": " is one of the pillars of machine learning and has lots of exciting research backing it up"}, {"start": 29.0, "end": 31.0, "text": " and improving it every single day."}, {"start": 31.0, "end": 36.0, "text": " So let's start by taking a look at what is reinforcement learning."}, {"start": 36.0, "end": 38.0, "text": " Let's start with an example."}, {"start": 38.0, "end": 41.0, "text": " Here's a picture of an autonomous helicopter."}, {"start": 41.0, "end": 43.0, "text": " This is actually the Stanford autonomous helicopter,"}, {"start": 43.0, "end": 47.0, "text": " weighs 32 pounds and is actually sitting in my office right now."}, {"start": 47.0, "end": 51.0, "text": " Like many other autonomous helicopters, it's instrumented with an onboard computer,"}, {"start": 51.0, "end": 55.0, "text": " GPS, accelerometers, gyroscope, and magnetic compass,"}, {"start": 55.0, "end": 59.0, "text": " so it knows where it is at all times quite accurately."}, {"start": 59.0, "end": 65.0, "text": " And if I were to give you the keys to this helicopter and ask you to write a program to fly it,"}, {"start": 65.0, "end": 67.0, "text": " how would you do so?"}, {"start": 67.0, "end": 70.0, "text": " Radio-controlled helicopters are controlled with joysticks like these,"}, {"start": 70.0, "end": 76.0, "text": " and so the task is 10 times per second you're given the position and orientation and speed"}, {"start": 76.0, "end": 78.0, "text": " and so on of the helicopter,"}, {"start": 78.0, "end": 84.0, "text": " and you have to decide how to move these two control sticks in order to keep the helicopter balanced in the air."}, {"start": 84.0, "end": 90.0, "text": " By the way, I've flown radio-controlled helicopters as well as quad-rotor drones myself,"}, {"start": 90.0, "end": 93.0, "text": " and radio-controlled helicopters are actually quite a bit harder to fly,"}, {"start": 93.0, "end": 95.0, "text": " quite a bit harder to keep balanced in the air."}, {"start": 95.0, "end": 99.0, "text": " So how would you write a program to do this automatically?"}, {"start": 99.0, "end": 104.0, "text": " Let me show you a fun video of something we got the Stanford autonomous helicopter to do."}, {"start": 104.0, "end": 109.0, "text": " Here's a video of it flying under the control of a reinforcement learning algorithm,"}, {"start": 109.0, "end": 111.0, "text": " and let me play the video."}, {"start": 111.0, "end": 116.0, "text": " I was actually the cameraman that day, and this is a helicopter flying under computer control,"}, {"start": 116.0, "end": 121.0, "text": " and if I zoom out the video, you see the trees planted in the sky."}, {"start": 121.0, "end": 126.0, "text": " So using reinforcement learning, we actually got this helicopter to learn to fly upside down."}, {"start": 126.0, "end": 128.0, "text": " We told it to fly upside down,"}, {"start": 128.0, "end": 134.0, "text": " and so reinforcement learning has been used to get helicopters to fly a wide range of stunts,"}, {"start": 134.0, "end": 137.0, "text": " or we call them aerobatic maneuvers."}, {"start": 137.0, "end": 142.0, "text": " By the way, if you're interested in seeing other videos, you can also check them out at this URL."}, {"start": 142.0, "end": 148.0, "text": " So how do you get a helicopter to fly itself using reinforcement learning?"}, {"start": 148.0, "end": 155.0, "text": " The task is, given the position of the helicopter, to decide how to move the control sticks."}, {"start": 155.0, "end": 163.0, "text": " In reinforcement learning, we call the position and orientation and speed and so on of the helicopter the state s,"}, {"start": 163.0, "end": 171.0, "text": " and so the task is to find a function that maps from the state of the helicopter to an action a,"}, {"start": 171.0, "end": 180.0, "text": " meaning how far to push the two control sticks in order to keep the helicopter balanced in the air and flying and without crashing."}, {"start": 180.0, "end": 185.0, "text": " One way you could attempt this problem is to use supervised learning."}, {"start": 185.0, "end": 189.0, "text": " It turns out this is not a great approach for autonomous helicopter flying,"}, {"start": 189.0, "end": 201.0, "text": " but you could say, well, if we could get a bunch of observations of states and maybe have an expert human pilot tell us what's the best action y to take,"}, {"start": 201.0, "end": 208.0, "text": " you could then train a neural network using supervised learning to directly learn the mapping from the state s,"}, {"start": 208.0, "end": 214.0, "text": " which I'm calling x here, to an action a, which I'm calling the label y here."}, {"start": 214.0, "end": 224.0, "text": " But it turns out that when the helicopter is moving through the air, it's actually very ambiguous what is the exact one right action to take."}, {"start": 224.0, "end": 230.0, "text": " Do you tilt a bit to the left or a lot more to the left or increase the helicopter stress a little bit or a lot?"}, {"start": 230.0, "end": 236.0, "text": " It's actually very difficult to get a data set of x and the ideal action y."}, {"start": 236.0, "end": 242.0, "text": " So that's why for a lot of tasks of controlling a robot like a helicopter and other robots,"}, {"start": 242.0, "end": 248.0, "text": " the supervised learning approach doesn't work well and we instead use reinforcement learning."}, {"start": 248.0, "end": 256.0, "text": " Now, a key input to a reinforcement learning is something called the reward or the reward function,"}, {"start": 256.0, "end": 261.0, "text": " which tells the helicopter when it's doing well and when it's doing poorly."}, {"start": 261.0, "end": 266.0, "text": " So the way I like to think of a reward function is it's a bit like training a dog."}, {"start": 266.0, "end": 273.0, "text": " When I was growing up, my family had a dog and it was my job to train the dog or the puppy to behave."}, {"start": 273.0, "end": 276.0, "text": " So how do you get the puppy to behave well?"}, {"start": 276.0, "end": 279.0, "text": " Well, you can't demonstrate that much to the puppy."}, {"start": 279.0, "end": 284.0, "text": " Instead, you let us do a thing and whenever it does something good, you go, oh, good dog."}, {"start": 284.0, "end": 287.0, "text": " And whenever it did something bad, you go, bad dog."}, {"start": 287.0, "end": 294.0, "text": " And then hopefully it learns by itself how to do more of the good dog and fewer of the bad dog things."}, {"start": 294.0, "end": 297.0, "text": " So training for reinforcement learning is like that."}, {"start": 297.0, "end": 300.0, "text": " When the helicopter is flying well, you go, oh, good helicopter."}, {"start": 300.0, "end": 304.0, "text": " And if it does something bad, like trash, you go, bad helicopter."}, {"start": 304.0, "end": 308.0, "text": " And then it's a reinforcement learning algorithm's job to figure out how to get more of the good helicopter"}, {"start": 308.0, "end": 312.0, "text": " and fewer of the bad helicopter outcomes."}, {"start": 312.0, "end": 320.0, "text": " One way to think of why reinforcement learning is so powerful is you have to tell it what to do rather than how to do it"}, {"start": 320.0, "end": 328.0, "text": " and specifying the reward function rather than the actual action gives you a lot more flexibility in how you design the system."}, {"start": 328.0, "end": 339.0, "text": " Concretely, for flying the helicopter, whenever it is flying well, you may give it a reward of plus one every second that is flying well."}, {"start": 339.0, "end": 344.0, "text": " And maybe whenever it's flying poorly, you may give it a negative reward."}, {"start": 344.0, "end": 350.0, "text": " Or if it ever crashes, you may give it a very large negative reward, like negative one thousand."}, {"start": 350.0, "end": 357.0, "text": " And so this will incentivize the helicopter to spend a lot more time flying well and hopefully to never crash."}, {"start": 357.0, "end": 360.0, "text": " But here's another fun video."}, {"start": 360.0, "end": 366.0, "text": " I was using the good dog, bad dog analogy for reinforcement learning for many years."}, {"start": 366.0, "end": 371.0, "text": " And then one day I actually managed to get my hands on a robotic dog"}, {"start": 371.0, "end": 378.0, "text": " and could actually use this reinforcement learning good dog, bad dog methodology to train a robot dog to get over obstacles."}, {"start": 378.0, "end": 384.0, "text": " So this is a video of a robot dog that using reinforcement learning,"}, {"start": 384.0, "end": 393.0, "text": " which rewards it moving toward the left of the screen, has learned how to place his feet carefully or climb over a variety of obstacles."}, {"start": 393.0, "end": 399.0, "text": " And if you think about what it takes to program a dog like this, I have no idea."}, {"start": 399.0, "end": 405.0, "text": " I really don't know how to tell it what's the best way to place his legs to get over a given obstacle."}, {"start": 405.0, "end": 412.0, "text": " All of these things were figured out automatically by the robot just by giving it rewards that incentivizes it,"}, {"start": 412.0, "end": 416.0, "text": " making progress toward the goal on the left of the screen."}, {"start": 416.0, "end": 424.0, "text": " Today, reinforcement learning has been successfully applied to a variety of applications ranging from controlling robots."}, {"start": 424.0, "end": 435.0, "text": " And in fact, later this week in the practice lab, you implement for yourself a reinforcement learning algorithm to land a lunar lander in simulation."}, {"start": 435.0, "end": 438.0, "text": " It's also been used for factory optimization."}, {"start": 438.0, "end": 446.0, "text": " How do you rearrange things in the factory to maximize throughput and efficiency as well as financial stock trading?"}, {"start": 446.0, "end": 451.0, "text": " For example, one of my friends was working on efficient stock execution."}, {"start": 451.0, "end": 455.0, "text": " So if you've decided to sell a million shares over the next several days,"}, {"start": 455.0, "end": 462.0, "text": " well, you may not want to dump a million shares on the stock market suddenly because that will move prices against you."}, {"start": 462.0, "end": 472.0, "text": " So what's the best way to sequence out your trades over time so that you can sell the shares you want to sell and hopefully get the best possible price for them?"}, {"start": 472.0, "end": 477.0, "text": " Finally, there have also been many applications of reinforcement learning to play in games,"}, {"start": 477.0, "end": 486.0, "text": " everything from checkers to chess to the card game of bridge to go as well as for playing many video games."}, {"start": 486.0, "end": 488.0, "text": " So that's reinforcement learning."}, {"start": 488.0, "end": 497.0, "text": " Even though reinforcement learning is not used nearly as much as supervised learning, it is still used in a few applications today."}, {"start": 497.0, "end": 505.0, "text": " And the key idea is rather than you needing to tell the algorithm what is the right output, why for every single input,"}, {"start": 505.0, "end": 512.0, "text": " all you have to do instead is specify a reward function that tells it when it's doing well and when it's doing poorly."}, {"start": 512.0, "end": 518.0, "text": " And it's a job of the algorithm to automatically figure out how to choose good actions."}, {"start": 518.0, "end": 524.0, "text": " With that, let's now go into the next video where we'll formalize the reinforcement learning problem"}, {"start": 524.0, "end": 536.0, "text": " and also start to develop algorithms for automatically picking good actions."}]