Tutorial: Dynamic system model
• • • • • 5.4 •
- 1 Using the Time index
- 2 Setting up the Hare sub-model
- 3 Using the Dynamic() function
- 4 Completing the Hare sub-model
- 5 Using the color palette
- 6 Creating a module
- 7 Duplicating a module
- 8 Completing the Fox sub-model
- 9 Creating aliases
- 10 Drawing influence arrows across modules
- 11 Viewing multiple results simultaneously
- 12 Foxes and Hares Act III
- 13 Summary
- 14 See Also
This chapter shows you how to:
- Use the Dynamic() function and the system variable Time
- Customize the appearance of variable nodes
- Organize a model using modules
- Make duplicates of nodes and modules
- Create aliases of variable nodes
- View the results of two variables simultaneously
Before starting this chapter you should know how to perform the following actions which will no longer be described in detail:
Create a new model; Open an existing model; Save; Save As... (See Tutorial: Open a model to browse)
Create and define new variables; Enter attributes in Attribute or Object windows; Draw influence arrows between nodes. (See Tutorial: Create a model)
You should also be familiar with Array variables and Index variables. (See Tutorial: Arrays)
Using the Time index
In this model you will set up a dynamic system to model a predator/prey relationship. The populations of foxes and hares will be set up as state variables: one-dimensional arrays indexed by Time.
Start by opening a new model and titling it Foxes and Hares Tutorial. Create a general variable titled Hare population.
Notice that Time is listed as one of the indexes in the left hand window. You did not have to define this index before using it. Time is a system index in Analytica that is always available to you. Note that it is distinguished by the system variable icon (). Although it is a system variable, the values of Time can be edited just like any other index.
Analytica will show an edit table for the Hare population variable. Notice that the default index values for Time are 0,1, and 2. You will need to have more than just three time points in your dynamic simulation.
Press OK when asked to replace the current definition with a sequence.
Edit the sequence by keeping 0 for the start value and entering 10 for the end value. Click OK to exit the Object Finder dialog.
If the edit table for Hare population is not already open select the Hare population node and click on the Result button (). Notice that our time index now goes from 0 to 10. We will leave the values of the Hare population zero the moment.
Setting up the Hare sub-model
Create three new general variables titled Initial hare population, Hare fertility, and Hare births. Draw influence arrows as follows:
- from Hare fertility to Hare births
- from Initial hare population to Hare population
- from Hare population to Hare births
Define Initial hare population as 500. Change its Identifier to Hare_zero.
Define Hare fertility as 60%. We will take this to mean that the number of newborn hares will be equal to 60% of the total population during the previous time period!
Define Hare births as
Hare_population*Hare_fertility. This is the total number of births during a time period.
Using the Dynamic() function
Now we consider how the hare population will develop over time. The hare population will be influenced by the number of hare births, which will be influenced by the hare population during the previous period. Ultimately the value of Hare population depends on the value of itself during the previous time period. We can address this situation using the Dynamic function.
Delete the existing table expression and replace it with the following:
The Dynamic() function can be entered directly as an expression or accessed as a built-in function (by selecting Other... in the Expression popup menu). It is listed under the Special library heading.
Note that the Dynamic function automatically incorporates the Time system variable. It was not necessary to initially define our variable as a table indexed by Time, although this step was included in the first section of this chapter to illustrate the Time index.
This is a simple exponential growth curve. It represents a rapidly multiplying population of immortal hares with no natural predators and an unlimited food supply. You will need to introduce a limiting factor to avoid this buried-in-bunnies scenario.
Completing the Hare sub-model
Quickly before it’s too late, create four new general variables as follows:
Finally you need to change the definition of Hare population as follows:
Dynamic(hare_zero, self[time -1] + hare_births[time - 1]- hare_deaths[time - 1])
Now we have accounted for mortality and limited food supply by introducing a crowding factor. When the crowding factor is equal to one, the hare population has reached the carrying capacity for the habitat. At this point the death rate will be equal to the birth rate.
Using the color palette
In order to make an influence diagram easy to understand it is often useful to color code nodes according to function. The color palette is used for this purpose. You can access it in two ways:
- Right-click the node and select Show/hide color palette from the context menu
- Go to the Diagram menu and select Show/hide color palette
In the color palette you can select from standard colors or click Other... to select from the entire 24-bit RGB color space.
Creating a module
Modules are an important feature of Analytica. They allow you to place a collection of nodes inside a single object, a module, which has the appearance of a single node. In this way, the top level of your diagram can be a simplified view showing influence arrows between modules. Each module can be opened as its own diagram window to show detailed interactions of the variables inside. Modules can even be placed within modules to create a nested hierarchy of detail.
Creating a new module is just like creating a variable node. Drag the Module node from the node palette to the diagram window. A module looks similar to a node but it has a thick border around it and displays the title in bold print. Whereas double-clicking a variable node will open an Object window, double-clicking a module will open a new diagram window. Attributes for the module can be entered using the Attribute window at the bottom of the diagram. Your new module will have the following attributes:
- Title: Hare module
- Identifier: Hare_module
- Description: A dynamic sub-model of the hare population
To populate your new module, start by making a multiple selection of all the nodes except for the module itself.
Reminder: To make a multiple selection hold down the Control or Shift keys, or drag a rectangular frame around the nodes you want to select.
Your top level diagram should now contain just the module by itself. Double-click the module to see the variables in a separate window.
If a single diagram window takes up the entire workspace press the maximize/un-maximize toggle () near the upper right corner of the window.
Duplicating a module
Now you will make a similar sub-model for the fox population. Since the basic structure will be similar to the hare sub-model, you can save time by duplicating it automatically.
Edit the Title and Identifier of the duplicate to read Fox module
Edit the Description attribute to read A dynamic sub-model of the Fox population
The diagram appears to be identical to the original but you will notice some important differences in the Identifiers. Open the Attribute window and check the identifier for the Hare population node. Notice it has been changed to Hare_population1. Analytica has appended the 1 to ensure that the identity of the new variable is distinct from the original. Different variables are allowed to have identical titles but they must always have different identifiers
Identifiers in functional expressions are modified accordingly. This ensures that the duplicate variables belong to a self-contained group that does not interfere with the original variables.
Drag one of the selected nodes to the module and release.
Completing the Fox sub-model
Edit the titles and identifiers in the fox module as follows: (These edits mostly involve substituting the word Fox for Hare.)
Change the definition of input variables as follows:
- Initial Fox population: 120
- Fox fertility rate: 35%
- Fox carrying capacity: 200
The fox population is now a self-contained sub-model. Select the Fox population variable and click on the Result button (). Or you can hover over the node and click on the result hover icon.
Although it is useful to organize a model with modular structure, accessing variables inside modules can be less convenient than having them all in the same window. To address this problem Analytica allows you make an alias of a variable and place it anywhere you wish. The alias provides local access to the variable but it is merely a representation, not a duplicate, of the original node.
In this case it will be convenient to access the Hare population and Fox population nodes on the parent diagram without having to open the modules.
Select the Fox population variable. Go to the Object window and select Make alias. The alias looks similar to the original node but the title will be shown in italics. Drag the Fox population alias to the parent diagram.
Repeat the same procedure to create a Hare population alias on the top diagram.
Drawing influence arrows across modules
Now you are ready to introduce predatory interaction! Create a new general variable titled Predations. This will represent the number of hares eaten by foxes in a given time period. The predation level is assumed to be proportional to the product of fox and hare populations.
Draw influence arrows from the Hare population alias to Predations, and from the Fox population alias to Predations. Enter the following expression to define the new variable:
Hare_population*Fox_population / 600'
Unfortunately for the hares, each predation will count as a death for their team. Open the Hare module and arrange windows so that the Hare module diagram and its parent diagram are both visible. Draw an influence arrow from Predations to Hare deaths.
Re-define Hare deaths as:
Hare_population*Hare_ndr + Predations
If you look closely at the Hare population and Hare deaths nodes you will notice small arrowheads on the margins. These indicate influence relationships with other nodes outside the module.
Predations are a food source for fox population and have a positive effect on their numbers. This can be modeled by making the Fox carrying capacity proportional to the Predations variable.
Re-define Fox carrying capacity as: Predations*1.6
Analytica will allow you to use a variable in an expression before drawing its influence arrow. The variable will not be listed in the Inputs popup menu so you must type the exact identity correctly. Influence arrows will automatically be drawn after you finish editing the expression.
Viewing multiple results simultaneously
Your model is now complete. Click the Diagram button () to open the top diagram. As you already know, you can view the results of the fox and hare populations separately by selecting either one of the population aliases and clicking the Results button (). But there is an easy way to combine both variables on the same graph. Select both alias nodes simultaneously (holding down the Control or Shift keys while selecting). Now when you click the Results button a dialog box will appear asking if you want to add a node to your model with this comparison. Click Yes and Analytica adds a new node to the diagram with the comparison, and display its result window. A comparison node is essentially a list variable with the variables to be compared as elements of the list.
The default title in this case will be Compare1.
The result window for Compare1 will contain information from both of the selected nodes. Switch to the Graph result, and choose Time as the horizontal axis in the Result window of Compare1. You can now see the result of the predatory interaction.
Foxes and Hares Act III
How does the Fox/Hare drama end? You can extend the simulation by simply adding more values to the Time index.
Go to the Definition menu and select Edit time. Extend the sequence to go from 0 to 100, and click the green check button to accept the new definition.
Now you can experiment by changing input values to see how they impact the result.
If you would like to see a more complete Foxes and Hares example, open Foxes and Hares.ana in the Tutorial Models folder.
In this chapter you have:
- Used the Dynamic() function to model a feedback loop in a dynamic system.
- Edited the system variable Time which is used as an index in the Dynamic() function
- Customized the appearance of nodes using the Color palette
- Grouped nodes into Modules
- Used the Duplicate command to create a new module with similar structure to the original
- Created aliases for convenient access to nodes contained within modules
- Established influence relationships between modes in different diagram windows
- Created a comparison node to view the results of two variables simultaneously.
- Play the Foxes and Hares model in Analytica Cloud Player
- Creating the Foxes and Hares model (based on chapter 7 of tutorial)
- Dynamic Simulation
- Expand your model
- Combining models into an integrated model
- Example Models
- Example Models and Libraries
- Modules and Libraries
- Draw arrows between modules
- Drawing arrows between variables in different modules
- Create and edit nodes
- User input nodes and user output nodes
- Alias nodes
- Node Style dialog
- Diagram Style dialog
- Color in influence diagrams
- Comparing results
- Tutorial videos