Upload
daniel-martin-katz
View
1.468
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
Introduction to Computing !for Complex Systems!
!
(Bonus Online Content)!
Daniel Martin Katz!Michigan State University!
System Dynamics Modeling!
System Dynamics!
Just want to give you a quick taste !of the ideas !
System Dynamics!
System Dynamics has a long history !
In 1950‘s Jay Forester of MIT Business School applied ideas in engineering to study business dynamics!
Professor Forester also responsible for inventing random-access magnetic-core memory (RAM)!
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 )!
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 !
positive --> if the resulting action builds upon the condition that triggers it!
These are the more interesting class of effects !
Perturbations to the system can generate a novel set of outcomes!
Positive feedback !
An Example of Feedback !
A positive connection: !”!
For Full Example: http://serc.carleton.edu/introgeo/models/loops.html
!“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.
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 !
An Example of Feedback !
the two connect i ons 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. !
System Dynamics!System Dynamics Models are typically represented by stocks and flows!
http://www.systemdynamics.org!
System Dynamics!
Exponential Growth!When you open exponential growth!
two windows will open!
Exponential Growth!
If you double click these variable windows will open !
System Dynamics!
System Dynamics Version !of the Wolf Sheep Model!
You can explore the netlogo version of system dynamics !
However, if you are really interested in system dynamics you f i nd a lternat i ve s o f t w a r e t o b e easier !
Some of the Alternative Software Platforms !
http://www.iseesystems.com/softwares/Education/StellaSoftware.aspx
http://www.vensim.com/software.html
http://www.berkeleymadonna.com/
Vensim !
You can start with the free download: !
If this works well you can by an academic license for $89!
http://www.vensim.com/download.html
http://www.vensim.com/cgi-bin/ecom.exe
To Learn More about !System Dynamics !
http://www.shodor.org/tutorials/vensim/
http://www.shodor.org/talks/ncsi/vensim/
Shodor also has a useful collection of sample models: !
Shodor is a national resource for computational science educat ion . The Shodor Website has a really nice Vensim tutorial:!
The Advanced SIR Model !
http://www.shodor.org/talks/ncsi/vensim/
To Run !the Model !
You can overwrite the file if you like !
The Advanced SIR Model !
http://www.shodor.org/talks/ncsi/vensim/
Move Around these Sliders !
The Advanced SIR Model !
http://www.shodor.org/talks/ncsi/vensim/
You can Right Click !!(ctrl+click for mac) !! !
To Learn More about !System Dynamics !
http://sysdyn.clexchange.org/road-maps/home.html
http://projects.ischool.washington.edu/ jscholl/Papers/DTABS01.PDF
!Nova: A Platform
for System Dynamics!
!
http://www.novamodeler.com/
http://www.novamodeler.com/
!Modifying the
Population Model!!
Modifying the !Population Model!
• Before we build more models, let’s take a quick look at the model we created in Session XIV.!
• If you no longer have access to that model, these slides should be sufficient to show you how you could go about modifying the model we built in class.!
Modifying the !Population Model!
!
• Our old model displayed a graph that showed exponential growth in one population and had sliders that gave users the chance to select the growth rate and initial population.!
Sub-Model!
Main Level!
Modifying the !Population Model!
!
• What if we wanted to compare populations with different initial populations and growth rates?!
• Would we have to create a whole new sub-model?!
Adding Another Population!
• Thanks to NOVA’s hierarchical modeling structure, we can simply ‘drag-and-drop’ another population, and connect that population to new sliders that will supply the values for that population’s growth rate and initial population.!
Adding Another Population!
• In fact, it’s a bit easier than that.!
• We can simply copy the sliders we already built as well as the population sub-model chip, and paste them below.!
Adding Another Population!
• In order to copy and paste, we would go to the select, resize, and move arrow, located above the modeling canvas.!
Adding Another Population!
• Then we would use the move arrow to select an area of the canvas fully encompassing the population chip model as well as the two sliders.!
• This will allow us to copy or move them.!
Copying the Old Population and Sliders!
Adding Another Population!
• After we copied the population sub-model chip and the sliders, we would simply paste the new population and sliders below.!
Pasting the New Population and Sliders!
Adding Another Population!
• As you can see, the new population sub-model chip was automatically named ‘Simple Population Growth Model 1’ to indicate that it is the second sub-model chip (the first was Model 0) to be calling upon the sub-model ‘Simple Population Growth’.!
Adding Another Population!
• Similarly, the rate slider and initial population slider also have a 1 next to their titles to indicate that they will be used for the second population sub-model.!
Adding Another Population!
• Still, we should check to see if the new sliders are connected to the new sub-model chip.!
• In order to see what is connected to a sub-model chip, we right-click the chip.!
Adding Another Population!
Adding Another Population!
• Our input data pins are already connected to rate_1 and Initial_Population_1, so we now have a working second population model.!
Adding Another Population!
• We could also switch the sliders that send information to the input data pins in the sub-model chips, so that rate_1 supplied information to the first population chip, while the first rate slider supplied information to our second population chip.!
The Graph!
• The only thing we need to do now is to connect the second population chip to the graph.!
• To do that, we would right-click on the bottom right edge of the graph. This will bring up the graph interface.!
The Graph Interface!
The Graph!
• We now see that there is something new located in the left-hand “Select Contents” box entitled ‘Simple Population Growth_1.pop’ !
The Graph!
• As we saw in class, this stands for the sub-model name, as well as a ‘_1’ to indicate that it is the second sub-model chip on the canvas, and that the information from that chip is being supplied to the graph through the data output pin located within the sub-model named “pop”.!
The Graph!
!
• Now we just need to select the second population’s name in the ‘Select Contents’ on the left hand side and use the arrows pointing to the right to bring it over to the right hand side.!
The Graph!!
• We can also give the second population an alias by using the ‘Alias’ box below the “Select Contents’ box on the right. !
• I will call the second population “Population Model 1” and set that alias so it shows up on the graph with that name.!
The Graph!
• Now we have two populations on the graph.!
• We can run the simulator with different values for each population and see them graphed next to each other. !
!Building the !
Forest Fire Model!!
Forest Fire Model!
• Now we are going to move onto something you will be familiar with if you looked at the other Netlogo focused sessions.!
!
• The forest fire model in Netlogo was a fairly short and simple program with one variable (forest density). !
Forest Fire Model!
• In NOVA, we will create a forest fire model using system dynamics principles and hierarchical modeling.!
!
Forest Fire Model!
• This model will show some of the interesting features available with NOVA’s plugins. !
• For example, we will give users the ability to select the initial state of every tree in the model by interacting directly with the GUI.!
Forest Fire Model!
!
• In the model we will build, each tree will be modeled through its own system dynamics process that will be located within a sub-model, similar to how the population chips were sub-models in our population model.!
Forest Fire Model!!
!
• The state of a given tree in each time step will be determined by the state of a tree’s neighbors.!
Forest Fire Model!!
• In NOVA, these types of models are called ‘cellular’ models, because each tree will be located within a grid, like patches in Netlogo, and each of the trees, or cells, in the grid will be allowed to interact with its neighbors.!
Forest Fire Model!
• Let’s go ahead and open up a new NOVA window so we can build the forest fire model.!
Building the Model!
• In a forest fire model, trees change between states such as unburned, burning, and burned.!
• The tree is therefore the thing that is changed over time and its state could be measured at any given point in time. Thus, it is our stock.!
Building the Model!
• Go to components and select stock.!
• Name the stock Tree.!
Modifying Our Tree!
• Now right-click on the stock “Tree” to get the stock interface.!
• Once there, check the discrete box and then press OK.!
Building the Model!
• Now we need something to change its state. This will be our flow.!
• Go back to the components menu and select the flow button. Place a flow somewhere to the left of the stock and name it “Change.” !
Building the Model!
• Once you have placed the flow down, connect the right-hand cloud to our stock.!
Building the Model!
• The next thing we will need is to give the model the probability of burning and give each tree its initial state.!
Building the Model!
• Select two data inputs and place them to the left of the flow. Name one “Prob of Burning” and the second one “Init” for initial state.!
Building the Model!
• We will also want to output the state of the tree to the main level of the model.!
• To do that, select a data output from the components menu and place it to right of the stock. Name the data output “state”.!
How It Should Look So Far…!
Building the Model!!
• Now we will want to wire them up.!
• Select the red arrow button from the components menu and connect an arrow running from “Prob of Burning” to the yellow valve on the flow “Change”.!
Building the Model!
• After that, use another red arrow to connect the stock “Tree” to the yellow valve on the flow “Change”.!
Building the Model!
!
• Use another red arrow to connect “Init” to the stock “Tree”.!
• Finally, use another red arrow to connect the stock “Tree” to the data output “state.” !
How It Should Look So Far…!
What The Red Arrows Tell Us!
• As you can see, Init will tell the tree what its state is in the first time step of the model, while Prob of Burning and the current state of the tree will be needed by the flow in order to tell the tree what state it should be in (for example, a burned out tree should never have the option of catching on fire again.)!
What The Red Arrows Tell Us!
!
• Just by looking at the diagram, we can clearly see that the new state of our tree will depend upon some function involving the probability of burning and the current state of the tree.!
Defining the States!
• Our model will be working with states that could simply be labeled with numbers such as 0,1,2, etc.!
• However, if we gave them labels, they would be much more easy to work with.!
Defining the States!
• Press on the lambda symbol located on the top left above the canvas.!
• You will get a blank space that will allow you to write some code.!
Defining the States!
• In that space type the following:!
(define unburned 0)!
(define burning 1)!
(define burned 2)!
(define state 2)!
It Should Look Like This!
Defining the States!
• Now when we need to refer to these states later on, we will be able to use these words rather than some numerical value.!
• It is important to note that these states will be available under the lambda symbol within the sub-model, not within the main model.!
Writing the Burn Procedure!
• The states that we just defined allow a tree to be either unburned, burning, or burned.!
• In our model, there will be some function that looks at the state of a cell’s neighbors and determine what state the cell should be in.!
Writing the Burn Procedure!
• Our trees will burn for one time step and then become burned.!
• A burned tree does not transform into an unburned tree, and only unburned trees can burn.!
Writing the Burn Procedure!
!
• Let’s go back to the canvas and right-click on the flow. The flow interface will pop up and allow us to write the procedure that will govern when a tree should change its state.!
Writing the Burn Procedure!
!
• Write the following code into the large top middle box:!
The Burn Procedure!
if Tree == unburned then!
"if NEIGHBORS(state, $==burning) > 0 then !
"if RANDOM(0,1) < Prob_of_Burning then!
" " Burning!
" "else unburned endif!
"else unburned endif!
else burned endif!
It Should Look Like This!
Dissecting The Code!
• The code you wrote contained some code that is native to the NOVA environment, like “primitives” in Netlogo, such as NEIGHBORS, RANDOM, and $.!
• These and other code native to NOVA are available in the bottom left of the interface.!
Dissecting The Code!
• In each time step the flow will ask if the current state of a tree is ‘unburned.’ If it is not unburned, the code will jump to the ‘else’ part of the if-else and make the state of the tree ‘burned.’ !
• Therefore a tree that is burning will only burn for one time step before becoming burned.!
Dissecting The Code!
• A burned tree will jump straight to the ‘else’ portion and remain burned.!
• An unburned tree must go through the rest of the procedure to determine its next state.!
Dissecting The Code!
• Once it is determined that a tree is unburned, it will take a look at its neighbors and report back if it is true that there are any neighboring cells that are in a state of ‘burning.’ ($ represents state.)!
Dissecting The Code!
• If it is true that there is at least one ‘burning’ neighbor, the unburned tree must continue on to the next ifelse conditional.!
• Otherwise it will remain unburned.!
Dissecting The Code!
• If there is at least one burning neighbor, then the procedure will flip a coin.!
• If the random number generator produces a number between 0 and 1 that is less than the probability of burning, then the tree will enter a state of “burning.” Otherwise it will not burn.!
Final Steps Of !The Sub-Model!
• Now we need to just add some finishing touches.!
• Right-click on the data output state and write “Tree” into it’s ‘state =’ box!
Final Steps Of !The Sub-Model!
• Then right-click on the stock “Tree” and write “Init” into its ‘Initial_Tree =’ box.!
Final Steps Of !The Sub-Model!
• Now we are done with the sub-model.!
• Let’s go to the main level and name our sub-model by pressing the yellow paper icon near the top left of the screen. When it asks what to name the sub-model, call it “Tree”.!
Building the Main Model!
• Like in the population model, we will drag-and-drop the sub-model into the main level’s canvas.!
• But we want to have more than one tree, so before you drag out the sub-model go to the components menu and find the button called “Cell Grid.” !
Building the Main Model!
• Go ahead and place the cell grid onto the canvas and call it “Forest.” !
Building the Main Model!
• Now we will drag-and-drop the sub-model into the cell grid.!
• Go ahead and click-and-hold on the sub-model title “Tree” and drag-and-drop it on top of the cell grid “Forest.” !
• Our cell grid is now a sub-model chip.!
The Cell Grid: Forest!
Building the Main Model!
• Right now, our forest has 9 trees in it, or 3 rows by 3 columns of trees.!
• We can change that to make it a much larger forest. Go ahead and right-click the lower right edge of the cell grid to bring up the cell grid interface.!
The Cell Grid Interface!
Building the Main Model!
• Let’s make a forest of 2500 trees. Change the rows and columns to 50.!
Building the Main Model!
• Now we need to build a slider to tell our model what the probability of burning is.!
• Select a slider from the components menu and give it the name, “Prob of Burning”. Make sure to right-click on it and change the range of values to between 0 and 1.!
Building the Main Model!
!
• Next, we need to connect our slider to the cell grid. Right-click on the lower right edge of the cell grid and select “Prob of Burning” from the menu for the first input.!
• Remember, since sliders don’t have pins, they do not need red arrow connections.!
The Cell Grid Interface!
Building the Main Model!
• Now we will want to select a GUI so that we can display our forest. Go to the Plugin menu and select the button on the bottom middle called Raster.!
Adding The GUI!
• Place the raster to the right of the cell grid and call it “Forest Display.” !
Adding The GUI!
• Right now our forest GUI is geared to display a 3x3 forest.!
• Right-click on the bottom right edge of the raster and then click “Properties” so we can access the raster interface.!
Adding The GUI!
!
• The raster interface will allow you to change the row and column numbers.!
• Change these to 50.!
Adding The GUI!
Adding The GUI!
• Next we have to program the colors for each state.!
• Change the number of colors to 3 and make the range go between 0.0 and 2.0!
Adding The GUI!
• Remember that in our states, 0 = unburned, 1 = burning, and 2 = burned.!
• So change the colors to match these numbers in the colors displayed on the right-hand side.!
• Do this by right-clicking on the colors.!
Changing The Colors!
Adding The GUI!
• Click OK to get out of the raster interface. You will now see that the display became green.!
Adding The GUI!
• Right now, rasters cannot be ‘wirelessly’ connected to cell grids so we will need red arrows to connect them.!
• Select the red arrow from the components menu and bring your mouse to the cell grid’s output pin located on the right. !
Adding The GUI!
• Connect the red arrow from the cell grid’s output pin on the right to the raster’s input pin on the left.!
User Selected Fires!
• You may have noticed earlier that we did not add a slider for the data input “Init”.!
• That is because while it is something we want the user to input on the main level of the model, we do not want the user to select these values from a slider.!
User Selected Fires!!
• Instead, the user will click on the forest GUI and select which trees will be either burning, burned, or unburned, by clicking individually on them once, twice, or three times (or leaving them in the default unburned state).!
User Selected Fires!
• We now need this user selected data to be feed back into our model.!
• Go and right-click on the cell grid and go to the “Init” pull down menu and select “Forest_Display.Out” !
User Selected Fires!
User Selected Fires!
• Now the user can select any initial pattern of initial burning trees they want, as well as create “walls” of unburned trees.!
Running the Model!
• Now we can run our model. Go to the simulator menu and in Off mode have the model go between 0 and 100 time steps, so the model will run long enough for the fire to move across the forest.!
Running the Model!
• Since this is a discrete model, go to the simulator menu and select for the Integration Method Euler. Also set Dt equal to 1.0.!
Running the Model!
• You can now select a few trees to set to “burning” and run your fire using Clock.!
• Remember not to fuss with the GUI too much while it is running.!