the simulator definitions
play

THE SIMULATOR DEFINITIONS In the requirements I have stated that - PowerPoint PPT Presentation

THE SIMULATOR DEFINITIONS In the requirements I have stated that your simulator will be a: stochastic, discrete event, discrete time simulator. Let's see what each of these terms means. STOCHASTICITY A stochastic process is one whose state


  1. THE SIMULATOR

  2. DEFINITIONS In the requirements I have stated that your simulator will be a: stochastic, discrete event, discrete time simulator. Let's see what each of these terms means.

  3. STOCHASTICITY A stochastic process is one whose state evolves “non­deterministically”, i.e. the next state is determined according to a probability distribution. This means a stochastic simulator may produce slightly different results when run repeatedly with the same input. Therefore it is appropriate to compute certain statistics to characterise the behaviour of the simulated system. Remember, these are statistics about the model : You hope that the real system exhibits behaviour with similar statistics.

  4. DISCRETE EVENTS Discrete events happen at a particular time and mark a change of state in the system. This means discrete­event simulators do not track system dynamics continuously, i.e. an event either takes place or it does not. There is no fine­grained time slicing of the states, i.e. Generally a state could be encoded as an integer. Usually it is encoded as a set of integers, possibly coded as different data types. Discrete­event simulations run faster than continuous ones.

  5. DISCRETE VS CONTINUOUS STATES When working with discrete events, it is common to consider that states are also discrete . Example:

  6. DISCRETE TIME Discrete time simulations operate with a discrete number of points: Seconds, Minutes, Hours, Days, etc. These can also be logical time points: Moves in a board game, Communications in a protocol. Your task is to write a discrete time simulator. Events will occur with second level granularity.

  7. THE EXPONENTIAL DISTRIBUTION Remember that the probability distribution gives the probability of the different possible values of a random variable. The exponential distribution describes the time between events in a Poisson process , i.e. Events' inter­arrival times are independent (memoryless), Events occur with a constant average rate λ .

  8. THE EXPONENTIAL DISTRIBUTION Roughly speaking, the time X we need to wait before an event occurs has an exponential distribution if the probability that the event occurs during a certain time interval is proportional to the length of that time interval. Applications: Call arrivals at a telephone exchange, Radioactive particle decay, Air plane arrivals at a large hub.

  9. THE EXPONENTIAL DISTRIBUTION The probability density function (PDF) is given by: f(x,λ) = λe­λx, ∀ x > 0 Describes the relative likelihood that an event with rate λ occurs at time x .

  10. THE EXPONENTIAL DISTRIBUTION The probability density function (PDF) is given by: f(x,λ) = λe­λx, ∀ x > 0 The integral of this gives the probability that it occurs within 2 time bounds (but you can largely ignore this).

  11. THE EXPONENTIAL DISTRIBUTION The cumulative distribution function (CDF) is given by: F(x,λ) = 1 ­ e­λx, ∀ x > 0

  12. THE EXPONENTIAL DISTRIBUTION So if something happens at a rate of 0.5 per unit of time, then the probability that we will observe it occurring within 1 time unit is: F(1, 0.5) = 1 ­ e0.5*1 = 0.393

  13. THE EXPONENTIAL DISTRIBUTION The mean or expected value is given by the reciprocal of the rate parameter. In plain English this means that if something occurs at rate r then we can expect to wait 1/ r time units on average to see each occurrence. If something occurs 7 times per week, you can expect to wait 1/7 of a week (or a full 24 hours) on average between each occurrence.

  14. EXERCISE What is the probability that a random variable X is less than its expected value, if X has an exponential distribution with rate λ ? The expected value of an exponential random variable with parameter λ is: E[X] = 1/λ

  15. EXERCISE We need to compute P(X ≤ E[X]) using the distribution function: P(X ≤ E[X]) = P(X ≤ 1/λ) = F(x,λ) = 1 ­ e ­λ*1/λ = 1 ­ 1/e

  16. THE MEMORYLESS PROPERTY Formally: P(X > s + t | X > s) = P(X > t), ∀ s, t > 0 Less formally: The time that we can expect to wait for the next occurrence of some (exponentially distributed) event, is unaffected by how long we have already been waiting for it. In the 7 times a week example, if it has been 24 hours since the last occurrence, the expected additional time I have to wait is still 24 hours.

  17. THE MEMORYLESS PROPERTY A quick note, don't confuse these two properties: Correct P(X > 100 | X > 80) = P(X > 20) Incorrect P(X > 100 | X > 80) = P(X > 100) The latter would be a strange kind of pre­determined system.

  18. THE MEMORYLESS PROPERTY In your simulation, users place new requests at exponentially distributed time intervals. That means the next request event does not depend on the previous ones. As a result of firing that event, the global state of the simulation changes. However local states may not have changed, e.g. a minibus may still be at a certain stop.

  19. HOW DO WE SAMPLE FROM A DISTRIBUTION? INVERSE TRANSFORM METHOD Let X be a RV with continuous and increasing distribution function F . Denote the inverse by F −1 . Let U be a random variable uniformly distributed on the unit interval (0, 1). Then X can be generated by X = F −1(U) . If we use an exponential CDF for F , then we effectively sample from that distribution by X = ­ln(U)/λ

  20. SAMPLING EXPONENTIAL DISTRIBUTIONS IN PRACTICE Straightforward, right? (denoting mean = 1/λ ) int r = (int) (-log(rand()/RAND_MAX)*mean); Well... not quite... rand() is known to be implemented poorly. You want to draw a RV uniformly distributed on ( 0,1 ) . Seeding properly a pseudo­random generator is tricky. OK, so what should we do?

  21. XKCD?

  22. DRAWING UNIFORMLY DISTRIBUTED RANDOM NUMBERS Use a uniform deviate and discard the zero. double uniform_deviate ( int seed ) { return seed * ( 1.0 / ( RAND_MAX + 1.0 ) ); } .... int r; do r = uniform_deviate ( rand() ); while (r == 0); r = (int) (-log(r)*mean);

  23. SEEDING RAND() The usual solution is to get the system time. srand ( (unsigned int) time ( NULL ) ); Note there may be some portability issues with the above. Julienne Walker argues that hashing the system time first is a good solution. For a longer discussion about this and random numbers you can check his web page .

  24. FURTHER READING Donald E. Knuth (1998). The Art of Computer Programming, volume 2: Seminumerical Algorithms, 3rd Edition , Addison­Wesley. William H. Press et al. (2007). Numerical Recipes: The Art of Scientific Computing, 3rd Edition , Cambridge University Press.

  25. YOUR SIMULATORS 1. Will be Discrete event simulators; 2. Will be Discrete time simulators; 3. Will make use of the exponential distribution to model user behaviour.

  26. CLARIFICATIONS Boarding time The first version of the coursework contained conflicting statements about the time to board/disembark a passenger. This parameter should be given in seconds –the coursework handout has been updated accordingly.

  27. CLARIFICATIONS Question: What file format should I expect for the input scripts? Answer: Input scripts will be given in plain text format (but not necessarily with a .txt extension).

  28. REMINDERS Read the handout carefully. These slides are not a substitute. You are encouraged to submit an early version of your simulator for Part 1. This is not marked, but it gives you the chance to receive feedback which can help in completing Part 2.

  29. GUEST LECTURE ANNOUNCEMENT Dr George Hazel OBE will give a guest lecture in November (exact date TBC). Dr Hazel has extensive experience in all aspects of transport and communications. He is currently advising Scottish Enterprise on Smart Mobility as their Smart Mobility Network Integrator.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend