Models with Randomness

Accumulate and Integrate

There was a brief exercise involving Accumulate and different kinds of Holding Tanks at the end of lab last week. We'll look at that this coming Friday in lab.

Randomness

Last week we concentrated on two simulations: the compound interest or investment simulation and the lake pollution simulation. The investment model had no randomness in it: there was a fixed interest rate. The lake pollution model involved randomness, but we didn't look at that part of the model at all. Today we'll look at randomness.

What does it mean?

Philosophically, what does randomness mean? Think about this some, and we'll discuss it in class. How is the word used in ordinary life? When someone says something is "random," what do we know about it?

Why and how is investing random?

When you invest, you buy something that you hope later to resell at a higher price. (Buying a car, despite the commercials, is not an investment.) These could be stocks, bonds, a house, or diamonds. Who knows what will happen?

Let's just talk stocks. Historically, over long time periods, US stocks have returned about 10 or 11 percent per year. But in any one year, they might go up 25 percent or down 15 percent (or vice versa) or be flat. Your return over many years depends on the product of the returns in each of those years.

(Aside: If the market is down X percent one day and then goes back up X percent then next day, you are not back where you started. You're worse off. Why?)

Modeling randomness in returns is the latest thing in investment advice. For decades, any financial consultant would just show you nice curves like the ones we created. Now, they are starting to talk about the uncertainty of returns and the range of possible results you could get. We're going to do this.

Why is pollution random?

Most industrial processes pollute, at least a little. If we include indirect pollution (such as the pollution by the power plant that keeps the lights in this classroom on), everything pollutes. There may be a fixed amount of pollution that a plant creates just by existing. In addition, there may be other pollution that depends on how business is: how many widgets are being produced, how many rush orders or slow times cause equipment to work at lower efficiency, and other factors. Thus, the amount of pollution, say in pounds of chemicals or tons of CO2 equivalents, will vary, say from 1 to 100.

How do we model randomness?

Let's start with dice. The computer doesn't really have dice, of course, but it can pretend to roll dice. Later in the semester, we'll discuss how the computer actually generates random numbers. For now, we'll assume it uses some real process like dice.

Let's not answer these questions theoretically, yet. We'll do that in a later lecture. Instead, let's get some practical experience with them.

Dice — Integer Uniform

Extend can generate lots of different kinds of random numbers. These are called different "distributions." We won't worry for now about what it means for one kind of random number to be different from another. We will soon, though.

We can get a generator of die values by using the "Input Random Number" block (Generic Lib > Input). (Note that I will typically call this a random number generator, since that's what it's normally called in the simulation literature.) We'll open the dialog and look at the following:

The number of faces on the die, call it N, is

N = (max - min) + 1

Why?

The probability of each face (each number) is

1/N

This is why it's called a uniform distribution: each of the possible numbers is equally likely. In other distributions, some numbers can be more likely than others.

We'll also use a "histogram" (Plotter Lib > Histogram). Histograms are a wonderfully useful way of looking at sets of numbers when you don't care about the particular history, you just care about how many of each kind there are.

We'll look at the dialog for this, too.

Finally, we'll look at how the number of rolls of the dice are determined (Run > Simulation Setup > Continuous Simulations > Number of Steps ).

Our model looks like:

one random number generator and one histogram

We'll run some experiments to explore the questions above and whatever other questions may arise during class.

N-sided Dice

Depending on our model, we may need dice with more or fewer than six sides. (Gamers run into this all the time. Do you know about "percentile dice" used in fantasy role-playing games?) In Extend, it's easy to handle this by adjusting the "min" and "max" values.

Can you think of a physical way to have a 3-sided die?

What if you only had a normal 6-sided die and needed to make a three-way decision?

Functions of Random Numbers

The uniform integer distribution is a pretty flexible kind of generator. Still, there are things it can't do immediately, so we may need to modify the numbers some.

Note that many of the kinds of random numbers have some fixed point (such as starting at zero). Therefore, in the following discussion, we will assume that the uniform integer distribution always has:

min=0 max=N-1

Why N-1?

location: 10-20

Suppose we needed numbers in the range from 10-20, inclusive, instead of starting at 0? What could we do?

We'll do this in Extend, just to give us a nice visual concept. It looks like

one die plus 10

Mathematically, if X represents the random variable, we are just computing

Y=X+10

(Historically, random variables are often denoted by bold type, although that can be a pain on the whiteboard or in your notes.)

I hope this is a pretty straightforward idea, but we'll introduce some terminology and call this "shifting" or "translating" the random variable: changing its location without changing the range or number of values or anything else about the random variable.

scale: 0,10,20...50

What if we needed numbers that weren't consecutive, but were in distances of 10 or 0.1?

Right, just multiply (or divide) by 10. Again, we'll do this in Extend, but the math is just:

Y=10X

We call this scaling the random variable: streching or shrinking its range. This is just like a change of units: say working in inches instead of feet.

More Generality

In general, we can do anything to a random number that we do to any number, so you can square it, take the cosine, compute some weird polynomial, or whatever you need for your model. As things get more interesting, you might want to use a "math" block.

The Equation block in Extend

Suppose, just for the sake of argument, that we want to compute

Y=3X2+4X+5

We could do that with four multiply blocks, three constant blocks and an add block, but the result would be a mess. Instead, we can encapsulate the whole thing into a single formula using the "Equation" block (Generic Lib > Math > Equation).

Let's try having the 3 come from a constant block instead of being built into the equation.

Sums of two dice

What's the difference between

Y=2X

and

Y=X+X

Let's build a model that has two random number generators (with identical parameters) and another that has a single random number generator but multiplies the result by 2.

The sum isn't uniform because there are lots of ways to produce a 7, but only one way to produce a 2. Therefore, the chance of getting a 7 is higher. This is something we all intuitively know from years of playing with dice. Here are the details:

2=1+1

7=1+6
7=2+5
7=3+4
7=4+3
7=5+2
7=6+1

So, the probability of getting a 7 is six times higher than the probability of getting a 2!

You can figure out all the probabilities by just looking at an addition table for the two dice.

The Multisim Plotter

Once we add randomness to a model, we will want to run it more than one time. Then, we'll want to compare the results in different runs, and the best way to do that is to plot them on the same plotter. To do that, use a Plotter, Multisim (not "Plotter, Multisim, DE"; we'll learn about that when we get to discrete event simulation).

