Skip to main content
Loading Explore guides…
Monte Carlo Simulation Intro · Acedra
Home
Explore
Mathematics
Monte Carlo Simulation Intro
Sign in to save
Chat
If YouTube asks you to sign in, open the video on YouTube.
Watch on YouTube
Reload player
Transcript
44 segments
Copy
Hide video
0:18
Welcome to the lecture on Introduction to Monte Carlo simulation. So, we have discussed about many techniques of simulation in this course. And now we will discuss about one of the very important technique that is known as Monte Carlo simulation. So, this simulation normally is used when the simulation through other approaches is becoming very very complex very difficult. And in this what we do is we use the random numbers to basically model the process.
1:00
So, Monte Carlo technique it deals with taking random samples from distribution of a variable in order to supply a series of values for use in the model. As we discussed that in this we have to take the random numbers and these random numbers will be assigned basically, there are methods depending upon the probability distribution or depending upon the chances, which have been told to you or which is basically clear in the question.
1:36
So, based on that you assign those values against certain random numbers and this random numbers are basically uniformly distributed. So, you can have the generation of this uniformly distributed random numbers, between some quantities like between suppose 1 to 100, 0 to 99 or you can have 0 to 1. So, we have the studied the algorithm or the methods of generating these random numbers in the chapter random number generation.
2:12
So, in that random number generation we studied the methods like linear congruential generation, we studied the method that is mixed congruential generator then also we studied about the method that was random variate generation; so where we had to generate this random numbers according to certain distribution function. So, we use the cumulative distribution function for certain typical distribution function and then by using the inverse transform we are generating the random variates.
2:49
So, these random variates are there random numbers are there and these random numbers are picked up I mean anyway they are generated then they are basically uniformly generated. So, the probability of any random number into that domain is equal. So, then they are used and then they are further used for predicting the system performance. So, they are stochastic and they are simple to implement and it is often used to solve stochastic problems to mimic randomness of physical behavior.
3:31
So, just you can have the understanding what is random like random walk by a drunkard person, who can put his foot any at any place and he can go in any direction. So, that is like the example of randomness. We can even solve some deterministic problems by using the probability for estimation. So, this Monte Carlo method can be used for that purpose we will have an example and we will see that how we can find the value of certain quantity, which is determined and
4:11
how can we find by the random means Monte Carlo method. So, what we need to go ahead to know about the Monte Carlo simulation or stochastic simulation. So, you should have the knowledge of relevant probability distribution. So, that you can generate the random numbers if required for particular distribution, you should have the idea that how this distribution behaves. If you have to predict any quantity then how to predict it how with what kind of distribution it will be matching.
4:53
So, that basically you must know that. So, you must have the information about theoretical I mean distribution or empirical distribution and about the system for which you are going to study. Now supply of random of random numbers of making random choices. So, what there are many methods and you can simulate large number of trials and probability. So, that way the accuracy will be more and more. So, as we do more and more number of iterations in that, we are coming closer to the actual value.
5:40
So, we can see how this random number works what happens in that. Now let us see; what is the process in that. So, many a times you come across the probability of occurrences. Suppose you are dealing with the lead time or you are dealing with the arrival time number of arrival. Suppose is there is approximated and you are told that either there will be 3 4 5 or 6 number of arrivals will be there in this particular time.
6:24
So, in a suppose 5 minute of interval, it was seen that either there will be 3 number of arrivals either 4 either 5 or 6 numbers of arrival will be there and it is said that it has the probability of suppose 15 percent, it has the probability of 30 percent it has the probability of 20 percent and this has again the probability of 35 percent suppose. So, this is told to you. So, it is 35 plus 20. So, it will be 45 plus 20, 65 and 35; 100 percent.
7:01
Now, if they are telling that suppose this is the arrival rate in it in suppose in 5 minutes, and this is the probability. Now if suppose you have to see you have to do the random sampling and then there is arrival of the customer simply you have the service rate. So, simply service also if the service is done, service rate is there, in again 5 minutes and if it is seen that there are 4 services done, there are 5 services done, and 6 services
7:43
done and they have the probability of say this is 30 percent, this is 40 percent and this is 30 percent. So, what we do is that because they are not following any typical distribution. So, we know that after looking at the data we came to this conclusion we have concluded that out of these 4, these are the respective probabilities. Now how to get the help from the random numbers. So, what we do here in this that normally the process is that you have the frequency. So, you will have the number.
8:29
So, whatever is there arrival rate, item is there basically, this is not the number this is suppose whatever item is there whatever quantity you are going to you know predict and its frequency. So, as we know that if it is you know arrival rate. So, arrival rate we know that you have 3, 4, 5 and 6, now in this as we know the frequency is 15, 30, 20 and 35. So, what we do is we find the cumulative frequency. So, once we find the cumulative frequency.
9:17
So, cumulative frequency will be here it is 15, this will be 45, this will be 65 and this will be 100. So, ultimately the cumulative frequency comes here because this is total is 100. So, you are matching it, now you have if you have the uniformly distributed random numbers between 0 to 100. So, excluding 100 because we will take the 2 digit number suppose. So, for a 2 digit number; 2 digit random number we have to assign.
9:58
So, what we do here is, as we know this is the uniformly distributed random number. So, the probability of the picking of any number is same. Now, what we see that if we are having this 3, it must have 15 percent of the probability. So, basically if you start the number with 00. So, upto 14 it will go. So, we randomly pick any number and if that number will be from 00 to from 14 then we will assume that this time we have to take the arrival rate as 3.
10:48
So, basically that arrival rate will define the inter arrival time basically. So, from here you will find the inter arrival time. So, let us see for this we have done. So, anyway if this is there are then we can have inter arrival time. So, basically we are going to estimate the inter arrival time from this, now in that case you are assigning from this 00 to 14. So, similarly the next 30 numbers; so the first 15 numbers is assigned for this item arrival rate that is 3, then the next 30 numbers.
11:29
So, it will start from 15 and it will go up to 44. So, these numbers will be basically assigned to this one this entity 4. So, in the same way it will start from 45 to next 20 number; 64 and then 65 to 99; so this including 65. So, it becomes 35 quantity. So, this way when you have a stream of numbers; so when you generate the stream of numbers random numbers from 1 to 100. So, once you generate the random numbers may be that first turn you will get 78, then you
12:30
may get 47, then you may get 13, then you may get 87, then you may get 88 or 89, then you may get here 05 or like that. So, this way you can have the random numbers uniformly distributed random numbers generation. Then what will happen? You will start from here you will take 78. So, in the first iteration if you take the first number as 78, this 78 we will see that it comes where. So, it is falling in this. So, in the first case the inter arrival rate time will be suppose 78.
13:07
So, that is why you will take it as the 6 minute is have been 6 is the arrival rate, 6 whatever quantity it is here. So, that 6 accordingly correspondingly whatever coming is the inter arrival time that you can find. So, similarly next will be 47. So, 47 comes here that will be 5, then 13, 13 will be coming here is 3. So, like that. So, every time we move from one time to other, iteration to other this numbers will be taken
13:40
in a sequence manner and these numbers are basically uniformly distributed, uniformly distributed means if this numbers are plotted against each other. So, if you have these numbers and then you generate another random number and then you plot them, then you will see that they are uniformly distributed in the domain; so 0 to 100 on the x, and 0 to 100 on the y. So, you will have the uniform distribution of the number in the whole rectangular domain or square domain of 0 to 100 and 0 to 100 here.
14:15
So, similarly if suppose here it is 4 is 30 percent, 5 is 40 percent, and then 6 is service rate is that is 30 percent, service time basically it will be. So, if the service time is 4 minutes or 5 minutes or 6 minutes in that case. So, that will be 00 to 29 will be required for this case. So, that if that number comes that will be basically for this 4, similarly you have from 30 to 69 will be for 5 and again 70 to 99 will be for 6.
14:52
So, this way we assign these random numbers and we try to get I mean every time whenever we require the values of those parameters, whose outcome is not known about whom we have to have the you know chance we have to know that what will be the next then taking the random number sample from that generated sample you can have it. Now you can have the generated number also or variate from a particular distribution
15:28
also and otherwise in normal excel software of Microsoft, you have the random function. So, you simply have the random rand function, it will give you the uniformly distributed number. So, you can generate any random number uniformly distributed between 2 domains. So, we will try to see that how can we. So, let us we will discuss that how can we calculate certain deterministic quantity like suppose we have to compute the value of phi.
16:05
So, suppose we have to compute the value of phi by random number. So, what we see is that, you see you know that there is a circle and if its diameter is one or if its radius is one then the radius the area of the circle will be phi. So, if we know or if the this value if diameter of this circle is 2; so if we draw it between plus 1 and minus 1 here and if we draw from minus 1 to plus 1 in this. So, in this case you have 2 things you will be getting one square as well as one circle.
17:01
So, square has the area 4 units whereas, the circle will have the areas which has basically phi units Now, the thing is that when we take any point in this, when we randomly select any point either it will be in this area or it will be outside this area. So, if we do this repetition we will see that if we do ten times we may have 7 times here and 3 times outside. So, 7 times basically. So, we can say that the probability of this is 0.7. So, whole area may be 0.7 into 4, 2.8.
17:49
So, 2.8 is the value of phi, but that is very you know approximate. But if you do this for 1000 number of times, for suppose 10000 number of times as you go on increasing taking the point in this domain in the whole domain if you take the point, in the whole domain and you take 10000 number of times or 20000 number of times as you go on increasing the chances of going closer to phi will be more and more. So, that we can see how we can do on excel this program.
18:28
So, let us see how we can do it on excel. Now, on the excel basically we can have a new excel file and as I discussed that we can have the generation of random number at any place. So, let us first of all have the numbering 1 2 and then we can extend it to any number. So, let us say go to 500 or 600 or may be 1000 we can go for the time being. So, we have gone up to 1000, now what happens that in this now here we can generate any random number and for that the command is that you generate.
19:34
So, if you generate any random number between. So, normally any command “rand” and then you put this command and if you put it. So, it will tell you a random number between 0 and 1 and if you further extend it this will go and tell you the random number between 0 and 1. So, let us do it may be up to only 500 because it takes lot of time. So, you can. So, up to 500 if you look at these are the every value is between 0 and 1. So, even that can be used.
20:13
Now, let us say if you have to suppose use the random numbers. So, in this case you have to use the random number between minus 1 and 1. So, what you can do is you can have the random number that is equal to 1 minus 2 times random number. So, 2 into rand function. So, if we put that you see that it is this value which will be coming now you see this numbers are normally coming which are between minus1 to plus 1 and they are uniformly distributed. So, this way you will have these numbers.
21:10
So, this way you can have it. Now, the thing is that you have to have another stream of random number every time you generate the random number it will be different. So, can simply copy it and you see that once you copy it will be coming like this and then further you can, you can pull it and come to 500. So, you are getting the 2 stream of random numbers between minus 1 to plus 1, we can see its uniformity. But, before that we will first try to copy it because it will be taking every time you
22:02
do the random number operation it will be basically changing, because of the random number random nature it will be changing every time. So, if we copy it and if we paste it as a number then it will not change ever, otherwise because of the randomness associated every time it is going to change. So, now, it will not change, you see that every time this is going to whatever we will do, but now this number will not change.
22:33
Now, these are the numbers from minus 1 to plus 1 which has basically been generated between minus 1 and plus 1 and they are uniformly distributed and you can see how uniform they are by plotting against each other. So, if you plot them. So, you have insert and then you can have this scatter. So, if you scatter and you see the scatter you just see this, now this is basically you just see this is a uniform distribution you can see that these numbers are basically between minus 1 to plus 1.
23:18
So, this is 0 you have one this side minus 1 and plus 1 this side, similarly minus 1 and plus 1 this side and you have uniform distribution of numbers. This is only up to 500 if we do up to 10000 then you will have quite good density of numbers, but otherwise they look uniform mostly. Now, the thing is that in this we have now to see that how to see the how to draw a number which has to be in the circle form. So, what is done in that circle?
23:57
So, as we know that if this is a circle then and radius is 1 it means the formula is x square plus y square has to be one. So, that is what the formula for the circle is, it means that you have to calculate here a random variable and again that will be basically. So, what we see is that we will see that if this square plus this square is becoming whether it is becoming equal to 1. So, in that case we are going to write this number. So, that condition we have to give.
24:45
Now, we have to see that now we have to ensure that for whichever point this x square plus y square means whenever x square plus y square will be less than or equal to 1less than 1 in that case it is inside this. So, we will take it as basically 1 or 0, so that way. So, whenever it is less than 1 then in that case it is 1 otherwise in most of the cases it will be all 1; either less than or equal to 1. So, we have to basically see that in one case we are going to see that for how many cases
25:30
the points are in this domain. So, for that we are writing a condition that if. So, the condition will be like this, that if x square plus y square is less than equal to 1, then you write it as 1 or else you write 0 this will be one condition and next condition will be if x square plus y square is less than equal to 1 then you write 1 otherwise you also write equal to 1. So, in the next condition if you write this condition, then it will write for every number 1.
26:14
So, in case you are getting all total numbers which are total points which are falling. So, that you will write in the next you are getting all the points which are basically less than 1. So, inside that and ratio of this will basically be this phi by 4, if that ratio is multiplied by 4 in that case that will be the value of phi. So, what you can do is you can have the condition here and you can have the condition written like this, that if this square means this e 1 square.
27:04
So, e 1 square will be there and that will be power 2 we can also write. So, this at this point we can write that if and then it is square. So, this and then you have square plus this square. So, this square is less than one 1 in that case. So, you will write 1 else you will write 0. So, if you put this condition there is some problem, if and you have to put one more here. So, in that case you will have either 1 or 0 and you can further extend it.
28:19
So, you will have these values and we see that whenever you have. So, in this case suppose 0.87 square it will something like 0.75, plus if it is 0.25 and more. So, it will be more than one. So, it is writing 0 here. So, wherever this point is going outside this domain, that points are taken as 0 and then, there are 500 points. If you take the summation of these points, this point is summed out to be let us see how much this is 403. So, that there are total 403 ones out of 500.
29:10
So, out of 500 you have 403 points which are falling inside this. So, basically it is coming out to be 0.8 806; so for only 500 iteration, because this is the phi by 4 reasons. So, for getting the whole phi value you will have to multiply it by 4. So, 0.806 multiplied by 4. So, it will be 3.224 whereas, the actual value is 3.14. Now, why this difference is this difference is because we are only for the 500 cases. Now if we do for more number of cases, if we do for 10000 number of cases, in those
30:15
that case it will be closer and closer that we can check. Suppose we are generating another stream of numbers from 500 onwards and go say up to whatever we had decided earlier up to 1000. So, again we are copying it and we will be pasting it. So, we can again past it. So, we can we have pasted them specially and then we have further we will have the condition. So, we can further drag them also. So, if we drag them for 1000. Now, in this case no it has taken some on different way.
31:13
So, in this case you have to see that how these values are coming anyway. So, what we can see here is that in this simulation that is done for Monte Carlo, which is for suppose 10000 or more number of iteration and when it was done for quite large number of iterations. So, after doing about 10000 of iterations what was seen was. So, what after doing 10000 of iterations it was seen that out of 10000; 7857 times this is coming in that reason; so 7857 out of 10000.
32:17
Now this area of since the area of this square is 4. So, you have to multiply it with four. So, if you multiply it with 4 it will be phi. So, if you see that it will be again 3.1428 by this value. So, you will have 3.14, it is coming very much closer as with respect to this value as you go on increasing that. So, you have these random numbers streams from 100 or 500 to 10000 and if you go more and more than in that case it is coming closer and closer.
32:54
So, this is the concept of using the random numbers, in that if you do for the large number of iterations you will see the average values, which will be coming closer to. So, that will talk about the expected value of the parameter and this way we do the random using the random number we do the stochastic simulation. So, in the next lecture, we will see that how the Monte Carlo technique is used for the simulation of inventory control or queuing problems. Thank you very much.
Here to help you learn
Sign in to keep a private conversation with your course tutor.
Ask me anything about the material…
Sign in to chat