1 00:00:00 --> 00:00:00 2 00:00:00 --> 00:00:01 The following content is provided under a 3 00:00:01 --> 00:00:03 Creative Commons license. 4 00:00:03 --> 00:00:06 Your support will help MIT OpenCourseWare continue to 5 00:00:06 --> 00:00:10 offer high quality educational resources for free. 6 00:00:10 --> 00:00:13 To make a donation, or view additional materials from 7 00:00:13 --> 00:00:17 hundreds of MIT courses, visit MIT OpenCourseWare 8 00:00:17 --> 00:00:19 at ocw.mit.edu. 9 00:00:19 --> 00:00:25 PROFESSOR: So you may recall that, in the last lecture, we 10 00:00:25 --> 00:00:29 more or less solved the drunken student problem, looking 11 00:00:29 --> 00:00:32 at a random walk. 12 00:00:32 --> 00:00:36 I now want to move on and discuss some variants of the 13 00:00:36 --> 00:00:41 random walk problem that are collectively known as 14 00:00:41 --> 00:00:53 biased random walks. 15 00:00:53 --> 00:00:58 So the notion here is, the walk is still stochastic but there 16 00:00:58 --> 00:01:02 is some bias in the direction, so the movements are not 17 00:01:02 --> 00:01:05 uniformly distributed or equally distributed 18 00:01:05 --> 00:01:07 in all directions. 19 00:01:07 --> 00:01:11 As I go through this, I want you to sort of, think in 20 00:01:11 --> 00:01:16 advance about what the take-home message should be. 21 00:01:16 --> 00:01:20 One, and this is probably the most important part for today, 22 00:01:20 --> 00:01:24 is I want to illustrate how by designing our programs in a 23 00:01:24 --> 00:01:30 nice way around classes, we can change them to do something 24 00:01:30 --> 00:01:35 else writing a minimal amount of code. 25 00:01:35 --> 00:01:39 And the idea here is that classes are not there just to 26 00:01:39 --> 00:01:42 provide some syntax that makes life complicated, but to 27 00:01:42 --> 00:01:46 actually provide a mechanism that lets us structure our 28 00:01:46 --> 00:01:52 programs in a way that we can modify them later. 29 00:01:52 --> 00:01:55 I also want to give you a bit more experience looking at 30 00:01:55 --> 00:01:59 data, and understanding how, when you get the results of a 31 00:01:59 --> 00:02:04 simulation or anything else that provides you with data, 32 00:02:04 --> 00:02:08 you can plot, them study the plots, and try and use those 33 00:02:08 --> 00:02:12 to develop an understanding about what's going on. 34 00:02:12 --> 00:02:16 And finally, I want to just get you thinking more 35 00:02:16 --> 00:02:18 about random behavior. 36 00:02:18 --> 00:02:20 Because we're going to talk a lot more this semester and 37 00:02:20 --> 00:02:24 in general throughout your careers, you'll see a lot of 38 00:02:24 --> 00:02:26 uses of stochastic things. 39 00:02:26 --> 00:02:31 All right, so let's think about these biased walks. 40 00:02:31 --> 00:02:37 So for example, assume that the drunk grew up in South Florida, 41 00:02:37 --> 00:02:40 and really hates the New England winter. 42 00:02:40 --> 00:02:44 Well there might be a bias that even though the drunk is not in 43 00:02:44 --> 00:02:48 total control, she's kind of wandering southward. 44 00:02:48 --> 00:02:51 So there's a bias when taking a step to more likely go 45 00:02:51 --> 00:02:55 south than certainly north. 46 00:02:55 --> 00:02:59 Or imagine that the drunk is photosensitive and moves either 47 00:02:59 --> 00:03:04 towards the sun or away from the sun, or some such thing. 48 00:03:04 --> 00:03:07 So we're going to look at different things of that nature 49 00:03:07 --> 00:03:10 and think about, I'll come back to Chutes and Ladders later in 50 00:03:10 --> 00:03:19 the lecture, you can speculate on why this is here. 51 00:03:19 --> 00:03:21 And we'll look at that. 52 00:03:21 --> 00:03:26 So, this is on the front page of your handout here. 53 00:03:26 --> 00:03:30 I've taken the random walk program we looked at last 54 00:03:30 --> 00:03:35 time and changed it a bit. 55 00:03:35 --> 00:03:46 And in particular, I've changed the way the drunk works. 56 00:03:46 --> 00:03:50 So let's look at the code. 57 00:03:50 --> 00:04:07 Wow, haven't even done anything it's -- see how this works. 58 00:04:07 --> 00:04:14 So now, drunk itself is a very small class, one I don't 59 00:04:14 --> 00:04:19 actually intend to ever instantiate. 60 00:04:19 --> 00:04:23 I've pared it down, it has only two methods in it. 61 00:04:23 --> 00:04:29 It has an init, which is the same as before, and a 62 00:04:29 --> 00:04:35 move which is the same as before, almost the same. 63 00:04:35 --> 00:04:40 Now I'm going to have the class usual drunk. 64 00:04:40 --> 00:04:42 That's the drunk we looked at the last time. 65 00:04:42 --> 00:04:45 And this usual drunk will behave just like the drunk 66 00:04:45 --> 00:04:48 we looked at last time. 67 00:04:48 --> 00:04:55 In here, I'm going to override the move method of the 68 00:04:55 --> 00:05:02 inherited superclass, and what this is going to do is, it's 69 00:05:02 --> 00:05:07 going to make the same random choice it made before and then 70 00:05:07 --> 00:05:10 it's going to call drunk dot move with the new 71 00:05:10 --> 00:05:14 compass point. 72 00:05:14 --> 00:05:19 So all I've done is, I've taken a couple of lines of code out 73 00:05:19 --> 00:05:23 of the previous implementation and moved it to the subclass. 74 00:05:23 --> 00:05:29 So it's now, excuse me, in the subclass I'm making 75 00:05:29 --> 00:05:32 the decision about which direction to move. 76 00:05:32 --> 00:05:36 Once I've made that decision, then I can call the 77 00:05:36 --> 00:05:39 drunk in the superclass. 78 00:05:39 --> 00:05:47 Notice here, when I've made the call, drunk dot move. 79 00:05:47 --> 00:05:50 So usually you're expecting me to write something 80 00:05:50 --> 00:05:54 like d dot move. 81 00:05:54 --> 00:05:55 The object. 82 00:05:55 --> 00:06:01 Here, instead I'm specifying which class to get the move 83 00:06:01 --> 00:06:07 from, So this is saying, don't call my local move, call the 84 00:06:07 --> 00:06:11 move from the superclass. 85 00:06:11 --> 00:06:14 There are a number of other syntaxes I could've used to 86 00:06:14 --> 00:06:16 accomplish the same thing. 87 00:06:16 --> 00:06:24 I used this because it seemed the most straightforward. 88 00:06:24 --> 00:06:29 Now let's compare the usual drunk to the cold drunk. 89 00:06:29 --> 00:06:35 So the cold drunk, again, I've overridden the move, and now 90 00:06:35 --> 00:06:37 it does something different. 91 00:06:37 --> 00:06:42 It gets the random compass point as before, but if it 92 00:06:42 --> 00:06:47 happens to be south, it calls drunk dot move 93 00:06:47 --> 00:06:53 with twice the distance. 94 00:06:53 --> 00:06:59 So whenever I get the notion I'm moving south, because I 95 00:06:59 --> 00:07:03 love the warmth, I actually move twice as fast. 96 00:07:03 --> 00:07:06 So instead of taking one step, which I do to the other compass 97 00:07:06 --> 00:07:11 points, if I happen to be going south I'll take two steps. 98 00:07:11 --> 00:07:17 So I'm biased towards moving southward. 99 00:07:17 --> 00:07:23 And then I call drunk dot move. 100 00:07:23 --> 00:07:30 Otherwise, I call drunk dot move with the distances before. 101 00:07:30 --> 00:07:34 So I've isolated into the subclass this notion 102 00:07:34 --> 00:07:38 of being heat-seeking. 103 00:07:38 --> 00:07:42 We've got a third sub class, ew drunk, known 104 00:07:42 --> 00:07:47 for east west drunk. 105 00:07:47 --> 00:07:52 And here, what I've done is, I choose to compass point and 106 00:07:52 --> 00:07:57 then while it's not either east or west, I choose again. 107 00:07:57 --> 00:08:00 So this drunk can only move eastward or westward. 108 00:08:00 --> 00:08:07 Can't move north or south. 109 00:08:07 --> 00:08:12 So again you'll see I'm able to have three kinds of drunks. 110 00:08:12 --> 00:08:15 Who as we will see, exhibit rather different behavior from 111 00:08:15 --> 00:08:25 each other with a minimal amount of change to the code. 112 00:08:25 --> 00:08:33 If we look down at the bottom, we'll see that the code 113 00:08:33 --> 00:08:37 is pretty much exactly what it was last time. 114 00:08:37 --> 00:08:40 By the way, this doesn't quite match the code in your handout. 115 00:08:40 --> 00:08:44 I decided to make the plots a little bit prettier with better 116 00:08:44 --> 00:08:47 titles and things, but when I tried to put these in your 117 00:08:47 --> 00:08:49 handouts it wouldn't fit. 118 00:08:49 --> 00:08:53 So I have a little more compact things, but this is, I think, 119 00:08:53 --> 00:08:55 a better way to write it. 120 00:08:55 --> 00:09:01 But essentially, perform trial, perform sim, answer quest, are 121 00:09:01 --> 00:09:05 all identical to what they were before. 122 00:09:05 --> 00:09:11 So because I structured my program in such a way that 123 00:09:11 --> 00:09:15 the drunk's behavior was independent of all the code for 124 00:09:15 --> 00:09:21 the generating the trials and plotting the results, I didn't 125 00:09:21 --> 00:09:24 have to change any of that. 126 00:09:24 --> 00:09:27 And this is the key to good design. 127 00:09:27 --> 00:09:34 Is to isolate decisions in small parts of your program, so 128 00:09:34 --> 00:09:38 when as inevitable happens, you want to enhance the program, 129 00:09:38 --> 00:09:41 or you discover you've done something wrong, the number 130 00:09:41 --> 00:09:48 changes you make is not large. 131 00:09:48 --> 00:09:53 OK, one thing we do need to look at down here is, it's not 132 00:09:53 --> 00:09:57 quite the same as before, because we'll see that there's 133 00:09:57 --> 00:10:06 an extra parameter to these things called drunk type. 134 00:10:06 --> 00:10:10 So if we start with answer question, it takes as before, 135 00:10:10 --> 00:10:15 the time, the number of trials, a title, and this one extra 136 00:10:15 --> 00:10:18 thing called the drunk type. 137 00:10:18 --> 00:10:22 And then when it goes on and it calls perform sim, it 138 00:10:22 --> 00:10:27 passes the drunk type. 139 00:10:27 --> 00:10:38 And this is the key line here. 140 00:10:38 --> 00:10:43 Before, you may recall we just said d equals drunk 141 00:10:43 --> 00:10:45 with the arguments. 142 00:10:45 --> 00:10:51 Here, I say d equals drunk type. 143 00:10:51 --> 00:10:56 So what is drunk type? 144 00:10:56 --> 00:11:00 Drunk type is itself a type. 145 00:11:00 --> 00:11:04 We can use types, you know variables can have as their 146 00:11:04 --> 00:11:09 values types, parameters can have as their values types. 147 00:11:09 --> 00:11:13 So I'm just passing the type around so that here, when it 148 00:11:13 --> 00:11:17 comes time to get a drunk, I get a drunk of the 149 00:11:17 --> 00:11:21 appropriate type. 150 00:11:21 --> 00:11:25 So I can now answer the question about a usual drunk, 151 00:11:25 --> 00:11:31 or a cold drunk, or a ew drunk. 152 00:11:31 --> 00:11:36 This is very common kind of programming paradigm. 153 00:11:36 --> 00:11:41 We've talked about it before, but this is yet another example 154 00:11:41 --> 00:11:44 of how we use polymorphism. 155 00:11:44 --> 00:11:47 Polymorphism. 156 00:11:47 --> 00:11:51 We write our code in such a way that it works with 157 00:11:51 --> 00:11:54 many types of objects. 158 00:11:54 --> 00:11:57 Here we're writing code that will work with 159 00:11:57 --> 00:12:01 any subtype of drunk. 160 00:12:01 --> 00:12:04 Now I'd better not pass it a float. 161 00:12:04 --> 00:12:08 You know, if I answer quest, and instead of something like 162 00:12:08 --> 00:12:12 usual drunk or cold drunk or e w drunk, I pass it float or 163 00:12:12 --> 00:12:17 int, the world will come crashing down around my head. 164 00:12:17 --> 00:12:22 But I haven't, so you'll see down here, I pass it num steps, 165 00:12:22 --> 00:12:27 number trials, and usual drunk. 166 00:12:27 --> 00:12:28 Which is the name of? 167 00:12:28 --> 00:12:33 A class. 168 00:12:33 --> 00:12:38 Any questions about this? 169 00:12:38 --> 00:12:39 Yes? 170 00:12:39 --> 00:12:45 STUDENT: [INAUDIBLE] 171 00:12:45 --> 00:12:46 PROFESSOR: Louder, please? 172 00:12:46 --> 00:12:53 STUDENT: [INAUDIBLE] 173 00:12:53 --> 00:12:54 PROFESSOR: Good, good question. 174 00:12:54 --> 00:12:58 The question is, does a drunk type make a new drunk? 175 00:12:58 --> 00:13:00 Now, I have so much candy to choose from, I don't 176 00:13:00 --> 00:13:02 know what to throw you. 177 00:13:02 --> 00:13:07 Do you like Tootsie Rolls, Snickers, Tootsie Roll Pops, 178 00:13:07 --> 00:13:11 Dots, what's your choice? 179 00:13:11 --> 00:13:19 Snickers. 180 00:13:19 --> 00:13:23 OK, so what is it? 181 00:13:23 --> 00:13:29 Down here nothing is created when that call was made. 182 00:13:29 --> 00:13:34 It was if I had typed the word float or int. 183 00:13:34 --> 00:13:41 I'm merely saying, here is a type, and the parameter should 184 00:13:41 --> 00:13:45 now be bound to that type. 185 00:13:45 --> 00:13:49 Now any time you use the parameter, it's just as if you 186 00:13:49 --> 00:13:56 had written the string, in this case, usual drunk. 187 00:13:56 --> 00:14:08 So when I get up to here, think about, it will take, the 188 00:14:08 --> 00:14:17 variable drunk type, evaluate it, it will evaluate to a 189 00:14:17 --> 00:14:23 type usual drunk, say, in the first call. 190 00:14:23 --> 00:14:28 And then it will, just as if I had written usual drunk, invoke 191 00:14:28 --> 00:14:34 the init method of drunk, and create a new drunk, but this 192 00:14:34 --> 00:14:40 drunk will be of type usual drunk rather than a drunk. 193 00:14:40 --> 00:14:44 Does that make sense? 194 00:14:44 --> 00:14:50 All right, so this avoids my having to write a whole bunch 195 00:14:50 --> 00:14:55 of tests, I could have passed a string, and said if the string 196 00:14:55 --> 00:14:59 said usual drunk, then d equals something. 197 00:14:59 --> 00:15:01 But here instead of that, I'm actually passing 198 00:15:01 --> 00:15:07 the type itself. 199 00:15:07 --> 00:15:12 OK? 200 00:15:12 --> 00:15:16 So other than the fact that I have to pass the type around, 201 00:15:16 --> 00:15:21 this is exactly the same as before. 202 00:15:21 --> 00:15:26 Now just for fun, we saw that last time when I asked you what 203 00:15:26 --> 00:15:30 did usual drunk do, there was some confusion. 204 00:15:30 --> 00:15:34 Not confusion, just a bad guess about how the 205 00:15:34 --> 00:15:35 drunk would wander. 206 00:15:35 --> 00:15:38 So, let's try it again. 207 00:15:38 --> 00:15:44 What do you think about the cold drunk? 208 00:15:44 --> 00:15:48 Will the cold drunk get further from the origin 209 00:15:48 --> 00:15:50 than the usual drunk? 210 00:15:50 --> 00:15:51 Not further from the origin? 211 00:15:51 --> 00:15:55 Who thinks the cold drunk will be further away 212 00:15:55 --> 00:15:56 the end of 500 steps? 213 00:15:56 --> 00:16:01 Who thinks the cold drunk will not be further away? 214 00:16:01 --> 00:16:05 And I'll bet we can all agr -- got that right, I think -- and 215 00:16:05 --> 00:16:08 I'll bet you'll all agree that, with higher probability, the 216 00:16:08 --> 00:16:12 cold drunk will be south of the origin than north 217 00:16:12 --> 00:16:14 of the origin. 218 00:16:14 --> 00:16:19 More interesting, how about the ew drunk? 219 00:16:19 --> 00:16:21 So this is a drunk that only goes east or 220 00:16:21 --> 00:16:27 west, east or west. 221 00:16:27 --> 00:16:31 Will this drunk, well, first of all, what's 222 00:16:31 --> 00:16:33 the expected distance? 223 00:16:33 --> 00:16:37 Do you think it should be close to zero or not close to zero? 224 00:16:37 --> 00:16:41 Who thinks it should be close to 0? 225 00:16:41 --> 00:16:44 Who thinks it won't be close to 0? 226 00:16:44 --> 00:16:47 Well you guys have all fallen for the same trick you 227 00:16:47 --> 00:16:49 fell for last time. 228 00:16:49 --> 00:16:50 Fooled you twice. 229 00:16:50 --> 00:16:54 Be careful, one more and you're out. 230 00:16:54 --> 00:16:56 As we'll see. 231 00:16:56 --> 00:16:57 But it's interesting. 232 00:16:57 --> 00:17:12 So let's run this program and see what happens. 233 00:17:12 --> 00:17:15 I can take a just a second or two and we should 234 00:17:15 --> 00:17:22 get a bunch of plots. 235 00:17:22 --> 00:17:25 All right, so here's the usual drunk. 236 00:17:25 --> 00:17:33 100 trials and just as before, wandered away. 237 00:17:33 --> 00:17:36 Moderately smooth, but of course little ups and downs, 238 00:17:36 --> 00:17:42 maybe suggesting averaging over 100 trials is not quite enough. 239 00:17:42 --> 00:17:45 I felt a little better if it were smoother, but the trend 240 00:17:45 --> 00:17:52 is pretty clear here, I think we probably don't doubt it. 241 00:17:52 --> 00:17:56 Well, look at cold drunk. 242 00:17:56 --> 00:18:00 Like a shot heading south. 243 00:18:00 --> 00:18:04 So here we see, there's bias, that if you get south you go 244 00:18:04 --> 00:18:08 twice as far makes a huge difference. 245 00:18:08 --> 00:18:12 Instead of being roughly 20 steps away, it's 246 00:18:12 --> 00:18:16 roughly 120 steps away. 247 00:18:16 --> 00:18:21 So we see, and this is something to think about, a 248 00:18:21 --> 00:18:27 small bias can end up making a huge difference over time. 249 00:18:27 --> 00:18:31 This is why casinos do so well. 250 00:18:31 --> 00:18:34 They don't have to have a very much of a bias in their favor 251 00:18:34 --> 00:18:37 on each roll of the dice in order to accumulate a 252 00:18:37 --> 00:18:40 lot of money over time. 253 00:18:40 --> 00:18:43 It's why if you just weigh your dice a little bit, so that 254 00:18:43 --> 00:18:47 they're not fair, you'll do very very well. 255 00:18:47 --> 00:18:52 I'm not recommending that. 256 00:18:52 --> 00:18:55 Kind of interesting. 257 00:18:55 --> 00:18:58 The e w drunk is pretty much the same distance away 258 00:18:58 --> 00:19:04 as the usual drunk. 259 00:19:04 --> 00:19:09 This is why we run these simulations, is because 260 00:19:09 --> 00:19:10 we learn things. 261 00:19:10 --> 00:19:13 Now, I have to confess, it fooled me, too. 262 00:19:13 --> 00:19:16 The first time I ran this, I looked at this and said, wait 263 00:19:16 --> 00:19:20 a minute, that's not what I expected. 264 00:19:20 --> 00:19:24 So I scratched my head, and thought about, all right, why 265 00:19:24 --> 00:19:27 is it behaving this way? 266 00:19:27 --> 00:19:32 This happens me a lot in my own research, that I crunch some 267 00:19:32 --> 00:19:37 data, do some plots, look at it, get surprised, and on the 268 00:19:37 --> 00:19:41 basis of that I learned something about the underlying 269 00:19:41 --> 00:19:42 system I'm modeling. 270 00:19:42 --> 00:19:47 Because it provokes me to think in ways I had not thought 271 00:19:47 --> 00:19:49 before I saw the data. 272 00:19:49 --> 00:19:50 This is an important lesson. 273 00:19:50 --> 00:19:54 You don't ignore the data, you try and explain the data. 274 00:19:54 --> 00:19:58 So when I thought about what happened, I realize that while 275 00:19:58 --> 00:20:02 I might have started at the origin, and after the first 276 00:20:02 --> 00:20:07 step I'm equally likely to be here or here. 277 00:20:07 --> 00:20:17 Once I've taken the first step, now my expected location 278 00:20:17 --> 00:20:20 is not zero, right? 279 00:20:20 --> 00:20:25 The first step, my expected location was zero. 280 00:20:25 --> 00:20:29 Because equally likely to be plus 1 or minus 1. 281 00:20:29 --> 00:20:34 But once I've taken a step and I happen to be here, my 282 00:20:34 --> 00:20:40 expected location, if I'm here, is plus 1, it's not 0. 283 00:20:40 --> 00:20:43 Because half the time I'll get back to 0, but half 284 00:20:43 --> 00:20:48 the time I'll get to 2. 285 00:20:48 --> 00:20:55 So once I have moved away from where I've started, the 286 00:20:55 --> 00:21:03 expectation of where I'll end up has changed. 287 00:21:03 --> 00:21:07 This is kind of a profound thing to think about, because 288 00:21:07 --> 00:21:12 when we look at it, this kind of behavior explains a lot of 289 00:21:12 --> 00:21:14 surprising results in life. 290 00:21:14 --> 00:21:21 Where, if you get a small run of random events that take you 291 00:21:21 --> 00:21:28 far from where you started, it's hard to get back. 292 00:21:28 --> 00:21:32 So if you think about the stock market, for example, if you 293 00:21:32 --> 00:21:36 happen to get unlucky and have a few days or weeks or months, 294 00:21:36 --> 00:21:42 as the case may be, where you get a run of bad days, it's 295 00:21:42 --> 00:21:45 really hard to get back if all the movements after 296 00:21:45 --> 00:21:46 that are random. 297 00:21:46 --> 00:21:50 Because you've established a new baseline. 298 00:21:50 --> 00:21:53 And as we'll see later, when you start doing things at 299 00:21:53 --> 00:21:57 random, it's likely you'll get a few runs in one direction or 300 00:21:57 --> 00:22:02 another, and then you've got a new baseline, and it's unlikely 301 00:22:02 --> 00:22:04 to get back to where you were originally. 302 00:22:04 --> 00:22:07 We'll see a lot of examples of this. 303 00:22:07 --> 00:22:13 But that's what's happening here, and that's why it 304 00:22:13 --> 00:22:17 looks the way it does. 305 00:22:17 --> 00:22:20 That makes sense to people? 306 00:22:20 --> 00:22:24 Well, so I had this theory, as I often do when I have 307 00:22:24 --> 00:22:28 theories, I don't believe them, so I decided I better write 308 00:22:28 --> 00:22:34 some more code to check it out. 309 00:22:34 --> 00:22:40 So, what I did is, I took the previous simulation and now 310 00:22:40 --> 00:22:44 instead of looking at different kinds of drunks, I got more 311 00:22:44 --> 00:22:50 aggressive in thinking about my analysis of the data. 312 00:22:50 --> 00:22:53 So again, there's a lesson here. 313 00:22:53 --> 00:22:58 I decided I wanted to analyze my data in new ways. 314 00:22:58 --> 00:23:03 And the beauty of it was, I could do that without changing 315 00:23:03 --> 00:23:07 either any of the code about the drunk, or any they of 316 00:23:07 --> 00:23:10 the code about performing the simulation, really. 317 00:23:10 --> 00:23:14 All I had to do was do a different kind of analysis 318 00:23:14 --> 00:23:18 to a first approximation. 319 00:23:18 --> 00:23:26 So, let's look at what I've done here. 320 00:23:26 --> 00:23:30 What I've decided to do here is not only plot, and again, I 321 00:23:30 --> 00:23:37 think you'll see this code, not only plot how far from the 322 00:23:37 --> 00:23:43 origin the drunk is over time, but I'm going to actually 323 00:23:43 --> 00:23:46 plot two other things. 324 00:23:46 --> 00:23:51 I'm going to use a scatter plot, I think I use scatter in 325 00:23:51 --> 00:23:55 this one, I do, to show where the drunk is at each 326 00:23:55 --> 00:23:56 period of time. 327 00:23:56 --> 00:23:59 Actually, just all the places the drunk ends 328 00:23:59 --> 00:24:00 up in each trial. 329 00:24:00 --> 00:24:04 This will give me a visualized way just see, OK, in my, say, 330 00:24:04 --> 00:24:08 100 trials, how many the drunk ended up near the origin, 331 00:24:08 --> 00:24:11 how many of them ended up really far away? 332 00:24:11 --> 00:24:16 And just, allow me to visualize what's going on. 333 00:24:16 --> 00:24:19 And then I'm going to also use a histogram to sort 334 00:24:19 --> 00:24:21 of summarize some things. 335 00:24:21 --> 00:24:34 To get a look at the distribution of the data. 336 00:24:34 --> 00:24:39 We've been just looking at average results, but it's often 337 00:24:39 --> 00:24:41 the case that the average does not really tell 338 00:24:41 --> 00:24:44 the whole story. 339 00:24:44 --> 00:24:46 You want to ask, well, how many of the drunks ended 340 00:24:46 --> 00:24:48 up really far away? 341 00:24:48 --> 00:24:51 How many of the drunks ended up where they started? 342 00:24:51 --> 00:24:55 You can't tell that from the averages. 343 00:24:55 --> 00:24:59 So you use a distribution, which tells you information 344 00:24:59 --> 00:25:03 about how many people ended up where. 345 00:25:03 --> 00:25:07 So we again saw that, in a less pleasant context, maybe, in 346 00:25:07 --> 00:25:10 looking at the quizzes, remember I sent you some plots 347 00:25:10 --> 00:25:16 about the quizzes, and I didn't just say, here was the average. 348 00:25:16 --> 00:25:20 I showed you the distribution of grades. 349 00:25:20 --> 00:25:23 That allowed you to see, not only where you were relative 350 00:25:23 --> 00:25:27 to the average, but whether you were an outlier. 351 00:25:27 --> 00:25:30 Was your grade much better than the average? 352 00:25:30 --> 00:25:33 Or were there a whole bunch of people around where you are? 353 00:25:33 --> 00:25:37 So there's a lot of information there, that will help us 354 00:25:37 --> 00:25:41 understand what's really going on. 355 00:25:41 --> 00:25:45 So we'll run this now. 356 00:25:45 --> 00:25:48 Again, there's nothing very interesting here about how I 357 00:25:48 --> 00:25:52 did it, I just used some of these Pylab dot hist, which 358 00:25:52 --> 00:25:55 gives me a histogram, Pylab dot scatter, which gives 359 00:25:55 --> 00:25:57 me a scatter plot. 360 00:25:57 --> 00:26:01 I'll take 500 steps, 400 trials. 361 00:26:01 --> 00:26:04 I've done some more trials here, so we get some smoother 362 00:26:04 --> 00:26:07 lines, better distributions. 363 00:26:07 --> 00:26:10 And then I'm going to look at the usual drunk and ew drunk 364 00:26:10 --> 00:26:24 only, just to save some time. 365 00:26:24 --> 00:26:31 At least I think I am. 366 00:26:31 --> 00:26:35 My computer runs faster when it's plugged in. 367 00:26:35 --> 00:26:37 All right, but we have our figures here, 368 00:26:37 --> 00:26:40 let's look at them. 369 00:26:40 --> 00:26:42 So here's figure one, the usual drunk. 370 00:26:42 --> 00:26:46 Well, all right, as we've seen this 1000 times, 371 00:26:46 --> 00:26:47 or at least six. 372 00:26:47 --> 00:26:55 So doing what it usually does, not quite 20. 373 00:26:55 --> 00:26:56 This is kind of interesting. 374 00:26:56 --> 00:27:00 This is the final locations of the 400 trials 375 00:27:00 --> 00:27:02 of the usual drunk. 376 00:27:02 --> 00:27:04 So we see some information here, that we really couldn't 377 00:27:04 --> 00:27:08 get from the averages. 378 00:27:08 --> 00:27:12 That there are more of these points near the middle, 379 00:27:12 --> 00:27:18 but there are certainly plenty scattered around. 380 00:27:18 --> 00:27:21 And we get to see that, they're pretty much symmetric 381 00:27:21 --> 00:27:24 around where we started. 382 00:27:24 --> 00:27:26 This is what we would have hoped, right? 383 00:27:26 --> 00:27:31 If we had looked at it, and we had seen all the points up 384 00:27:31 --> 00:27:34 here, or most of them up here, we would have said, wait a 385 00:27:34 --> 00:27:38 minute, there's something wrong with my code. 386 00:27:38 --> 00:27:40 This was supposed to not be a biased walk, but 387 00:27:40 --> 00:27:43 an unbiased walk. 388 00:27:43 --> 00:27:47 And if I'd seen a bias in this population, I should have 389 00:27:47 --> 00:27:50 gotten nervous that I had some problems with my 390 00:27:50 --> 00:27:51 implementation. 391 00:27:51 --> 00:27:53 My simulation. 392 00:27:53 --> 00:27:56 So in addition to helping me understand results, this gives 393 00:27:56 --> 00:27:59 me some confidence that I really am doing an 394 00:27:59 --> 00:28:03 unbiased walk, right? 395 00:28:03 --> 00:28:04 Some over here, some over here. 396 00:28:04 --> 00:28:09 Not exactly the same, but close enough that I feel 397 00:28:09 --> 00:28:19 pretty comfortable. 398 00:28:19 --> 00:28:25 And if I look at the distribution, which probably I 399 00:28:25 --> 00:28:27 could've if I worked really hard, gotten from the scatter 400 00:28:27 --> 00:28:34 plot, but I really didn't want to, we'll see that most of the 401 00:28:34 --> 00:28:39 drunks actually do end up pretty close to the origin. 402 00:28:39 --> 00:28:43 But that there are a few that are pretty far away. 403 00:28:43 --> 00:28:49 And again, it's close to symmetric around zero. 404 00:28:49 --> 00:28:52 Which gives me a good feeling that things are working 405 00:28:52 --> 00:28:54 the way they should. 406 00:28:54 --> 00:29:00 This, by the way, is what's called a normal distribution. 407 00:29:00 --> 00:29:04 Because once upon a time, people believed this was the 408 00:29:04 --> 00:29:07 way things usually happened. 409 00:29:07 --> 00:29:16 This is called either normal or Gaussian. 410 00:29:16 --> 00:29:18 The mathematician Gauss was one of the first people to write 411 00:29:18 --> 00:29:20 about this distribution. 412 00:29:20 --> 00:29:23 We'll come back to this later, and among other things, 413 00:29:23 --> 00:29:27 we'll try and see whether normal is really normal. 414 00:29:27 --> 00:29:29 But you see it a lot of times. 415 00:29:29 --> 00:29:34 And basically what it says is that most of the values 416 00:29:34 --> 00:29:38 hang out around the average, the middle. 417 00:29:38 --> 00:29:42 And there are a few outliers, and as we get further and 418 00:29:42 --> 00:29:49 further out, fewer and fewer points occur. 419 00:29:49 --> 00:29:52 So you'll see these kind of curves, of distributions, 420 00:29:52 --> 00:29:53 occurring a lot. 421 00:29:53 --> 00:29:56 Again, we'll come back to distributions in a week, or 422 00:29:56 --> 00:29:58 actually in a lecture or two. 423 00:29:58 --> 00:30:03 See a little bit more today, and then more later on. 424 00:30:03 --> 00:30:13 All right, here's our east west drunk, again as before, 425 00:30:13 --> 00:30:18 drifting off to around 18. 426 00:30:18 --> 00:30:23 Well, look at these dots. 427 00:30:23 --> 00:30:26 Well, this makes me feel, that at least I know that the drunk 428 00:30:26 --> 00:30:30 is only moving east and west. 429 00:30:30 --> 00:30:32 And again you'll see, pretty dense in the middle 430 00:30:32 --> 00:30:35 and a few outliers. 431 00:30:35 --> 00:30:37 Managed to get a little further east than west, 432 00:30:37 --> 00:30:41 but that happens. 433 00:30:41 --> 00:30:47 East is always more attractive. 434 00:30:47 --> 00:30:49 What we might have guessed. 435 00:30:49 --> 00:30:56 And if we look at the distribution, again we can look 436 00:30:56 --> 00:31:00 at it, and I'm just giving you the east west values here, and 437 00:31:00 --> 00:31:07 again it's about the same. 438 00:31:07 --> 00:31:11 So, what do I want you to take away from these graphs? 439 00:31:11 --> 00:31:15 Different plots show you different things. 440 00:31:15 --> 00:31:18 So I'm not going to try and claim that of these three 441 00:31:18 --> 00:31:22 different plots we did, one is the right one to do. 442 00:31:22 --> 00:31:24 What I'm going to assert is that you want 443 00:31:24 --> 00:31:26 to do all of them. 444 00:31:26 --> 00:31:31 Try and visualize the data in multiple ways. 445 00:31:31 --> 00:31:36 And sometimes it's much easier to, even if different plots 446 00:31:36 --> 00:31:41 contain exactly the same information, and in some sense 447 00:31:41 --> 00:31:45 of the scatter plot and the histogram do contain exactly 448 00:31:45 --> 00:31:47 the same information. 449 00:31:47 --> 00:31:49 In fact, there's more information in the scatter 450 00:31:49 --> 00:31:53 plot, in some sense, because I see each one individually. 451 00:31:53 --> 00:31:57 But it's, for me, a lot harder to see. 452 00:31:57 --> 00:32:00 If I'd ask you from the scatter plot, are they 453 00:32:00 --> 00:32:02 normally distributed? 454 00:32:02 --> 00:32:04 You might have had a hard time answering it. 455 00:32:04 --> 00:32:08 Particularly for the usual drunk, where you just 456 00:32:08 --> 00:32:10 saw a lot of points. 457 00:32:10 --> 00:32:14 So the idea of some summarizing it in the histogram makes it 458 00:32:14 --> 00:32:19 much easier to make sense of the data, and see what you're 459 00:32:19 --> 00:32:32 doing, and to try and learn the lesson you're trying to learn. 460 00:32:32 --> 00:32:37 OK, this makes sense to people? 461 00:32:37 --> 00:32:40 All right, let's move on. 462 00:32:40 --> 00:32:48 Now we'll go back to this lovely picture we had before. 463 00:32:48 --> 00:32:51 Any of you ever play the game Chutes and Ladders? 464 00:32:51 --> 00:32:53 Raise your hand? 465 00:32:53 --> 00:32:57 OK, some things never go out of style. 466 00:32:57 --> 00:33:04 Well, imagine your poor drunk wandering through this board, 467 00:33:04 --> 00:33:09 and every once in a while, because I'm kind of a, not a 468 00:33:09 --> 00:33:12 nice person, I've eliminated all the ladders, and 469 00:33:12 --> 00:33:13 have only some chutes. 470 00:33:13 --> 00:33:16 And every once in a while the drunk hits a chute 471 00:33:16 --> 00:33:18 and goes whoosh. 472 00:33:18 --> 00:33:27 And in fact, let's, for the sake of simplicity here, assume 473 00:33:27 --> 00:33:32 that the chutes are going to, every once in a while, the 474 00:33:32 --> 00:33:37 drunk will hit a bad spot, and go right back to the origin. 475 00:33:37 --> 00:33:40 So this poor, say, heat-seeking drunk who's trying to head 476 00:33:40 --> 00:33:45 south, does it for a while and maybe gets zipped right back 477 00:33:45 --> 00:33:48 to where he or she started. 478 00:33:48 --> 00:33:54 All right, I've now told you I want to put some, 479 00:33:54 --> 00:33:55 make this happen. 480 00:33:55 --> 00:34:01 What part of the code do you think I should change? 481 00:34:01 --> 00:34:02 Somebody? 482 00:34:02 --> 00:34:04 STUDENT: The field. 483 00:34:04 --> 00:34:11 PROFESSOR: The field, absolutely. 484 00:34:11 --> 00:34:14 Those are good to throw short distances. 485 00:34:14 --> 00:34:17 The field, right, because what we're talking about here is not 486 00:34:17 --> 00:34:23 a property of the drunk, or a property of the simulation, but 487 00:34:23 --> 00:34:30 a property of the space in which the drunk is wandering. 488 00:34:30 --> 00:34:34 So again, we see that by structuring the initial program 489 00:34:34 --> 00:34:40 around the natural abstractions that occur in the problem, 490 00:34:40 --> 00:34:46 natural kinds of changes can be localized. 491 00:34:46 --> 00:34:52 So let's go and change the field. 492 00:34:52 --> 00:34:57 So I'm going to have the field I had before plus this 493 00:34:57 --> 00:35:03 thing called an odd field. 494 00:35:03 --> 00:35:06 Odd field will be a subclass of field. 495 00:35:06 --> 00:35:08 This is not odd as in odd or even, this is 496 00:35:08 --> 00:35:12 odd as in strange. 497 00:35:12 --> 00:35:19 So I'm going to first define where my chutes are. 498 00:35:19 --> 00:35:30 So is chute will take, will get the coordinates, and assign it 499 00:35:30 --> 00:35:34 to x and y, so it gets the coordinates of a place, and 500 00:35:34 --> 00:35:39 then will return abs x minus abs y is equal to zero. 501 00:35:39 --> 00:35:45 So, where are my chutes going to occur? 502 00:35:45 --> 00:35:53 Somebody? 503 00:35:53 --> 00:36:00 Yeah, kind of radiating out from the origin. 504 00:36:00 --> 00:36:06 Any place, so I'll have my origin, here. 505 00:36:06 --> 00:36:08 Got my graph. 506 00:36:08 --> 00:36:13 And all along here, any place x and y are equal, 507 00:36:13 --> 00:36:18 there'll be a chute. 508 00:36:18 --> 00:36:21 Now, I have to be a little bit careful that it doesn't happen 509 00:36:21 --> 00:36:27 here, or we won't get anywhere. 510 00:36:27 --> 00:36:32 So, and then move, in odd field, will call field dot 511 00:36:32 --> 00:36:38 move, which is unchanged from what it was before. 512 00:36:38 --> 00:36:42 And then it will say, if self dot is chute, set 513 00:36:42 --> 00:36:45 the location back to 0,0. 514 00:36:45 --> 00:36:50 So the poor drunk will move as before, and if he or she hits 515 00:36:50 --> 00:36:58 this wormhole, get instantly teleported back to the origin. 516 00:36:58 --> 00:37:01 Very small change, but it will give us rather different 517 00:37:01 --> 00:37:08 behaviors, at least I think it will. 518 00:37:08 --> 00:37:17 And then if we look at how we use it, not much changes. 519 00:37:17 --> 00:37:20 Except, what do you think is going to have to change? 520 00:37:20 --> 00:37:23 Where will I have to make the change, somebody? 521 00:37:23 --> 00:37:27 You can actually see the code here. 522 00:37:27 --> 00:37:31 I'll have to get a different field, right? 523 00:37:31 --> 00:37:35 So, at the place where I instantiate a field, instead of 524 00:37:35 --> 00:37:40 instantiating a field, I'll instantiate an odd field. 525 00:37:40 --> 00:37:44 Now if I'd had 16 different kinds of odd fields, or even 526 00:37:44 --> 00:37:49 two, I might well have done what I did with drunk. 527 00:37:49 --> 00:37:53 But in order to sort of minimize things, I've done 528 00:37:53 --> 00:37:55 something much smaller. 529 00:37:55 --> 00:37:57 So let's see, where did we get the field? 530 00:37:57 --> 00:37:59 I don't even remember. 531 00:37:59 --> 00:38:03 So, here's what I do when I'm looking at my program and I 532 00:38:03 --> 00:38:06 want to see where something is. 533 00:38:06 --> 00:38:13 I use the text editor, and I'm going to search for it. 534 00:38:13 --> 00:38:24 Let's see. 535 00:38:24 --> 00:38:31 Well, it's not there. 536 00:38:31 --> 00:38:33 There it is. 537 00:38:33 --> 00:38:37 So here when I get my field, I get my drunk, and then I get a 538 00:38:37 --> 00:38:44 field which is an odd field. 539 00:38:44 --> 00:38:46 All right, anyone want to speculate what will happen 540 00:38:46 --> 00:38:54 when I run this one? 541 00:38:54 --> 00:38:57 Think the drunk will be closer or further from the 542 00:38:57 --> 00:39:00 origin when we're done? 543 00:39:00 --> 00:39:03 Who thinks closer? 544 00:39:03 --> 00:39:05 Who thinks further? 545 00:39:05 --> 00:39:07 Who thinks no difference? 546 00:39:07 --> 00:39:10 Well, you're right, I mean it's sort of logical if we think 547 00:39:10 --> 00:39:12 about it, that if every once in a while you get to zipped, back 548 00:39:12 --> 00:39:15 it's going to be harder to get further away. 549 00:39:15 --> 00:39:17 We'll see different behaviors, by the way, it depends 550 00:39:17 --> 00:39:19 on the drunk, right? 551 00:39:19 --> 00:39:23 That's true for the usual drunk, but maybe not for 552 00:39:23 --> 00:39:27 the east west drunk. 553 00:39:27 --> 00:39:29 We can see what happens. 554 00:39:29 --> 00:39:33 So let's try some. 555 00:39:33 --> 00:39:36 We'll do it for the usual drunk, which is the more 556 00:39:36 --> 00:39:58 interesting case to start with. 557 00:39:58 --> 00:40:01 So you'll see whereas before we were up just shy of 20 most of 558 00:40:01 --> 00:40:06 the time, here we don't get very much much, further. 559 00:40:06 --> 00:40:13 We do get steadily further, but at a lot slower pace. 560 00:40:13 --> 00:40:16 What do you think it means that, before you remember, we 561 00:40:16 --> 00:40:17 saw a pretty smooth line. 562 00:40:17 --> 00:40:21 Here we see what may look you like a fat line, but 563 00:40:21 --> 00:40:25 is in fact a line with a lot of wiggles in it. 564 00:40:25 --> 00:40:30 What does that imply, about what's going on in the 565 00:40:30 --> 00:40:35 simulation, the fact that line is jagged rather than 566 00:40:35 --> 00:40:41 smooth as it was before? 567 00:40:41 --> 00:40:43 Pardon? 568 00:40:43 --> 00:40:44 Can't hear you? 569 00:40:44 --> 00:40:44 STUDENT: 570 00:40:44 --> 00:40:44 That it jumps. 571 00:40:44 --> 00:40:50 PROFESSOR: Well, certainly it happens because of the jumps, 572 00:40:50 --> 00:40:51 but what else is going on? 573 00:40:51 --> 00:40:54 But what is it, sort of, imply more, whoa, sorry about 574 00:40:54 --> 00:40:57 that, more generally? 575 00:40:57 --> 00:41:01 Right, what it's saying, is that because of the jumps, 576 00:41:01 --> 00:41:07 there's a lot more variation from trial to trial. 577 00:41:07 --> 00:41:09 Not surprising, right, because you sometimes you hit 578 00:41:09 --> 00:41:12 these wormholes and sometimes you don't. 579 00:41:12 --> 00:41:15 So let's look at this other figure. 580 00:41:15 --> 00:41:18 This is kind of interesting. 581 00:41:18 --> 00:41:24 So here's the scatter plot. 582 00:41:24 --> 00:41:37 And if we zoom in on it, what we see here is, there are 583 00:41:37 --> 00:41:41 essentially holes, you know, these alleys where 584 00:41:41 --> 00:41:46 no points lie. 585 00:41:46 --> 00:41:50 Just as we might have guessed from here. 586 00:41:50 --> 00:41:53 The only way you would get a point lying on these alleys, if 587 00:41:53 --> 00:41:55 it happened to be the very last step of the simulation, not 588 00:41:55 --> 00:41:58 even then, because the last thing we do is go 589 00:41:58 --> 00:42:00 back to the origin. 590 00:42:00 --> 00:42:04 So we can look at this, and say, well, sure enough, this 591 00:42:04 --> 00:42:15 is keeping people off of a certain part of the field. 592 00:42:15 --> 00:42:20 All right, some of you will be happy to know we are, for the 593 00:42:20 --> 00:42:22 moment, actually maybe for the whole rest of the term, 594 00:42:22 --> 00:42:24 leaving the notion of drunks. 595 00:42:24 --> 00:42:26 Though not of random walks. 596 00:42:26 --> 00:42:30 All right, any questions about what's going on here? 597 00:42:30 --> 00:42:32 And again, I would urge you to sort of study the code and the 598 00:42:32 --> 00:42:35 way it's been factored to accomplish these things. 599 00:42:35 --> 00:42:38 And play with it, and look at what you get from 600 00:42:38 --> 00:42:40 the different plots. 601 00:42:40 --> 00:42:44 I now want to pull back from this specific example, and 602 00:42:44 --> 00:42:50 spend a few minutes talking about simulation in general. 603 00:42:50 --> 00:42:55 Computer simulation really grew hand in hand with the 604 00:42:55 --> 00:42:59 development of the computers, from the very beginning. 605 00:42:59 --> 00:43:02 The first large-scale deployment of computer 606 00:43:02 --> 00:43:15 simulation was as part of the Manhattan Project. 607 00:43:15 --> 00:43:19 This was done during the war to model the process 608 00:43:19 --> 00:43:29 of nuclear detonation. 609 00:43:29 --> 00:43:33 And, in fact, what they did was a simulation of 12 hard 610 00:43:33 --> 00:43:37 spheres, and what would happen when they would bump 611 00:43:37 --> 00:43:38 into each other. 612 00:43:38 --> 00:43:43 It was a huge step forward to do it with simulation, since 613 00:43:43 --> 00:43:46 the whole project had been stalled by their attempt 614 00:43:46 --> 00:43:48 to do this analytically. 615 00:43:48 --> 00:43:52 They were unable to actually solve the problem analytically. 616 00:43:52 --> 00:43:55 And it was only when they hit upon the notion of using a 617 00:43:55 --> 00:43:59 computer, a relatively new tool in those days, to simulate it, 618 00:43:59 --> 00:44:02 that they were able to get the answers they needed. 619 00:44:02 --> 00:44:05 And they did it using something called a 620 00:44:05 --> 00:44:19 Monte Carlo simulation. 621 00:44:19 --> 00:44:22 Now in fact, that's just what we've been doing with the 622 00:44:22 --> 00:44:24 random walk, the Monte Carlo simulation, and I'll come 623 00:44:24 --> 00:44:27 back to that in a minute. 624 00:44:27 --> 00:44:32 In general, the thing to think about, is we use simulation 625 00:44:32 --> 00:44:39 when we really can't get a closed form analytic solution. 626 00:44:39 --> 00:44:42 If you can put down a system of equations and easily solve 627 00:44:42 --> 00:44:47 it to get an answer, that's usually the right thing to do. 628 00:44:47 --> 00:44:50 But when we can't easily do that, the right thing to do 629 00:44:50 --> 00:44:54 is typically to fall back on simulation. 630 00:44:54 --> 00:44:57 Sometimes even when we can do it analytically, simulation 631 00:44:57 --> 00:45:05 has some advantages, as we'll be seeing as we go forward. 632 00:45:05 --> 00:45:16 What we're typically doing when we're simulating anything, is 633 00:45:16 --> 00:45:35 we're attempting to generate a sample of representative 634 00:45:35 --> 00:45:43 scenarios. 635 00:45:43 --> 00:45:47 Because an exhaustive enumeration of all possible 636 00:45:47 --> 00:45:50 states would be impossible. 637 00:45:50 --> 00:45:53 So again, if sometimes you can't solve it analytically, 638 00:45:53 --> 00:45:56 you can exhaustively enumerate the space and 639 00:45:56 --> 00:45:59 then see what's going on. 640 00:45:59 --> 00:46:01 But again, usually you can't. 641 00:46:01 --> 00:46:04 And so we look for a sample, and the key is, it's 642 00:46:04 --> 00:46:07 gotta be representative. 643 00:46:07 --> 00:46:11 Of what we would get in reality. 644 00:46:11 --> 00:46:14 We'll see an example of that shortly. 645 00:46:14 --> 00:46:20 So simulation attempts to build an experimental device that 646 00:46:20 --> 00:46:25 will act like the real system in important aspects. 647 00:46:25 --> 00:46:29 So I always think of a simulation as an 648 00:46:29 --> 00:46:32 experimental device. 649 00:46:32 --> 00:46:37 And every time I run it, I'm running an experiment designed 650 00:46:37 --> 00:46:41 to give me some information about the real world. 651 00:46:41 --> 00:46:44 These things are enormously popular, so if you were 652 00:46:44 --> 00:46:52 to get on Google and look at simulation. 653 00:46:52 --> 00:47:00 So for, example, we could Google simulation finance. 654 00:47:00 --> 00:47:06 You know, we see we get about 3,000,000 hits. 655 00:47:06 --> 00:47:13 We can do biology. 656 00:47:13 --> 00:47:16 We get twice as many hits, showing the relative 657 00:47:16 --> 00:47:21 importance in the world of biology and finance. 658 00:47:21 --> 00:47:25 For all you Course 7 majors, we should make sure that should 659 00:47:25 --> 00:47:27 compare biology to physics. 660 00:47:27 --> 00:47:31 Oh dear, we'll see that physics is even more important 661 00:47:31 --> 00:47:35 than biology. 662 00:47:35 --> 00:47:38 And I know we have a lot of Course 2 students in here, 663 00:47:38 --> 00:47:43 so let's try mechanical. 664 00:47:43 --> 00:47:45 Oh, lot of those, too. 665 00:47:45 --> 00:47:48 And if I did baseball, or football, we'd get 666 00:47:48 --> 00:47:50 more than any of them. 667 00:47:50 --> 00:47:54 Showing the real importance of things in the world. 668 00:47:54 --> 00:48:00 As we look at simulations, I want you to keep in mind that 669 00:48:00 --> 00:48:12 they are typically descriptive not prescriptive. 670 00:48:12 --> 00:48:18 So by that I mean, they describe a situation, 671 00:48:18 --> 00:48:22 they don't tell you what the answer is. 672 00:48:22 --> 00:48:28 So another way to think about this is, a simulation is not 673 00:48:28 --> 00:48:31 an optimization procedure. 674 00:48:31 --> 00:48:35 When we looked at optimization, that was prescriptive. 675 00:48:35 --> 00:48:41 We ran an optimization algorithm, and it gave us 676 00:48:41 --> 00:48:45 the best possible solution. 677 00:48:45 --> 00:48:48 A simulation typically doesn't give you this best possible 678 00:48:48 --> 00:48:52 solution, but if you give it the starting point, 679 00:48:52 --> 00:48:58 it will tell you the consequences of that. 680 00:48:58 --> 00:49:01 Now, can we use simulation to do optimization? 681 00:49:01 --> 00:49:03 Absolutely. 682 00:49:03 --> 00:49:07 For example, we can use it to do guess and check. 683 00:49:07 --> 00:49:10 Where we guess a, probably not to get a truly optimal 684 00:49:10 --> 00:49:15 solution, but to get a good solution, we can guess various 685 00:49:15 --> 00:49:18 possibilities, simulate them, and see. 686 00:49:18 --> 00:49:21 People do that all the time. 687 00:49:21 --> 00:49:27 If they want to see what's the right number of checkout 688 00:49:27 --> 00:49:30 counters at the supermarket, or what's the right airline 689 00:49:30 --> 00:49:32 schedule to use? 690 00:49:32 --> 00:49:35 They'll make a guess, they'll simulate it, and they'll say 691 00:49:35 --> 00:49:39 all right, this was better than this, so we'll choose it. 692 00:49:39 --> 00:49:42 All right, I'm going to stop here. 693 00:49:42 --> 00:49:45 Next time we're going to get more deeply into the actual 694 00:49:45 --> 00:49:49 stochastics, the probability distributions, and start 695 00:49:49 --> 00:49:52 understanding what's going on under the covers. 696 00:49:52 --> 00:49:52