Distributions
|
|
|
Running a simulation with different distributions elegantly(Author: Klaus Muller; kgmuller at users.sourceforge.net)In simulation modelling, one often has the situation that one wants to run the same model with different distributions (normal, uniform, empirical, . . ) for a random variate, e.g. for "what if" investigations. This is simple to achieve by editing the program text, but this is tedious and error prone. One also ends up with several different program versions. Python comes to the rescue. With functions being first class objects and with generators, distributions are easily encapsulated so that the distributions can be referenced generically. They can also be given parameters once, without repeating them in the program text. Here is an example which shows the elegance which can be achieved. Let's assume that for an arrival process, several distributions for inter-arrival times are to be studied, i.e. normal, uniform and empirical distributions. By
one comes up with this clean program:
One can embed any distribution this way, even distributions returning e.g. a value input interactively by a user at run time.
|
©Copyright 2004, 2005, 2006, 2007, 2008 SimPy
Developer Team.
|