Presentation is loading. Please wait.

Presentation is loading. Please wait.

Where real stuff starts

Similar presentations


Presentation on theme: "Where real stuff starts"— Presentation transcript:

1 Where real stuff starts
28/05/2019 Simulation Where real stuff starts

2 ToC What, transience, stationarity How, discrete event, recurrence
28/05/2019 What, transience, stationarity How, discrete event, recurrence Accuracy of output Monte Carlo Random Number Generators How to sample 1

3 1 What is a simulation ? An experiment in computer
28/05/2019 An experiment in computer Important differences Simulated vs real time Serialization of events 2

4 Stationarity A simulation can be terminating or not
28/05/2019 A simulation can be terminating or not For a terminating simulation you should make sure it is stationary 3

5 Information server, scenario 1
28/05/2019 Information server, scenario 1 4

6 Information server, scenario 2
28/05/2019 Information server, scenario 2 5

7 Stationarity In scenario 1: In scenario 2:
28/05/2019 In scenario 1: Transient phase, followed by “typical” (=stationary) phase You want to measure things only in the stationary phase Otherwise: non reproduceable, non typical In scenario 2: There is no stationary regime “walk to infinity” you should not do a non terminating simulation with this scenario 6

8 Definition of Stationarity
28/05/2019 A property of a stochastic model Xt Let Xt be a stochastic model that represents the state of the simulator at time t. It is stationary iff for any s>0 (Xt1, Xt2, …, Xtk) has same distribution as (Xt1+s, Xt2+s, …, Xtk+s) i.e. simulation does not get “old” 7

9 Classical Cases Markov models
28/05/2019 Markov models State Xt is sufficient to draw the future of the simulation Common case for all simulations For a Markov model, over a discrete state space If you run the simulation long enough it will either walk to infinity (unstable) or converge to stationary Ex: queue with  >1: unstable queue with  <1: becomes stationary after transient If the state space is strongly connected (any state can be reached from any state) then there is 0 or 1 stationary regime Ex: queue Else, there may be several distinct stationary regimes Ex: system with failure modes 8

10 Stationarity and Transience
28/05/2019 Knowing whether a model is stationary is sometimes a hard problem We will see important models where this is solved Ex: Solved for single queues, not for networks Ex: time series models Reasoning about your system may give you indications Do you expect growth ? Do you expect seasonality ? Once you believe your model is stationary, you should handle transients Remove (how ? Look at your output and guess) Sometimes it is possible to avoid transients at all (perfect simulation) 9

11 Non-Stationary (Time Dependent Inputs)
28/05/2019 Non-Stationary (Time Dependent Inputs) 10

12 Typical Reasons For Non Stationarity
Obvious dependency on time Seasonality, growth Can be ignored at small time scale (minute) Non Stability: Explosion Queue with utilization factor >1 Non Stability: Freezing Simulation System becomes slower with time (aging) Typically because there are rare events of large impact (« Kings ») The longer the simulation, the larger the largest king Ex: time between regeneration points has infinite mean We’ll come back to this in the chapter « Importance of the View Point » 11

13 Quiz 28/05/2019 12

14 2 Simulation Techniques
28/05/2019 Discrete event simulations Recurrences Stochastic recurrences 13

15 Discrete event simulation Uses an Event Scheduler
28/05/2019 t1 t2 t3 queue length 1 2 t4 Example: Information system modelled as a single server queue Three event classes arrival service Departure One event scheduler (global system clock) arrival service departure 14

16 Scheduler: Timeline t1 t2 t3 queue length 1 2 t4 initialization Step 1
t1 t2 t3 queue length 1 2 t4 Scheduler: Timeline 28/05/2019 initialization Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 service t=0 arrival t=t1 arrival t=t1 departure t=t2 service t=0 departure t=t2 arrival t=t4 t=t1 departure t=t2 service arrival t=t4 service t=t2 departure t=t3 arrival t=t4 departure t=t3 arrival t=t4 Event being executed arrival t=0 State of scheduler 15

17 Statistical Counters 28/05/2019 Assume we want to output: mean queue length and mean response time. How do we do this ? Note the difference between Event based statistic Time based statistic 16

18 A Classical Organization of Simulation Code
28/05/2019 Events contain specific code A main loop advances the state of the scheduler Example: in the code of a departure event 17

19 28/05/2019 Main program 18

20 28/05/2019 19

21 Stochastic Recurrence
28/05/2019 An alternative to discrete event simulation faster but requires more work on the model not always applicable Defined by iteration: 20

22 Example: random waypoint mobility model
28/05/2019 21