Let's build a simple simulation that just sums the random numbers we get. We only need a random number generator, an accumulator, and a plotter (multisim).

In Run > Simulation Setup, modify the number of runs to 5 and the number of steps to be 10. Then run the model. We'll look at the multisim plot together:

Pitfall: different axes

Consider an alternative way to do this:

All in all, not a good option. But maybe for some purposes.

Samples versus Distributions (Populations)

If we roll a die, we get a particular number. That number is called a sample. What is it a sample of? It's a sample of a population of possible outcomes, namely the numbers 1-6.

Similarly, if we roll a die 5 times, we get 5 numbers. That sequence of 5 numbers is a sample from a population of all possible sequences of 5 numbers 1-6.

Less obviously, when we run our "dice-sum" simulation, we are obtaining a sample (or 5 samples) from a population of all possible runs of the model, which, of course, is just the population of sums of 10 random numbers 1-6.

When we add randomness to a simulation, each run becomes a sample from a (possibly infinite) population of possible runs. The statistics questions and techniques that we will explore, starting next time, are always based on the idea of trying to figure out what a sample can tell us about a population.

The randomness that we build into a simulation can't be completely arbitrary. Like everything else in the model, it has to be based on some aspect of the real world system. Thinking of our philosophical discussion earlier, the randomness might represent our inability to predict something in the real world or our lack of knowledge of some constant or parameter.

It can be confusing sometimes, but there is a huge difference between a sample and a population. Try to keep these examples in mind as we use those terms.

Modifying the Interest Model to use Randomness

We said that the long-run average return on stocks is about 10%. Suppose that the year to year returns range from -20% to +40%.

Let's use the Integer, Uniform to create this. For simplicity, we'll use steps of 0.1.

Here's a model to play with: random-return.mox

Looking at Randomness in the Lake Pollution Model

The Lake Model already has a random number generator in it. We'll replace it with a Integer Uniform between 0 and 2000.

Predator-Prey Simulations

We hinted at this the first day, but didn't dig into the model. Today, we'll just introduce the basic ideas, and we'll dig into them in a hands-on way in lab.

This work is licensed under a Creative Commons License | Creative Commons License | Viewable With Any
Browser | Valid HTML 4.01! | Valid CSS!