 Okay, so you all heard that, right? Yes. Or not? You heard recording in progress? Yes. Okay, good. So if you speak or if you make yourself visible, it's on you. But good, at least I won't be the only one. Okay, so the notion here is to put randomness into our simulations. And we already know a lot about this just from the homework you've been doing. Why do we want randomness in our simulations for, because there's complexity in the world. Things aren't constants in the real world, and so they shouldn't be constants in our simulation. But if we know, that's a different question, but if we know the distribution that our data or input data follows, that's great. Then we can sample from it from this distribution. Not for this class, but maybe next week or the week after we'll be looking at how do we know what the distribution is how do we know that our for example that are into arrival times are exponential. Okay, it's a different question. Right now all we know is we need randomness. You saw that when you, for those of you, well, even when you did the uniform distribution. And for those of you who did your the Excel using the exponential distribution. It was all based on random the random number generator and Rand, which gave you a random number between zero and one from not mistaken. So that's the first thing and that's what this lecture really is all about. It's about the base randomness, not about generating various from a particular distribution. We could, although we don't. We could use real randomness in our simulation right if you if you haven't thought about it, you could think about it now. We could use and is in fact the the checkout stand started out that way, where we were using something that was really random, tossing a die chips in a hat, labeled one to 10. And you can see there are other other ideas a roulette wheel. Generally speaking, when you have a truly random number. There are some real physical process that generates the randomness radioactive decay bumping electrons off of a wall, or towards a wall. That sounds as often measuring the distance from the center from from an edge. Something that results in randomness, and that can be measured. That's sounds extremely messy and extremely expensive. So you can understand we don't do that. However, we might do that to generate random numbers right. If you haven't you can look at look it up when you get you get home or you are home probably, when you get to a book in either probability or statistics at the back of the book there'll be a random numbers table. You probably used it before and your undergraduate studies. What, what were these, where did these random numbers come from. Well, we know where they came from they came from the Rand Corporation, which actually used an electronic simulation of a roulette wheel for the randomness true to randomness attached to a computer to generate the measurements, the values. That wasn't good enough, even though it was truly random. So they had to also test it. And perhaps there was some filtering going on to make sure that extreme values, let's say, you know weren't left in certain parameters that they needed to match your book of random numbers comes from or the table of random numbers at the back of your book comes from a book that was put out in 1955 by Rand with those random numbers and in addition, between and you know the late 1940s and on the Rand Corporation made these random numbers available to people on a magnetic tape. So that, you know, you don't have to actually key in the values from the random number table. And what you see there on the screen is just a clip. A piece of the random number table. And it's in its grouped in in units of five digits. And it looks two dimensional, but it's not two dimensional. It's just a one long stream of random digits. So if you look at the top left it starts with seven, seven, three, seven, three, five, four, five, nine, six, three and so on, across the across the row and then in major row order. And all that was was a convenient way of arranging one long stream of random digits. We don't have anything to do with each other it doesn't matter it doesn't matter that they're in groups of five, or that this looks like it's in two dimensions none of that is none of that is important. It's just a stream of random digits. So, we could use true randomness. These digits are truly random, we could still get access to it on an electronic, an electronic form. We could still get a file with it. Think about why we don't. And I'm not asking people to contribute because we're recording, and I know people may not wish to, but please do feel free if you don't mind to just unmute yourself anytime and jump in, either answer questions or ask your own. But if we have a file of random numbers or in this case random digits. How do we access it for our simulation program. We would have to read a digit from the file. Maybe we'd have to read a sequence of 10 digits from the file if that's what we need. And then go to the simulation, discard it, and then go to the next one and read another number and use it in the simulation. And you may not realize this, but reading from an external file is extremely expensive it takes a long time. It takes a lot of computer time. It's the the probably the most expensive thing that you could be doing in the context of, if you're paying for computer time for example. It's very inefficient use of your time. So it we could do it, but now let's move on to look at something that might be almost as good, and sometimes maybe even better. What we actually use are not random numbers, even though the function in Excel is called Rand. They're really pseudo random numbers and if you look at the diagram on the slide. That's exactly what a pseudo random number generator does. It outputs a random number and then uses that random number as input in order to generate the next number and the next number and the next number. So there's a stream of random numbers, each one generating the next. And naturally, it's booted up externally before you get into that loop by a single random number that's used once. And that's called the seed. SEED that should probably be, I should probably put that in the slide shouldn't I. So that random number that's used once as input to the pseudo random number generator is the seed, which then produces the entire stream of random numbers that comes after it. It's nice to know because if we ever want to duplicate what we've done before. What we have to do is use the same seat, and it will produce the same stream of random numbers every single time. And if we don't want to duplicate what we did before but we want we want true randomness. We just start with a different seat, which has its own issues, of course, as we know. Not only are truly random numbers inefficient and more expensive to use, especially when we're talking about computer time, even many simulation programs are, you know, take a very long time. Some of them even have to be run on a supercomputer. However, they're still doable. In addition to that reason, pseudo random numbers are better. Because, well, it's faster, which not only means that I don't have to pay for that lengthy computer time but it's faster. I don't have to wait such a long time for my computer program to run in the programs we've been doing that's not an issue. But but in other cases it is. But even more, probably the best reason for using pseudo random numbers is because I can actually not to replicate I can duplicate what I've done before. If I have the same model and the same random numbers, I will get exactly the same thing that I got before. So you're going to say why would I want that. Why would I want to get the same thing I got before. And there are cases when you would want that suppose I'm planning to renovate my hospital emergency room. Wouldn't it be nice if I could take the customers I had yesterday, do the renovation, and then run the same customers with the same illnesses through the emergency room tomorrow, after the renovation, and look at the differences. I could do that by by this, this feature of reproducibility. If I use a pseudo random number generator, as opposed to truly random numbers. Certainly, if I use a pseudo random number generator as opposed to just experimenting in the real world. Truthfully with truly random numbers as long as I have saved them in some format, I can reuse them. Sure. A disadvantage of pseudo random numbers, and especially a disadvantage if we want to keep on using a different seed. To not have the same, the same entities moving through the system at the same rate and at the same time, each time. Every pseudo random number generator has what's called periodicity. There is a finite period during which every random number generates another new random number but after a while, it's goes back it cycles back to the beginning. And you have the very same stream of random numbers from that point. Obviously, clearly, that's a problem, especially if you don't know what's going on. All right, so everyone wants to see what a pseudo random number generator looks like. Here's one. It's a simple one and as you can see it's also an old one. It's presumably not what we're using in our calculators in programs in Excel, because there are better more efficient ones. But the nice thing about this is it's simple to do by hand and it's simple to understand. Okay, let's see how it works. It's called middle square. We start with, as always, we start with a random number of a certain number of digits. In this case, we're looking for an end of is even so, you know, whatever it is, whatever you decide on that you you figure out what your seed will be. Some random number you can even start with a sequence of random digits and even number of them from the random number table. Take the random number do some arithmetic to it. That's what all of these random number generators do. They take the random number do some arithmetic to it and output spit out the next random number in the sequence. In this case, what are we doing we're squaring it. We're adding zeros to the left which we know is doable and doesn't change the value. Now we're going to form a sequence we add enough digits to form a sequence of two and digits. So if we have, let's go to the example. If we have 1111 as hard as a wonderful seed right we have 1111 as our as our first random number. We square it. Get 1234321. That's seven. Zero on on the left, which doesn't change things but makes it an eight digit number. And the center is 2343. We take the, the middle four digits to create the new random number of four digits. Okay, and the more digits you use obviously the better you'll be especially if you're doing this for cryptography. This is one that's probably not going to be used because the the periodicity is very small it starts to repeat very quickly. Why couldn't you preview my file. See if I get it now. Yeah. Okay good. What should a good pseudo random number generator have since this is pretty much common sense. I think you could figure all of these out on your own. But let's take a look let's go down the list. They should be random. Of course they're not going to be random. How do we know that pseudo random numbers are not random. How, how, how do we know they're not random. Well, if I give you a pseudo random number. I'm going to the generator. I can predict what the output will be. That's the very definition of relatedness of, of not being random. If you can predict what your random number will be clearly it's not random if you can compute a random number using a bunch of arithmetic. Clearly it's not random. So our pseudo random numbers aren't really random. That's why they're called pseudo random. They behave like random numbers. I see a chat flashing. Is that okay. And if any problem with that. Oh, okay. All right. I should learn my lesson. If you see something in the chat, somebody check to see if it's important. And give me Morse code or you could even send me an email I have my phone right here. If you don't want to speak. Okay. Basically pseudo random numbers appear random. They act random. Clearly they should be reproducible because one of the things we liked is the fact that as long as we have the seed. We can produce the same stream of random numbers each and every time every single time. That's not only something we like it's critical because there's no point in using pseudo random numbers otherwise over truly random numbers it's a huge advantage. We want the algorithm to be fast we want it to work quickly we don't want to have to wait to get the random numbers as you know from working with Excel. Once things get a little bit complicated. Even a few seconds of a delay when things are recomputing a noise us. We want to make efficient use of computer resources so it's not only time. It's also space in other words how much storage spaces use where the storage is. Whenever we say efficient in relation to computer resources we're talking about issues of time and space. We want to make sure that even though we know there will always be cycling there will be periodicity. We want to make sure that the algorithm we use has a long period. It doesn't cycle too soon because it's pretty much useless if it does. And we want to make sure that not only do we want numbers to be random but we don't we want them to be distinct we don't want to get the same number over and over again. That if that happens that means the whole thing just degenerated. How can we test random numbers. I think that the matter is that pseudo random numbers are tested when when when when someone, let's say we tests a pseudo random number generator for goodness to see how good it is. They're going to be it's going to be tested to see if the numbers are quote unquote random which basically means do they act like random numbers. We know they're not random, but we want to know if they act like random numbers. These the pseudo random number generators do test well. They act like random numbers for the most part is a little bit of an issue with Excel, at least in the 2010 edition. The interesting thing is that if you do higher level testing, which, of course, we're not doing in this course, but if you ever find yourself in a situation where you are doing higher level testing and by higher level. I mean multi multidimensional hyperplane testing. So in other words when we test the stream of random digits or a stream of random numbers. We're testing something linear. Right. But if you take these numbers and look at them in a hyperplane very often patterns emerge. And the people who the mathematicians who study this have basically said, there's no such thing as a truly random pseudo random number generator. In a way is what we're looking for is good enough we're looking for it to be good enough random enough. If it passes the tests of randomness, we're happy, then we're good. Okay. So, even though, so I'm going to move on to the next lecture on generating random variants. This one does happen to have a narration, but I'll continue recording and then at some point when we all get when we feel we've had enough I'm not going to do the whole thing. I'll stop and I'll pause the recording or I'll close the recording. And then we can move on to other things. Professor I'm the one that message you I just have to leave like around like five or 10 minutes. I won't even I won't even notice. Don't you like hearing that I won't even notice you're gone. But thank you. Thank you for letting me know. Okay, people are so polite. I'm really I've been teaching undergraduates and I'm really not used to it. But thank you. Okay. To some degree we're trying to straighten out terminology. And quite frankly, I don't think that's what we should be doing in the lecture. It's not not that important and it's also not going to directly affect what you're doing in the homework. So I will just say, in general, when we sample from a distribution, we will often maybe even usually call it Monte Carlo sampling or Monte Carlo methods. And we were generating the inter arrival times in Excel for 20 or 50 or 100 customers. That was a Monte Carlo method. So whenever we're sampling values from a distribution, a particular distribution, getting random variants that can be called Monte Carlo sampling. Some people will consider it simulation. I think simulation should have a time element. And Monte Carlo simulation is just a numerical analysis. It doesn't have a time element. It's a static sampling, right. All right, the, it's interesting to note that Monte Carlo methods go back to. Well, the technique goes back to the 18th century. But it wasn't called Monte Carlo then the name Monte Carlo goes back to the Manhattan project in which many physicists from different countries got together to create that thing called the atom bomb. And naturally it was, it was a big secret, which was why it was called the Manhattan project and not the atom bomb project. And anything connected to it was kept secret. And so the, the code name Monte Carlo was used for the method of sampling for this methodology. All right, this you can read on your own. I'm not going to read, you know, reading slides is boring. And again, it's not relevant to what we're doing right now with our homeworks, but you should you should do it on your own. Okay, when do we use Monte Carlo. Sometimes there were other reasons okay one thing that I said earlier is that we want to sample variants from a particular distribution. Sometimes we want to compute things that are best computed with numerical methods, iteratively like the value of pie. Or like repeatedly sampling from a distribution where the mean is, is either too difficult or impossible to compute using expectation. And, and we get the mean, pretty much empirically that way in kind of weird to call it empirically but yeah it is. Okay. So here's how Monte Carlo methods work in general, not all the same obviously. So we have a random number somehow generated by some method like getting getting it from a magnetic tape, a table of random numbers, a roulette wheel, a computer program like a pseudo random number generator. Somehow we need a source, we need a source of random numbers or pseudo random numbers. We also need the cumulative probability distribution, and I'll show you why on the next slide. See that little picture. If you've never seen a cumulative distribution you probably should go back and look one up. Let me just use my pen. Okay. So, if just to just to draw a very common distribution, the normal, right. The normal distribution goes to plus infinity on one side negative infinity on the other side. Here's the mean. The mean is equal to the media and is equal to the mode. The cumulative distribution comes from taking our probabilities for as we go along the x axis and accumulating them. By the time we get to the very last place where we could be. It's 100% of the distribution, wherever that is. And we start out with zero the distribution. Take a look at what happens we keep increasing and increasing and increasing which is very much like what you see down here. And then we not only are increasing but we're jumping. In the middle, where we have the most concentration of the frequencies or the proportion of the data in our distribution. All of a sudden there's a jump, and then it peters out again. As we go to the other side the values on the higher side. So this S shaped curve is very typical of a cumulative probability distribution for a symmetric distribution, where the mean is equal to the median is equal to the mode. And that's practically the definition, but certainly one of the properties of the normal distribution. Okay, so why do we want it's, why do Monte Carlo methods depend on having a cumulative probability distribution well look at this. We have a number between zero and one. Isn't that great. And our random numbers come to us as numbers between zero and one. The median at the 50% mark is point five, the probability the cumulative probability is point five. Suppose we want to know what that corresponds to in our original data. We can horizontally go till we hit the curve at point five, and then drop down. And hopefully if it's a normal distribution or some other very symmetric distribution will be at the mean. But whatever x value that is it's it's corresponds to the 50% market in the cumulative probability distribution. So it's very useful to be able to look at a distribution not in terms of the the x not in terms of the relative frequency of any particular value or group of values, but in terms of the cumulative frequency or the cumulative probability. So how do we, how do we do this. Okay. We get the probability distribution we get a random number between zero and one. We get it randomly so randomly will find a number between zero and one. We project horizontally, we drop down vertically, and we sample our x variable. That's how we would do it graphically, of course as we probably could figure out we don't want to do it graphically. So many reasons, the not the least of which is the fact that it's very hard to get a very fine tuned value of x. You know we should be able to get something like 3.5 or 3.67 but to get 3.63241 would be difficult. Okay. So this is the, an algorithm instead of a graphical approach. And this is the algorithm that you've, you've used, you found it, you either found it here, or you found it on Google or you found it. Well, that's probably it. And it's called the inverse transform methods. And it's exactly the same as getting a number between zero and one a random number, hanging a horizontal hanging a vertical and finding that value of x. It's exactly the same as the graphical approach. I just want to make a point. This is cumulative distribution that's more for symmetric distributions like the normal. And this is probably closer to an exponential. Anyway. Oh, here, yeah, the formula for the cumulative exponential distribution. Okay. So if we want to use the inverse, inverse transform to get to generate random numbers from an exponential distribution, which is the same by the way as what we would use for a Poisson only in the inverse. Okay, f of x. That's our function that gives us the cumulative probability distribution. The cumulative probability distribution for an exponential is one minus e to the negative lambda x where lambda is the parameter. If we add one to both sides. We haven't really changed anything have way, because what f of x and one minus f of x are both numbers between zero and one. Now all we do is replace one minus f of x with we're getting a random number from a pseudo random number generator, and we want to generate a random number that's between zero and one that's what that ran means. And what we're left with on the right side is e to the minus lambda x. Remember all of this is going towards solving for x. Well, if we take the natural log of both sides, the natural log of the random number on the one side, the natural log of e to the etc, the natural log on the cancel. And we'll end up with negative lambda times x on the right. And if we want x. So we take negative lambda and divide the right side and the left side by negative lambda, and we end up low and behold with what you've, what you saw our two presenters using in Excel. So negative one over lambda times the log of the random number between zero and one. And just, you know, writing it more neatly here, but it doesn't really matter how you write it. All right, this is what we were talking about earlier I said this in response to a question during one of the presentations. And so it's just a repeat. The Poisson and the exponential are inverse of each other. If you want to prove it to yourself just make sure you keep track of the units. Okay. The exponential distribution is in times in terms of time. And you generally are talking about time per entity, like into arrival time between successive entity service time per entity. The Poisson is actually because I was an interesting distribution it's considered a discrete distribution, but it's this it's a discrete distribution. It's a distribution of a discrete random variable that's inside of a continuous interval, which is the only one that I can think of that's like that it's very unusual. So the Poisson distribution would govern let's say, number of defects in a square yard of material. And in this case, what we're looking at our rates. Number of customers per time interval that's a rate. And that could be the rate of service or the rate of arrival. Number of entities per time unit. If you turn it around time unit per number of entities then you have an exponential. Okay. Again, I'm assuming that if you have questions or if you want me to go through something a little slower, you will let me know somehow. I'm going to do a couple of more slides. We already did the part that was relevant to the homework. I just want to show you that there are other distributions and there's other things we could be doing but the process is usually the same not always but usually. Suppose we have a different discrete probability distribution we looked at the Poisson. I mean you could do it with I suppose with binomial to we haven't. Here's a general probability distribution where it's just enumerated. There's no formula. Okay, and we've seen problems like this and you've seen problems like this in other classes I'm sure. In this case, this is the distribution of customers that are arriving in 10 minute intervals the number of customers to arrive the probability of the particular values of customers arriving in a particular time interval 10 minute interval. So, in any 10 minute interval, we can expect zero customers arriving with probability 40. We expect one customer to arrive with probability 25 two customers would arrive with probability 20 and three customers with probability 15 the cumulative probability you just accumulate. Okay, the probability of zero customers arriving is point four, the probability of zero or one is point four plus point two five or point six five. The probability of zero or one or two is point eight five and the probability of zero one two three well that's got to be 100% because there's nothing else left. And if we graph the cumulative probability distribution. It would look like this graph. Thankfully, I learned to do this in Excel by by this point so it's a little bit less ugly than the others. And so here's a simulation, suppose our first five random numbers came out this number between zero and one remember point oh nine point five four point four to point 80 point 20. Okay. Well, for the point oh nine. There's nothing before. Point four. Anything in any random number between zero and point four is going to be zero on the x axis, right. So you can take each, each one of these random numbers. Find where it is on the y axis. And then go horizontally until you reach. The value you're looking for and then hang a vertical down, and you get the value. So doing this using the graphical approach of course you don't have to use the graphical approach we could use an algorithm to for these five random numbers you get zero one one two zero customers in 50 minutes. There are other ways of doing it, obviously, but this is a simple way and it's using the same principle as we used with the exponential. Now here's something a little different. What if we want to sample from a normal distribution. We know what and here you see this is the same one as before the famous S curve. We know what the cumulative distribution looks like for the normal. And we know what the formula is. And we really don't want to solve for X. It's, it's a it's kind of thing that would give us nightmares probably it could be done, or maybe not. I don't know. I have it's been a long time since I had calculus. At any rate there are approximations which which I'm not going to go into now. That's again it's not relevant but you should look at look at it. There are approximations that are based on sums. You know that the central limit theorem is based on the notion of averages which is basically the same as sums that says that no matter what the underlying distribution is, if you keep repeatedly sampling from it. It's going to end up at some point looking a lot like a normal distribution. This is an example of a uniform distribution, the distribution of a die that after several tosses ends up looking like a triangular distribution. And if you keep on going you'll end up with something very much like a normal distribution. Okay, so that's just the theory behind it. You know perhaps we'll come back to this one day in the class perhaps not. There is a method by which to use this for, it's kind of cool. Okay, but we're probably not going to need it. If we do make sure you let me know if you need it for some something that you're doing, make sure to let me know and then I'll go back. We'll go over it in class. Maybe I'll use a marker board. Okay. Oh, this is still. Oh, this it ends up being, you know, this is just simplifying the algorithm it ends up being not too bad. If you don't have to worry about why you're doing it. Okay, I'm going to stop the recording now just in case people want to contribute. If I could figure out where it is.