Lesson 2 - Brief Overview of Key Advanced Features
Although this Course covered all of the key features and capabilities of GoldSim, a number of advanced features were not covered at all. Rather than discussing these features in any detail at all, the goal of this Lesson is to simply to make you aware of them, so that once you are more comfortable with GoldSim, you can start to learn about and take advantage of them. The most important of these advanced features are introduced briefly below.
Manipulating Arrays (Vectors and Matrices)
In the Examples and Exercises discussed in this Course, all of the elements represented scalar values (or conditions). In many systems, however, you will want to create and manipulate elements that represent collections of data, rather than individual items. For example, you may want to create an element that represents your company's revenue for each of five separate divisions, or an element that represents the salmon population in each of a number streams.
One way to do this, of course, would be to create separate elements for each object you wanted to model (e.g., five elements representing revenue, 13 elements representing salmon populations in different streams). Such an approach, however, is not desirable for two reasons:
- It could require you to create a very large number of elements (e.g., if you wanted revenues for 100 subgroups or wanted to evaluate salmon populations in 200 streams). This could result in very large, cluttered models.
- Usually, you will want to carry out the same types of calculations and operations on all related objects in such a collection (e.g., multiply all revenues by a particular number, compute the total number of salmon eggs this year for all the streams based on the current salmon population). Having to do this individually for every object in a large collection would be very cumbersome and time-consuming.
To address these kinds of problems, GoldSim allows you to create and manipulate vectors and matrices (collectively referred to as arrays). For example, you could create a vector Data element that represented the salmon populations in each of a number of streams, as shown below:
You could also create a matrix Data element that represented the salmon population in each of a number of streams for a period of 3 years, as shown below:
In addition to adding data in the form of vectors and matrices, you can manipulate these arrays in equations. For example, you could create an Expression element, and define it as:
2 * Salmon_Population
The output of the Expression would be an array, identical to the Salmon_Population array, except each item of the array would be two times greater. Note that if you did not use arrays to carry out this calculation, rather than creating 2 elements, you would need to create 26 elements (2 for each stream: 13 Data elements and 13 Expression elements) to accomplish the same thing!
If required, you can access a particular item of the array in an equation. For example,
references a single (scalar) value representing the salmon population in Bear Creek in 1999.
GoldSim provides a wide variety of special operators which allow you to manipulate arrays. For example, if the name of the vector was Salmon_Population, the expression
would result in a single (scalar) value representing the sum of all items in the vector.
Linking to Spreadsheets and Databases
Earlier in this Course, we saw that GoldSim provides capabilities to easily import time series data from spreadsheets to GoldSim (and you can also import Lookup Table data). We also saw that you can export GoldSim results to a spreadsheet.
In addition, GoldSim allows you to dynamically link a spreadsheet directly into your model using a Spreadsheet element. In the simplest use of this element, you can use the spreadsheet as a data source. In addition to importing data from a spreadsheet, however, you can use a spreadsheet as a custom element (with specific functionality). That is, you can dynamically send data from GoldSim to a spreadsheet, force the spreadsheet to recalculate, and then retrieve (updated) data from the spreadsheet back into GoldSim during a simulation (e.g., every timestep).
GoldSim also allows input elements to be linked directly to an ODBC-compliant database. After defining the linkage, you can then instruct GoldSim to download the data prior to running the model. When it does this, GoldSim internally records the time and date at which the download occurred, and this information is stored with the model results. This mechanism provides very strong and defensible quality control over your model input data.
Controlling the Timestep in a Model
In the Examples and Exercises in this Course, we used constant timesteps. However, GoldSim provides powerful timestepping capabilities that allow you represent the dynamics of your system very accurately for complex models. This includes the following:
- You can increase or decrease the timestep length according to a specified schedule during a simulation (e.g., start with a small timestep, and then telescope out to a larger timestep). This can be useful, for example, if you know that early in a simulation, parameters are changing rapidly, and hence you need a smaller timestep.
- You can dynamically adjust (adapt) the timestep during a simulation based on the values of specified parameters in your model. For example, you could instruct GoldSim to use a timestep of 1 day if X was greater than Y, and 10 days if X was less than or equal to Y. Similarly, you could instruct GoldSim to use a short timestep for a period of 10 days after a particular event occurs, and then return to the default timestep.
- You can apply dynamic adaptive timestepping to specific Containers. This allows you to specify different timesteps for different parts (i.e., Containers) of your model. For example, if one part of your model represented dynamics that changed very rapidly (requiring a 1 day timestep), while the rest of the model represented dynamics that changed much more slowly (requiring a 10 day timestep), you could assign a 10 day timestep to the model globally, and a 1 day timestep to the Container representing the subsystem that changed rapidly.
Activating and Deactivating Portions of a Model
GoldSim provides the ability to make parts of your model (i.e., Containers) conditional. Conditionality allows you to make a Container and all of its contents inactive unless specific events occur and/or conditions are met. Elements in an inactive container are “dormant”. That is, they are not updated or recalculated each timestep, and while they are inactive their output values never change. When other specific events occur and/or conditions are met, the Container (and its contents) can become active (and hence carry out their normal calculations). A conditional Container can activate and deactivate multiple times during a simulation.
Conditionality is a very powerful feature, and can be used to 1) temporarily “turn off” certain parts of your model (e.g., during a testing phase); or 2) simulate processes or features which themselves only exist or are active during certain parts of your simulation. This feature is particularly useful when using GoldSim to simulate projects.
Keeping Track of Model Changes Using Versioning
To assist with managing the construction and maintenance of complex models, GoldSim provides the ability to track changes that you have made to your model file (Which elements have changed? Which elements were deleted? Which elements have been added?).
This feature (referred to as versioning) allows you to quickly determine the differences between the current version of your model file and some previous version of the file.
Providing this configuration management capability is particularly useful for:
- coordinating model changes when multiple people can access and modify the model file; and
- as a Quality Assurance/Quality Control feature enabling you to demonstrate and document when and what changes have been made to a model file.
Optimizing a Model
GoldSim provides the ability to carry out a special type of run to facilitate optimization of your model. For this type of run, you specify an objective function (a specific result that you would like to minimize or maximize), an optional constraint (a condition that must be met), and one or more optimization variables (variables in your model that you have control over).
GoldSim then runs the model multiple times, systematically selecting combinations of values for each of the optimization variables. By doing so, GoldSim can determine the values of the optimization variables that optimize (minimize or maximize) the objective function while meeting the specified constraint:
Typical uses of optimization include:
- Finding the best input data values for a model, in order to match observed historical data (i.e., calibration);
- Selecting the "best" option from among alternatives. "Best" could mean safest, cheapest, most reliable, or another appropriate measure; and
- Optimizing the timing of actions or policy changes during the course of a simulation.
Carrying Out Sensitivity Analyses
GoldSim provides the ability to carry out a special type of run to facilitate sensitivity analyses. For this type of run, you specify the result you are interested in, and one or more variables that you want to analyze (which must be Stochastics or Data elements).
GoldSim then runs the model multiple times, systematically sampling each variable over a specified range, while holding all of the other variables constant. This then allows GoldSim to produce sensitivity plots (i.e., a tornado chart and X-Y function charts) to assist you in graphically identifying the variables in your model to which the result is most sensitive:
GoldSim also provides a second type of sensitivity analysis in which statistical sensitivity measures are computed by analyzing the results of multiple realizations of the model where all of the Stochastic variables are simultaneously sampled each realization:
Representing Stochastic Variables Using a History Generator
In Units 12 and 13, we discussed ways in which you could generate (or input) variables that behaved stochastically (i.e., exhibit inherent temporal randomness). This included repeatedly sampling a Stochastic element, using historic Time Series data, and defining random events.
In addition to these methods, however, GoldSim also provides a specialized element to generate such time histories, referred to as a History Generator. A History Generator generates a random time history based on a specified set of statistics.
The History Generator can generate a stochastic time history based on one of two statistical approaches:
- The variable follows a “random walk” through time. It can be specified to be unconstrained during the walk, or it can be specified to revert to a “target”:
- The variable exhibits geometric growth with a specified volatility:
This element is typically used to simulate financial and economic variables (e.g., security prices, interest rates, sales rates), but also has many applications in other arenas.
Carrying Out Iterative (Looping) Calculations
In some models, you may want to carry out an iterative calculation at each timestep. This might be useful, for example, if you have a coupled system of nonlinear equations that must be solved every timestep by iterating.
GoldSim allows you to create a Looping Container in which the elements inside are iteratively updated every timestep until a specified condition is met:
Such a looping calculation is facilitated by the fact that GoldSim also provides a specialized element that allows you to reference the previous calculated value of any variable in your model.
Building Custom Elements Using Scripts and External Elements
In some situations, you may wish to define a complex function which cannot be readily implemented using the expression editing features supplied by GoldSim. For example, calculation of an output may require very complex logic which would be cumbersome to represent using standard GoldSim elements, or it may require a numerical solution technique (e.g., iteration); or perhaps you need to construct an array using complex logic.
One way to address this is to dynamically link an external computer program directly to GoldSim using what is referred to as an External element. GoldSim provides a programming interface to support this. You must specify the parameters (outputs of existing GoldSim elements) that you wish to send to the external program, and the parameters that the external program will return to, and make available within, GoldSim. In most cases, you need to only make minor modifications to the external program code to which you want to link in order for it to communicate with (i.e., be dynamically called by) GoldSim.
Although, for some complex calculations, an External element may be required, for many applications a Script element can be used instead. The key advantages of a Script over an External element is that 1) it does not require use of a separate programming language and interface; and 2) it is much more transparent (all of the “code” can be seen directly in GoldSim):
Scripts are created by inserting and editing statements or statement blocks, which may be variable definition statements, variable assignment statements, statements controlling the sequence of execution in the script (e.g., loops and if statements), or statements used for writing messages to a log file. Script elements even have their own built-in debugging features (e.g., breakpoints).
The Script element does not expect the user to learn or be familiar with a particular language. As a result, scripts are not created using a text editor. Rather, statements are inserted and edited within a “controlled environment” within the element’s property dialog in which the user selects from a number of available statement types. The syntax is already defined for each type of statement – the user simply specifies the attributes and properties for each statement via a dialog box when the statement is inserted. Statements can subsequently be moved, deleted, and edited.