Upcoming SlideShare
×

# ICPSR - Complex Systems Models in the Social Sciences - Lab Session 9 - Professor Daniel Martin Katz

932 views
811 views

Published on

Published in: Education, Technology
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
932
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
50
0
Likes
1
Embeds 0
No embeds

No notes for slide

### ICPSR - Complex Systems Models in the Social Sciences - Lab Session 9 - Professor Daniel Martin Katz

1. 1. Introduction to Computing for Complex Systems (Lab Session 9)
2. 2. Goals For Today Quick Overview of System Dynamics Quick Overview of NOVA Programming Concepts Simple Population Growth Model
3. 3. System Dynamics Modeling
4. 4. System Dynamics Modeling Professor Forester also responsible for inventing random-access magnetic-core memory (RAM) In 1950‘s Jay Forester of MIT Business School applied ideas in engineering to study business dynamics
5. 5. Feedback Effects System Dynamics is interested in systems that feature feedback effects Feedback = the return to the input of a part of the output (can be +, - or 0 )
6. 6. negative feedback negative feedback --> negative if the resulting action opposes the condition that triggers it This class of feedback is often described as auto- regulating in so much as deviations from the equilbriua are dragged back
7. 7. System Dynamics positive --> if the resulting action builds upon the condition that triggers it These are the more interesting class Perturbations to the system can generate a novel set of outcomes
8. 8. An Example of Feedback A positive connection: “The positive connection for a cooling coffee cup implies that the hotter the coffee is the faster it cools. The variables Tc and Tr are coffee and room temperature respectively.” For Full Example: http://serc.carleton.edu/introgeo/models/ loops.html
9. 9. a negative connection: “the negative connection in the figure below for a cooling coffee cup implies a positive cooling rate makes the coffee temperature drop.” For Full Example: http://serc.carleton.edu/introgeo/models/ loops.html An Example of Feedback
10. 10. An Example of Feedback the two connections are combined yield a negative feedback loop coffee temperature approaches the stable equilibrium of the room temperature. going around the loop the positive connection times the negative connection gives a negative loop feedback effect.
11. 11. System Dynamics System Dynamics Models are typically represented by stocks and flows http://www.systemdynamics.org
12. 12. Basic Ideas, Basic Ingredients
13. 13. Basic ideas, Basic Ingredients •  Like agent based modeling, system dynamics modeling is another method used to study the behavior of complex systems.
14. 14. Basic ideas, Basic Ingredients •  The dynamics of these systems are generated by the interdependent nature of their parts, especially concerning the role of feedback loops between entities that change over time, and the various relationships that affect the rate of change over time.
15. 15. •  The relationships described by system dynamics models offer us a better picture into how these systems often exhibit nonlinear behavior and produce emergent phenomena. Basic ideas, Basic Ingredients
16. 16. Basic ideas, Basic Ingredients •  System dynamics models are distinguished by the use of stocks, flows, feedback loops.
17. 17. Basic ideas, Basic Ingredients •  Stocks are things that either accumulate or deplete over time, but which at any given point in time can be measured. •  Flows are measured over a period of time; they represent the rate of change in a stock.
18. 18. Example: Simple Population Growth •  Let’s take a quick look at what a system dynamics model would look like before we build some for ourselves. •  Let’s model a population that grows, but has no outlet for depletion.
19. 19. Example: Simple Population Growth •  First, we will need an accumulator, a stock. Let’s call our stock “Population,” since a population is something that can be measured at a given time, but which can also grow or decrease over time.
20. 20. Stock: Population
21. 21. Example: Simple Population Growth •  Now we will want to manipulate our stock over time. Let’s add a flow coming into our stock so that we can put new things into it over time. Since we are not going to remove things from our stock, there is no reason to place a flow leaving the stock.
22. 22. Adding an In Flow
23. 23. Example: Simple Population Growth •  You may have noticed the hour glass shaped object on the inflow. Stock and flow diagrams often use this symbol to represent a valve controlling the rate of flow into or out of stocks.
24. 24. Flows represent the rate of change
25. 25. Example: Simple Population Growth •  Let’s call our flow “Growth.” This will represent the amount of new population members flowing in to the population during each time step.
27. 27. Example: Simple Population Growth •  To finalize our model, we will want to inform the growth flow of the prior population size as well as the current rate of growth. •  After adding those last elements we will have finished our qualitative description of a simple population growth model!
28. 28. Simple Population Growth
29. 29. •  System dynamics modeling programs allow us to mathematical define the relationships between our stocks and flows, allowing us to simulate model runs and see what occurs in the system when we tweak parameter and variable values. Basic ideas, Basic Ingredients
30. 30. •  The program we will be using to create system dynamics models is called NOVA. Introduction to NOVA
31. 31. http://www.novamodeler.com/
32. 32. http://www.novamodeler.com/
33. 33. http://www.novamodeler.com/
34. 34. Introduction to NOVA •  “Nova is a dynamic modeling platform that supports and encourages hierarchical design. Through hierarchical design, Nova combines the dynamic systems (DS), spacial and agent-based modeling paradigms.” http://www.novamodeler.com/
35. 35. Introduction to NOVA •  NOVA is being developed by Professor Richard Salter of Oberlin College •  NOVA takes an interesting approach to system dynamics modeling by enabling modelers to easily create sub-procedures that are also system dynamics models.
36. 36. Introduction to NOVA •  This features gives modelers flexibility and scalability in modeling dynamic relationships between different interacting systems as well as the ability to quickly duplicate dynamic systems of interest, either in a higher level of the same model, or in other models.
37. 37. Introduction to NOVA •  Like writing good modular code in Netlogo or other programming languages, the sub- models of NOVA provide an excellent way to organize models and allow users to utilize relevant sub-procedures of other models within their own programs.
38. 38. Quick Overview of Nova Concepts •  Helpful Sites: •  The following website features explanations of NOVA modeling components, as well as tutorials. •  https://sites.google.com/a/oberlin.edu/ nova-help/
39. 39. Quick Overview of Nova Concepts •  Helpful Sites: •  The following website features several NOVA models that can run through Java Web Start. •  https://sites.google.com/a/oberlin.edu/ nova/00-nova-concepts
40. 40. Quick Overview of Nova Concepts •  Let’s go through a quick run down of some of NOVA’s components before we build a model of our own. •  First, open the Nova.exe application file in your Nova_Windows folder.
41. 41. Open Nova Application
42. 42. Quick Overview of Nova Concepts •  You should now have an open window; the large empty area on the left is known as the canvas, which is where models are built •  As we will see later, the boxes to the left are where the main model and sub-models are located
43. 43. Quick Overview of Nova Concepts •  Let’s look at where we will locate the many of the things needed to build system dynamics models. •  There are three buttons on the top right that we should look at: Components, Plugins, and the Simulator
44. 44. First Click on Components
45. 45. Components •  The components contain the building blocks of the models, such as the stocks and flows •  It also contains items unique to NOVA, such as the cell grid, which creates a homogeneous multidimensional array of submodels that can interact with each other.
47. 47. Plugins •  The next button to look at is the Plugins. •  This contains the different types of GUI’s that we will use to visualize our models with. •  Plugins can also be developed and specialized for a user’s model and added to NOVA’s Plugin directory.
48. 48. Plugins •  Plugins can also be developed and specialized for a user’s model, as well as added to NOVA’s Plugin directory. •  Not all Plugins deal with visualizations, for example, one creates histograms.
50. 50. Simulator •  Finally, let’s investigate the Simulator •  The simulator offers several different means of operating model runs.
51. 51. Clock •  The first way to run a model is to use clock. •  It allows users to start a model run, pause it, stop it, reset it, speed it up or slow it down, and also turn looping on and off.
52. 52. Auto •  The second way to run a simulation is through Auto mode, which reruns the simulation any time there is a change of input using a slider or spinner. •  This is highly useful when you want to visually see what changing a given parameter can do.
53. 53. Repeater •  Finally, the Repeater is used primarily for sensitivity analysis, to create multiple runs with varying parameter values.
54. 54. The Simulator
55. 55. Model Library •  You can find other NOVA models in the NOVA model library, which is under File > Browse Model Library
56. 56. NOVA Help •  If you forget what a component or plug-in does, just left click it and then press ‘F1.’ •  This will bring up the NOVA help website which will explain what that component does.
57. 57. Applying Model Building Principles Across Different Platforms
58. 58. This ought to look familiar… •  Although system dynamics provide a different way of approaching complex systems, many of the lessons you have learned so far about programming agent based models in Netlogo should readily apply, especially in the NOVA environment.
59. 59. This ought to look familiar… •  For example, let’s look at the flocking model, found in the NOVA Model Library under the Agent-based model section. •  Since it is a new environment, it is not surprising that the model may at first look strange and intimidating…
60. 60. Applying Model Building Principles Across Different Platforms •  However, I think if you take a closer look, you’ll start to see some similarities…
61. 61. NOVA
62. 62. Netlogo
63. 63. NOVA
64. 64. Net Logo
65. 65. Applying Model Building Principles Across Different Platforms •  You’ve mapped the dependencies in the code of the flocking model of Netlogo before, so I think you can see that while there are differences, some basic principles can be applied across different modeling platforms!
66. 66. Similarities Across Programs •  In Netlogo, there are sub-procedures to handle a bird’s aligning, cohering, or separating, •  As you saw, there are similar dependencies in the NOVA system dynamics model version.
67. 67. Similarities Across Programs •  Although the flocking model is an advanced model, your prior experience with it in Netlogo should make what once looked strange and unfamiliar seem much more manageable.
68. 68. Modular Coding and Hierarchical Systems •  Another thing to note is that NOVA’s hierarchical design works just like modular coding in Netlogo. •  Even better, as we will see when we construct our own NOVA model, NOVA allows you to literally drag and drop sub- models into other models.
69. 69. Modular Coding and Hierarchical Systems •  The drag-and-drop feature is just like adapting already existing code in Netlogo to your own modeling needs. •  If you needed the “Mover” sub-model in the NOVA flocking model, which converts polar coordinates to rectilinear coordinates, you can copy it to your own model.
70. 70. Modular Coding and Hierarchical Systems •  You do not need to reinvent the wheel.
71. 71. Building Our Own Model •  Now we are ready to build our own system dynamics model in NOVA. •  Since we have already conceptually mapped what a simple population growth model would look like, why don’t we expand upon that and see what implementing a system dynamics model looks like!
72. 72. Building the Simple Population Growth Model
73. 73. Building Our Own Model •  If you haven’t done so already, let’s get a clear NOVA canvas to work with. •  Go to File > New Project to bring up a blank page to work with.
74. 74. File > New Project
75. 75. Building the Model •  As you remember from before when we conceptually built the simple population growth model, we know that we will need a stock for population, a flow for growth, and parameters that will tell the model what the growth rate is at any given time.
76. 76. Building the Model •  Let’s get components for our model. •  Please click on the Components button on the top right of the screen to access the Components Menu.
77. 77. Building the Model •  We are going to want to get a stock. •  Stocks are represented by the green square in the first top left button in the Components menu.
78. 78. Building the Model •  Now that you have pressed stock, click on any clear section of the NOVA canvas. •  The program will ask you to name the stock. Please name it “Population”
79. 79. Building the Model •  If you do not give a Stock a name, NOVA will assign it the name “Stock 0.” This is true for other component types as well. •  If you need to rename a component, just double click on the name (not the component, just the name tag).
80. 80. Building the Model •  You should now have a stock called “Population.”
81. 81. Building the Model •  The next thing we need is a flow. Click on the flow button, which is the button on the very top far right that looks like a yellow hour glass. •  As we mentioned before, it represents a valve controlling the rate of the flow.
82. 82. Building the Model •  Now click somewhere to the left of the population stock. •  Next, NOVA will ask you to assign the flow a name. Give the flow the name, Growth.
83. 83. Building the Model •  You should now have something that looks like this:
84. 84. The Select, Resize, & Move Arrow •  Before we move on, it would be a good thing to learn about an arrow you can use to select and move components with. This arrow is on the top right, next to the blue question mark and green ‘i’ button.
85. 85. The Select, Resize, & Move Arrow •  By forming a rectangle completely around any component you wish to move, this arrow will allow you to move any object or objects you wish.
86. 86. The Select, Resize, & Move Arrow •  The objects will become black when they are selected. While they are this color, you may move them.
87. 87. Another Way to Move Objects •  Even without the move arrow, you can simply click on a component once to move it. Like with the move arrow, after a single click, the object will turn black.
88. 88. The Select, Resize, & Move Arrow •  Sometimes, when you are selecting components, you might forget that you still have a component button turned on, and this will cause you to accidently put down components. •  The Select & Move arrow is a good ‘neutral’ position to be in to stop that from occurring.
89. 89. • Back to our model…
90. 90. Building the Model •  Again, you should now have something that looks like this:
91. 91. Building the Model •  The next step is to connect the Growth Flow rate to our population stock. •  However, first we should look inside the flow rate, to see how flow rates work, and to make the flow rate uniflow (since it will only be moving in one direction, into the stock.)
92. 92. Building the Model •  Right-click on the valve of the Growth Flow rate, you should get the following interface:
93. 93. Building the Model •  This is where you will be able to define the mathematical relationships between stocks and flows. •  You can see that on the bottom left, there is a list of programming code that is native to NOVA, just like the ‘primatives’ of Netlogo.
94. 94. Building the Model •  The box on the top right will be where other variables and parameters that affect the rate of the flow will show up. •  This will you will know what needs to be accounted for when you write out the equation detailing how the flow will influence your stock.
95. 95. Building the Model •  The large box in the top middle is where the code will be written. •  Just to give a hint of what is to come, in order to model population growth we will have to come up with an equation using the following terms: current population and the current growth rate.
96. 96. Building the Model •  Finally, the bottom middle box is for comments. •  Just like commenting in Netlogo was not used by the program, anything written here is for users to see only, and will not alter the operation of the model in any way.
97. 97. Building the Model •  Under the comments box you will see two options, Uniflow and Biflow. •  Select Uniflow and then press OK.
98. 98. Building the Model •  Now we will connect our Growth Flow to our Population Stock. •  First double-click on the right-hand cloud. You should see a blue dotted line that follows your mouse wherever it goes.
99. 99. Building the Model •  The blue dotted line is ‘sticky,’ it will not let go of your mouse until it is stuck onto a stock. Right now, that is exactly what we want. However, sometimes, especially if you double click a cloud by mistake, this can be a nuisance.
100. 100. Building the Model •  As mentioned earlier, selecting the Select and Move arrow is a good way to get out of such jams. •  Another way is to click the bottom right edge of the components or plugins box. This will get rid of the sticky blue dotted line, as well as other component buttons.
101. 101. Building the Model •  Now we will connect the flow to the stock. •  Double-click the right-hand cloud again and drag the blue dotted line to the population box. Once there click the population stock.
102. 102. Building the Model •  Your model show look like the following:
103. 103. Building the Model •  Now our flow is connected to our stock! •  We now have a stock, and something to change the stock.
104. 104. Building the Model •  Since we are building an exponential growth model, we need to inform the flow of the existence of the current population, since the current growth rate is dependent upon the current population size.
105. 105. Building the Model •  This is done by ‘adding arrows,’ which connect an information source to another component that needs the information.
106. 106. Building the Model •  Go back to the components menu and select the red arrow button •  It is on the left hand column of the 2nd to the top row.
107. 107. Sticky Lines! •  WARNING! •  Red arrows are sticky too. If you need to get out of red arrow mode, just select the select and move arrow, or click the bottom right edge of the components menu.
108. 108. Building the Model •  Once you clicked the red arrow, click on the Population Stock. There should now be a red dotted line following your mouse coming out of the stock.
109. 109. Building the Model •  Drag your mouse, and the red dotted line, to the yellow valve on the Growth Flow and click it. There will not be a red arrow pointing from the Population Stock to the flow.
110. 110. How do I get Rid of Red Arrows? •  If you have a red arrow you don’t like, just click off the red arrow (by clicking the bottom right edge of the components menu) and then click the circle on the end of the red arrow. •  It will turn the arrow black, and you can either move the arrow or delete it.
111. 111. Building the Model
112. 112. Building the Model •  Now we need a rate of growth. •  We will allow the user to select what the rate of growth will be, so we want to use a component that allows for user input.
113. 113. Building the Model •  Go back to the components menu and select the button in the middle column of the second to the top row. This button looks like a red arrow pointing away from the left.
114. 114. Building the Model •  This is a data input button. •  We are actually creating the sub-model of our main model right now. The rate of growth slider will be in the main model’s interface, and this input button brings in the information into the sub-model.
115. 115. Building the Model •  Call the Data Input button ‘rate.’ •  Now we want to connect the rate to the Growth Flow. •  Go back to the components menu and get a red arrow and connect it to ‘rate.’
116. 116. It Should Look Like This
117. 117. Building the Model •  Now connect the red arrow to the yellow growth valve. Now we have information about the current population size and the rate of growth going into the flow.
118. 118. NOW Time to ADD THE MATH … J
119. 119. It’s Getting Serious Now •  Right-click once on the yellow valve on the Growth Flow. •  This will take you back to the Flow Interface. •  We are going to add an equation in the large box in the middle.
120. 120. Building the Model •  Notice how the stock and data input are now in the box on the top left. •  That is because the red arrows are pointing to the flow.
121. 121. Building the Model •  You can now either write “rate * population” •  OR •  You can click rate in the top left box, type *, and then click population. Clicking them ensures you won’t misspell anything.
122. 122. It Will Look Like This:
123. 123. Building the Model •  If you misspell a word, the flow’s name becomes red.
124. 124. Building the Model •  We would also like to add an initial population, especially one that the user could select. •  In order to do that we return back to the components menu, and select the Data Input button again.
125. 125. Building the Model •  This time, click on a clear spot on the canvas and name the Data Input, “Initial Population” •  Go back to the components menu and select the red arrow, click it on the Data Input, “Initial Population,” and then connect that arrow to the Population Stock.
126. 126. Here’s What It Should Look Like
127. 127. Building the Model •  Once you have clicked out of red arrow mode, go back and left click the Population Stock. •  This will bring up the Stock Interface. Click on Initial Population in the top left hand box, so that Initial Population then appears in the top middle box.
128. 128. Building the Model •  Click on Initial Population in the top left hand box, so that Initial Population then appears in the top middle box. Then click OK to get out of the interface.
129. 129. Building the Model •  The next step is to bring the current population information into the main model interface. •  Just as Data Input buttons are used to bring information from the main model to the sub- model, we will bring the information to the main model from the sub-model with a Data Output button.
130. 130. Building the Model •  Go back to the components menu, and select the button in the right hand column of the 2nd to the top row.
131. 131. Building the Model •  Click somewhere to the right of the population stock and name the Data Output, “pop”. •  Then get a red arrow, connect it to the Population Stock, and connect the arrow to the Data Output, “pop.”
132. 132. Our Sub-Model Is Almost Done
133. 133. Building the Model •  There is only one more step before our sub-modal is finished. •  Right-Click on the data output “pop”, and write “Population” in the Data Output Interface Coding box (the one in the middle on the top). This sets “pop” to “Population,” our stock.
134. 134. Building the Model •  That’s it! Now the stock’s value will be outputted to the main level of the model. •  Now we will create the main level so that we can create the sliders and the GUI.
135. 135. Finished Sub-Model
136. 136. Building the Main Model •  To create the main level of the model, we need to click the yellow paper button on the top left.
137. 137. Building the Main Model •  It will ask you to name the sub-model. Call it “Simple Population Growth”
138. 138. Building the Main Model •  Now there is probably a blank screen. This is the higher level of the model. It has not yet been made.
139. 139. Building the Main Model •  You’ll see the sub-model in the bottom left box. Click on the name and you’ll get our sub-model.
140. 140. Building the Main Model •  We can give our main model a title. Just right click on “Untitled” and give it the name “Population Model”.
141. 141. Building the Main Model •  Now click on “Population Model,” the main model. •  We are about the drag-and-drop our sub- model into the main model.
142. 142. •  Click, AND HOLD, the sub-model’s name in the bottom left box (Simple Population Growth), and drag your mouse, while holding down, until you get into the empty canvas. Now drop. •  You now have the sub-model embedded as a chip inside the main model. Building the Main Model
143. 143. Drag-and-Dropping the Sub- model
144. 144. Seeing the Sub-Model from the Main Model Level •  To see the sub-model, just press Shift + right click and press on the chip.
145. 145. Building the Main Model •  Did you see the little red things sticking out of the chip? Those are the two data inputs and the one data output! •  They are called pins, and they communicate with the sub-model.
146. 146. Building the Main Model •  Which means we need sliders for the data inputs. •  Go to components and select the slider (its on the left hand side, 4th row down).
147. 147. Building the Main Model •  Once you selected slider, click somewhere clear on the canvas and name the slider, “rate”.
148. 148. Building the Main Model •  The slider goes between 0 and 100. •  Those are bad values for a growth rate. •  Right click the bottom right edge to get the slider interface, and change the high value to 2.0.
149. 149. Building the Main Model •  Create another slider and call it “Initial Population.” •  You can leave the range between 0 and 100.
150. 150. Building the Main Model •  However, we cannot have fractions of people in the initial population. •  Right click on the bottom right edge of the slider to change the decimal place to 0.
151. 151. Building the Main Model •  We can now assign the sliders to the input pins in out sub-model chip in the main model. •  Go ahead and right click on the sub-model chip and an interface will appear.
152. 152. Building the Main Model •  Go ahead and assign the input “rate” to “rate” in the draw down menu, and the input “Initial_Population” to Initial Population in the draw down menu. •  These connect the inputs in the sub-model to the main model’s sliders. No red sticky arrows needed.
153. 153. Our Main Model, so far
154. 154. Our Model, so far •  Our sub-model calculates the new population is each time step, and with the new sliders, we are able to input an initial population, and a current population growth rate. •  All we need now is a graph!
155. 155. Getting the Graph •  Go to the components menu and select the ‘add graph’ button, located on the left- hand side on the 2nd to the bottom row.
156. 156. Getting the Graph •  Now add the graph somewhere to the right of the sub-model chip. •  Name the graph, “Population.”
157. 157. The Graph, Population
158. 158. Getting the Graph •  We need to configure the graph. •  Right click on the right bottom edge of the graph to pull up the graph interface.
159. 159. Getting the Graph •  As you can see, the interface wants us to now select what we want to graph. •  In the left-hand “Select Contents,” there is an option labeled, Simple Population Growth_0.pop •  Clearly, that is what we want to select, but why?
160. 160. Getting the Graph •  Simple Population Growth is the name of the sub-model. •  The “.pop” refers to the output pin, which you will remember we named, “pop.”
161. 161. Sub-Models Can Be Used by Multiple Chips, Multiple Models •  It is assigned the number zero because that is the name of the chip in our interface. We could create another chip, and then we would have two models, each using the same sub-model, but we could supply different sliders in order to provide different values.
162. 162. Getting the Graph •  We can give an alias what we are graphing by selecting Simple Population Growth_0.pop, and then writing an alias in the Alias box, and pressing Set. •  Name the alias, “Population Model”
163. 163. Getting the Graph
164. 164. Our Model Output! A Success!
165. 165. The Finished Product •  Our model now is fully linked up to the graph, and therefore has a complete two- tiered hierarchical system dynamics model of exponential growth!
166. 166. The Finished Product
167. 167. Running the Simulation •  Now go to the Simulator and select Clock •  As we said earlier, Clock runs for a period of time given certain parameters. •  Go ahead and run the model with different parameters
168. 168. Running the Simulation •  You can also select Auto in the Simulator. •  Auto will automatically update when you change parameters •  Go ahead an run a few different parameters using Auto
169. 169. A Word of Advice •  While not so important with graphs, be careful about fussing too much with the GUIs while they run. •  It can cause problems.