23 28/05/2019 22

24 28/05/2019 23

25 24

26 Queuing System implemented as Stochastic Recurrence
28/05/2019 25

27 28/05/2019 26

28 3 Accuracy of Simulation Output
28/05/2019 A stochastic simulation produces a random output, we need confidence intervals Method of choice: independent replications Remove transients For non terminating simulations Be careful to have truly random seeds Ex: use computer time as seed 27

29 Results of 30 Independent Replications
28/05/2019 28

30 28/05/2019 Do They Look Normal ? 29

31 28/05/2019 Bootstrap Replicates 30

32 Confidence Intervals Mean, bootstrap Median Mean, normal approx 31
28/05/2019 Mean, bootstrap Median Mean, normal approx 31

33 5 Random Number Generator
28/05/2019 A stochastic simulation does not use truly random numbers but pseudo-random numbers Produces a random number » U(0,1) Example (obsolete but commonly used, eg in ns2: ) Output appears to be random (see next slides) 32

34 The Linear Congruential Generator of ns2
28/05/2019 uniform qq plot autocorrelation 33

35 Lag Diagram, 1000 points 28/05/2019 34

36 Period of RNG RNG is in fact periodic
28/05/2019 RNG is in fact periodic Period should be much larger than maximum number of uses 35

37 Two Parallel Streams with too simple a RNG
28/05/2019 36

38 28/05/2019 Impact of RNG 37

39 Take Home Message 28/05/2019 Be careful to have a RNG that has a period orders of magnitude larger than what you will ever use in the simulation Serialize the use of the RNG rather than parallel streams 38

40 6 Sampling From A Distribution
28/05/2019 Pb is: Given a distribution F(), and a RNG, produce some sample X that is drawn from this distribution A common task in simulation Matlab does it for us most of the time, but not always Two generic methods CDF inversion Rejection sampling 39

41 CDF Inversion 28/05/2019 Applies to real or integer valued RV 40

42 28/05/2019 41

43 Example: integer valued RV
28/05/2019 42

44 28/05/2019 43

45 28/05/2019 44

46 Rejection Sampling 28/05/2019 Applies more generally, also to joint n-dimensional distributions Example 1: conditional distribution on this area Step1 : Can you sample a point uniformly in the bounding rectangle ? Step 2: How can you go from there to a uniform sample inside the non convex area ? 1000 samples 45

47 Rejection Sampling for Conditional Distribution
28/05/2019 This is the main idea How can you apply this to the example in the previous slide ? 46

48 Rejection Sampling for General Distributions
28/05/2019 47

49 28/05/2019 48

50 A Sample from a Weird Distribution
28/05/2019 49

51 28/05/2019 50

52 Another Sample from a Weird Distribution
28/05/2019 51

53 6.3 Ad-Hoc Methods 28/05/2019 Optimized methods exist for some common distributions Optimization = reduce computing time If implemented in your tool, use them ! Example: simulating a normal distribution Inversion method is not simple (no closed form for F-1) Rejection method is possible But a more efficient method exists, for drawing jointly 2 independent normal RV There are also ad-hoc methods for n-dimensional normal distributions (gaussian vectors) 52

54 A Sample from a 2d- Normal Vector
28/05/2019 53

55 4 Monte Carlo Simulation
28/05/2019 A simple method to compute integrals of all kinds Idea: interpret the integral as Assume you can simulate as many independent samples of X as you want 54

56 28/05/2019 55

57 28/05/2019 56

58 28/05/2019 57

59 28/05/2019 58

60 Take Home Message 28/05/2019 Most hard problems relative to computing a probability or an integral can be solved with Monte Carlo Braindumb but why not Run time may be large -> importance sampling techniques (see later in this lecture) 59

61 Questions 28/05/2019 60

62 Questions Q4.2 A node receives messages from 2 sensors S1 and S2. Each of the sources sends messages independently of each other. The sequence of time intervals between messages sent by source S1 is iid, with a Gaussian distribution with mean m1 and variance s12 and similarly for S2. The node works as follows. It waits for the next message from S1. When it has received one message from S1, it waits for the next message from S2, and sends a message of its own. How do you implement a simulator for this system ? Q4.1 A system contains a population of tasks that arrive as a Poisson process. Each task spends a time that is random, iid, independent of the arrival process, and with Pareto distribution. How do you implement a simulation of this system ? 61

63 Conclusion Simulating well requires knowing the concepts of Transience
28/05/2019 Simulating well requires knowing the concepts of Transience Confidence intervals Sampling methods 62


Download ppt "Where real stuff starts"

Similar presentations


Ads by Google