icpsr - complex systems computing - session 9 - 2012

Post on 29-Nov-2014

480 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

Introduction to Computing for Complex Systems!

Daniel Martin Katz! Eric Provins!

Goals For Today!

Quick Overview of System Dynamics!

Quick Overview of NOVA Programming Concepts!

Simple Population Growth Model!

System Dynamics Modeling!

!

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

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 !

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!

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

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 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. !

System Dynamics!System Dynamics Models are typically represented by stocks and flows!

http://www.systemdynamics.org!

Basic Ideas, !Basic Ingredients!

Basic ideas, Basic Ingredients!

• Like agent based modeling, system dynamics modeling is another method used to study the behavior of complex systems. !

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. !

• 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!

Basic ideas, Basic Ingredients !

!

!

• System dynamics models are distinguished by the use of stocks, flows, feedback loops. !

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.!

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. !

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.!

Stock: Population!

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.!

Adding an In Flow!

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.!

!

Flows represent the rate of change!

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.!

Growth Added!

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!!

Simple Population Growth!

!

• 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 !

!

• The program we will be using to create system dynamics models is called NOVA.!

Introduction to NOVA!

Introduction to NOVA!

•  “Nova is a dynamic modeling platform (currently under development) that supports and encourages hierarchical design. Through hierarchical design, Nova combines the dynamic systems (DS), spacial and agent-based modeling paradigms.” !

• http://nova.oberlin.edu/!

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.!

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.!

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.!

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/ !

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!

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.!

Open Nova Application!

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!

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!

First Click on Components!

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.!

Components Menu!

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.!

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.!

Plugins Menu!

Simulator!

!

• Finally, let’s investigate the Simulator!

• The simulator offers several different means of operating model runs.!

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.!

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.!

Repeater!

• Finally, the Repeater is used primarily for sensitivity analysis, to create multiple runs with varying parameter values.!

The Simulator!

Model Library!

• You can find other NOVA models in the NOVA model library, which is under File > Browse Model Library!

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.!

Applying Model Building Principles Across Different

Platforms !!

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.!

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…!

Applying Model Building Principles Across

Different Platforms !

• However, I think if you take a closer look, you’ll start to see some similarities…!

NOVA!

Netlogo!

NOVA!

Net!Logo!

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!!

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.!

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.!

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.!

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.!

Modular Coding and Hierarchical Systems!

• You do not need to reinvent the wheel.!

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!!

!Building the Simple Population Growth

Model!!

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.!

File > New Project!

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.!

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.!

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. !

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” !

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).!

Building the Model!

• You should now have a stock called “Population.” !

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.!

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.!

Building the Model!

• You should now have something that looks like this:!

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.!

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.!

The Select, Resize, & Move Arrow!

• The objects will become black when they are selected. While they are this color, you may move them.!

!

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.!

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.!

• Back to our model…!

Building the Model!

• Again, you should now have something that looks like this:!

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.)!

Building the Model!

• Right-click on the valve of the Growth Flow rate, you should get the following interface:!

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.!

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. !

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.!

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.!

Building the Model!

• Under the comments box you will see two options, Uniflow and Biflow.!

• Select Uniflow and then press OK.!

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.!

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.!

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.!

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.!

Building the Model!

• Your model show look like the following:!

Building the Model!

• Now our flow is connected to our stock!!

• We now have a stock, and something to change the stock.!

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.!

Building the Model!

!

!

• This is done by ‘adding arrows,’ which connect an information source to another component that needs the information.!

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.!

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.!

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.!

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.!

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.!

Building the Model!

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.!

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.!

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.!

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.’ !

It Should Look Like This!

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.!

!NOW Time to!

ADD THE MATH …!!

J !!

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.!

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.!

!

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.!

It Will Look Like This:!

Building the Model!

• If you misspell a word, the flow’s name becomes red.!

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.!

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.!

Here’s What It Should Look Like!

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.!

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.!

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.!

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.!

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.” !

Our Sub-Model Is Almost Done!

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.!

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.!

Finished Sub-Model!

Building the Main Model!

• To create the main level of the model, we need to click the yellow paper button on the top left.!

Building the Main Model!

• It will ask you to name the sub-model. Call it “Simple Population Growth” !

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.!

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.!

Building the Main Model!

• We can give our main model a title. Just right click on “Untitled” and give it the name “Population Model”.!

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.!

• 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!

Drag-and-Dropping the Sub-model!

Seeing the Sub-Model from the Main Model Level!

•  To see the sub-model, just press Shift + right click and press on the chip.!

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.!

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).!

Building the Main Model!

• Once you selected slider, click somewhere clear on the canvas and name the slider, “rate”.!

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.!

Building the Main Model!

• Create another slider and call it “Initial Population.” !

• You can leave the range between 0 and 100.!

!

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.!

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.!

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.!

Our Main Model, so far!

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!!

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.!

Getting the Graph!

• Now add the graph somewhere to the right of the sub-model chip.!

• Name the graph, “Population.” !

The Graph, Population!

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.!

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?!

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.” !

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.!

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” !

Getting the Graph!

Our Model Output! !A Success!!

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!!

The Finished Product!

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!

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!

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.!

top related