Lesson 2 - Representing a Stochastic Process: Resampling a Stochastic
Perhaps the simplest way (but, as we shall see, not the only way) to represent a stochastic process is to use the Stochastic element itself.
In the previous Unit, we dealt only with parameters whose uncertainty is due to ignorance or lack of knowledge. As a result, at the beginning of each realization, we sampled a Stochastic element (and held its value constant for the entire realization). Each realization has a different sampled value.
Parameters whose uncertainty is due to inherent randomness can also be represented using a Stochastic element. But in this case, the distribution represents a frequency distribution in time (e.g., the hourly flow rate in a river). As a result, what we want to do is resample the distribution (in this case every simulated hour). Resampling a distribution means that instead of picking a random value only at the beginning of the simulation, we will pick new random values throughout the realization (according to some logic/schedule that we specify).
As was noted very briefly in the previous Unit, the Stochastic element provides a setting to do precisely this. In particular, you may recall that the Stochastic has two Mode radio buttons:
The default is “Sampled once”. To resample the element, we select “Resampled”.
The best way to understand this is to create a very simple example. Start with a new model and insert a Stochastic element. Name it “Constant_Values”.
Press the Edit… button and change the definition to a Normal distribution with a Mean of 10 and a Standard Deviation of 2. Close that dialog and you will note that “Sampled once” is indeed the default for the Mode. For now leave this as the default.
Now let’s set up a Monte Carlo simulation and run the model. Open the Simulation Settings dialog, go to the Monte Carlo tab, and set up the model to run for 10 realizations. Close the Simulation Settings. To plot time histories, we will need a Time History Result element. Add one now (you can do this in Edit Mode; you will find it under the “Results” category when inserting an element), and add the Stochastic element to the list of outputs:
Now run the model and double-click on the Result element. Your result will look something like this:
By default, GoldSim displays Probability Histories (which we discussed in Unit 11, Lesson 7). For the purposes of this Lesson, this display is not very useful, so select “All Realizations” from the Display drop-list:
Note: Your 10 realizations will not look identical to this. Each will be a flat line, but the values will be different, since the random numbers used to sample the distributions are different. We will discuss random numbers later in this Unit.
The key thing to note here is that because the Stochastic was “Sampled once”, each realization has a different value, but the values do not change over time.
Before we close this dialog, let’s make a few formatting changes, as we will continue to add some results to this chart (and it also gives you some additional practice formatting results). Recall from Unit 7, Lesson 3 that we can edit the Chart Style using this button:
When you do so, a Chart Style dialog will appear (next to the chart).
Go to the Y-Axis tab. By default, the Title uses a keyword (discussed previously in Unit 7, Lesson 3), so that the axis title uses the first label in the list of outputs. We are going to add several additional outputs, so this won’t be appropriate, so let’s just replace this with simply “Result”. Then change the Minimum and Maximum to 0 and 20, respectively:
Press Apply to view the change and then OK to close the dialog. Next, let’s hide the Header. To do this, right-click in the plot, select View from the menu, and clear the check next to “Show Header”. Finally, select “Realization” from the Display drop-list. When you are done, your chart should look similar to this (you can toggle to view any particular realization). The actual values for the various realizations will, for reasons mentioned above, be different.
Now close the dialog and return to Edit Mode.
Now we are going to create a Stochastic element that is resampled instead of sampled only once.
Copy the Stochastic element (select and press Ctrl+C), and paste it (Ctrl+V). Double-click on the new (pasted) element, and rename it “Stochastic_Process”. For the Mode, select “Resampled”. When you do so, you will see that the Resample… button becomes active:
If we want to resample a Stochastic (i.e., sample it multiple times during simulation), we obviously have to somehow tell GoldSim when to do so. The Resample… button provides access to a dialog for doing this:
This is referred to as the Triggering dialog, and we will discuss it in detail in Unit 13 (when we discuss modeling discrete events). In that Unit, we will see that this same dialog is used by a number of elements in GoldSim. The triggering dialog is used to define one or more triggering events. When you trigger an element (via a triggering event), you are specifying a discrete event or signal (at a specific point or points in the simulation) that you want the element to respond to. Each of the elements that supports a triggering dialog responds to the event in a specific way. In the case of a Stochastic, it responds by resampling itself.
Press the Add button and GoldSim will add a row. Then open the drop list:
There are a number of types of triggering events that can be defined (and we will discuss these in Unit 13). For this Unit, however, we are going to focus on only one of these: “On Changed”:
This type of triggering event is the one that is most commonly used when using a Stochastic element to represent a stochastic process. The way it works is quite simple: you enter an output into the Trigger Definition, and the element is triggered whenever the value of that output changes. When resampling a Stochastic to represent a stochastic process, what we typically will want to do is resample the element regularly according to some schedule (e.g., every hour, every day, every month). Fortunately, GoldSim provides outputs that allow you to do this very easily.
You should recall from previous Lessons (Unit 6, Lesson 9 and Unit 10, Lesson 3) that GoldSim provides a number of special reserved names, referred to as Run Properties, that can be directly referenced in input fields. We can use these Run Properties to regularly sample the Stochastic.
You can enter the names of the Run Properties directly (just as you would enter the name of an output), or you can insert them into an input field using the Insert Link dialog. Let’s use the latter method: right-click in the Trigger Definition field and select Insert Link… from the menu. The following dialog will be displayed:
At the top of the dialog is a folder labeled “Run Properties”. If you expand this folder, you will see that the Run Properties are organized into four categories (Calendar Time, Elapsed Time, Reporting Periods, and Simulation):
Expanding any particular category folder lists all of the Run Properties in that category. For our purposes, let’s expand the Calendar Time category:
You can see that there are a number of properties we can reference.
So how can we use these?
- To resample the Stochastic every day, select any of the outputs starting with “Day”, such as “DayofWeek” (this output simply cycles from 1 to 7 throughout the simulation):
- To resample the Stochastic every hour, select “Hour” (this output simply cycles from 1 to 24 throughout the simulation).
- To resample the Stochastic every calendar month, select “Month” (this output simply cycles from 1 to 12 throughout the simulation).
Note: Even though we are actually running an Elapsed Time simulation in this simple example, we can still reference calendar-based properties such as these. This is because in an Elapsed Time simulation, a Start Time is still specified (by default it is the actual date/time when you created the model), and therefore GoldSim has a basis on which to compute these calendar-based properties.
Leave Trigger Definition as “DayofWeek” and close the triggering dialog. Hold your cursor over the Resample… button and you will note that GoldSim displays a tool-tip showing the triggering event(s). Now close the main dialog for the element. We have now set this Stochastic element to be resampled every day (in order to represent a stochastic process). Let’s now add this element to the Time History Result element (open the Result element, and use the Add Result… button to do this). Then re-run the model and view the Time History Result:
As can be seen, for each realization, the “Constant_Values” element remains constant, while the “Stochastic_Process” element is resampled every day. If you toggle through the ten realizations (using the spin control at the top of the display), you will note that each realization, the Stochastic_Process element not only has a different initial value, but it follows a different random path through time: it represents a stochastic process.
Return to Edit Model and save this little example problem (name it Example16_Resampling.gsm) to the “MyModels” subfolder in the “GoldSim Course” folder, as we will revisit it briefly later in this Unit.