waqqasfarooq.com

  • Increase font size
  • Default font size
  • Decrease font size
Home Tutorials Simulations Infrastructure


Simulations Infrastructure

E-mail Print PDF
User Rating: / 67
PoorBest 
Article Index
Simulations Infrastructure
Solution 1 (Probability Principals)
Solution 2 (Real World Scenario)
Solution 3 (Simulations)
-- 3.1 Using excel spreadsheet
-- 3.2 Using excel VBA macro
-- 3.3 Using Python
-- 3.4 Using Matlab
Appendix A - Downloads
All Pages

In this article I want to give out a basic reusable infrastructure for quickly starting off with simulations and reporting the results.

I will give a step-by-step setup of simulations testbed using 4 different technologies:

  1. Excel Spreadsheets
  2. Excel VBA macro
  3. Python
  4. Matlab

I believe that the best way to learn something is to bring in an application (or example) in as soon as possible. So the layout of this article will be that I will describe a fictitious 'situation' and then I will go ahead and provide a step-by-step guide as how to model the 'situation' in computer tech (e.g. matlab, python,...).

The complete source code is available in Appendix A


Problem Definition (Example)

Say there are 1000 students and each students is given a die (small cube with the numbers 1 to 6 marked in dots on the sides used in gambling). Each student will roll the die once and the teacher will note that value (the number of dots on the side facing up) of the roll. Now, we are interested in the average (or the expected value) of this process.

Note: This is a very simple example which might not make a lot of sense in real life, but this will show us how simulations are useful. You can later extend this example into more complicated ones like ones given in Monte Carlo Simulation & Analytical Hierarchy Process.


Solution

To the problem given above we can take 3 approaches to get to the solution:

  1. Using the principals of probability and mathematics to get the expected value (average in our example) for the result.
  2. Gather 1000 students; give each one of them a die; get a teacher; ask each student to roll the die and have the teacher note the result in a notebook; then take the average of the 1000 results. Good luck!
  3. Using simulations: Write a computer program that simulates 1000 students, the properties of a die roll & the teacher who keeps record of the dice rolls. Have the computer create the report result.

I will talk about solutions 1 and 2 briefly next, then I will work on solution 3 and give you different infrastructures for simulations.




 

Comments  

 
0 #7 ross 2013-02-07 08:49
You are literally a life saver. Thank you so much for posting this.
 
 
0 #6 jn 2011-10-04 06:11
you code is skewed, 2 and 5 have slightly less probability of selection than 1, 3, 4, 6 - thats the disadvantage of numerical approximation I guess using 1/6 instead may produce better results at least to machine precision.
 
 
+1 #5 Muhammad Abdullah 2011-09-18 11:31
want to create a program in matlab about rolling 4 dices (fair dices, 6 sided) at the same time, and then assign them the probabilities. then i have to conduct n trials of the experiment and plot it also
please help me, please write a ful matlab code am v poor in matlab
 
 
0 #4 Waqqas Farooq 2010-10-27 20:27
Quoting optimizerx:
Thanks, great example.

I noticed you also do eCommerce which piqued my interest in a simulation problem and best approach to solving it:

1) Website needs to forecast future eCommerce conversions quantity

2) 6 Different traffic sources each w/ varying conversion performance

3) 4 unique content areas a site visitor can consume along their site traversal path

Given the combination of varying originating traffic source & content areas combinations, would it be appropriate to solve the problem with markov & monte carlo methods?

Your thoughts?

Thank you very much in advance for your response.


I am not sure what exactly the question is asking but I think I do get the general question. The question is: "how many customers will switch to eCommerce service in the future?"

The answer to this that you could use either markov chains or monte carlo but I would use monte carlo method. Mostly because you do not have repeating states (i.e. once a customer is an eCommerce service user then he stays there).

Now, the information you are providing in point 2 and 3 is important and it needs to be detailed. You need to come up with numbers (e.g. probability for people coming from source 1 and converting to eCommerce service...). Doing a thorough analysis of the input variables will also help you decide which method (monte carlo or markov chains) to choose to solve this problem.
 
 
+1 #3 optimizerx 2010-10-25 16:51
Thanks, great example.

I noticed you also do eCommerce which piqued my interest in a simulation problem and best approach to solving it:

1) Website needs to forecast future eCommerce conversions quantity

2) 6 Different traffic sources each w/ varying conversion performance

3) 4 unique content areas a site visitor can consume along their site traversal path

Given the combination of varying originating traffic source & content areas combinations, would it be appropriate to solve the problem with markov & monte carlo methods?

Your thoughts?

Thank you very much in advance for your response.
 
 
+1 #2 Waqqas Farooq 2010-09-29 01:40
Quoting Misra N. N.:
gr8....Thanks a lot...
Matlab...most awaited...


Just added the matlab source code for the dice rolling problem.
 
 
+1 #1 Misra N. N. 2010-09-24 07:26
gr8....Thanks a lot...
Matlab...most awaited...