CS108L Spring 2014 Week 7: Video Summary

advertisement
CS108L Spring 2014
Week 7: Video Summary
Designing and Running Experiments in NetLogo
• Model
▫ The actual program
▫ The abstraction of the real world
▫ Captures the elements of the system and the behavior of the elements being
modeled
• Simulation
▫ Running the model to simulate the passage of time
▫ Exploring the behavior of the modeled system over time.
▫ In studying complex systems, sometime unexpected patterns emerge that
weren’t explicitly programmed into the model.
• Why model?
▫ Once the model is developed
• Can run many trials
• Can run many parameters
▫ Can develop models for situations where experimentation is difficult
• Too dangerous
• Too expensive
• Too time intensive
• Two types of simulation models:
▫ Deterministic simulation models:
• Provide single outputs for each set of inputs
• No Randomness involved
▫ Stochastic simulation models
• Can produce somewhat different outputs for each set of inputs
• Randomness IS involved
• Agent-based models of Complex Adaptive Systems have Randomness ->
they are stochastic
• Look at the probability distribution of possible outcomes.
• How to Run a Simulation
▫ Simple parameter sweeping (one dimension)
• Hold all other variables constant
• Set min, max, and increment for one variable.
• Sweep one variable (from min to max value)
▫ Repetition – Because the models are stochastic
• Repetitions at each setting
• Take the average?
▫ What output do you want?
• Simulation Output depends on the model
• Stopping a forever button
• Forever GO button can go forever.
• Automatically Stop the Forever GO button
▫ Conditional Stop at the TOP of GO procedure
Document1
▫
to go
if condition? [ stop ]
...
end
Computer Simulation Write-up - Must include enough information to explain and allow
replication of the experiment
▫ Description of problem of interest and abstraction
▫ Description of Model
 Assumptions/Simplifications
 Variables/Parameters
▫ Description of Simulation
 Parameter Sweeping
 Repetitions
▫ Description of Results
 Verbal Description
 Tables/Graphs
▫ Discussion of Results/Conclusions
Breeds and Shapes in NetLogo
• NetLogo allows the programmer to define different “Breeds” of Turtles
▫ Breeds are types of Turtles - Has all the properties that turtle has in addition to
breed specific
▫ Breeds are a Subset of Turtles
• Many reasons to use breeds, some include:
▫ Want agents with attributes
• Example: genders, species, infected, healthy,…
▫ Want agents that can behave differently
• Ask each breed to behave differently
▫ Want to refer to each breed separately
▫ Want agents to have different variables
• Define turtle breeds using the breed keyword
▫ At the top of the program
▫ Before any procedures
breed [ plural_name singular_name ]
• Create breeds - Similar to creating turtles:
create-<breeds> number create-<breeds> number [ commands ]
 Can set breed attributes (NetLogo predefined agent variables):
ask <breed> [set attribute #]
ask wolf 3 [set size 5]
ask <breeds> [set attribute #]
ask wolves [set size 5]
• You can set the shape of a turtle or specific breed
• Set initial shape
set-default-shape turtles string set-default-shape breed string
 Changes the shape of breeds after used
Document1
Can set shape within the code
set shape “shape_name”
• How to change shape
• Top of program – Tools Tab
• Turtles Shape editor to view shapes
 Can look at the shapes in the Turtle Shape Editor window and pick
one - Over 30 shapes to choose from
 Can Import a shape from the Library - Over 200 shapes
 Can Edit an existing shape –RENAME it
 Can create a new shape
 Once you pick/import/edit/create a shape – note the name
carefully
Can specify variables for breeds -Each agent in that breed has its own value
• At top of the program before procedures
<breeds>-own [var1 ...]
To get Breeds to do specific actions:
ask breeds [commands…]
ask breed # [commands…]
ask breeds with [ condition][commands]

•
•
Population Dynamics
• What is a Population?
• A group living things: Ants, bees, turtles, people…
• Agent Based Modeling: Agents ( Ants, Bees,… but also molecules, cars, …)
• Population Dynamics - Life Science
• Characterizes a population
• Size, age, type, reproduction, death
• Changes in Population  Population Dynamics
• Populations affected by
 Birth and death
 Immigration and emigration
• Positive Feedback – enhances what you are looking at
• Negative feedback – slows down or decreases what you are looking at
• Some types of Population Curves
o Exponential
o Logistic
o Cyclical
• Model things that effect birth as changes in the birth rate
• Model things that effect death as changes in the death rate
• Many ways to model Birth
• Agent interactions (same species)
• Agent/Environment interactions (location, food,…)
• Changes in the agent (correct age, energy, ...)
 Energy > Birth Threshold
• Need a certain energy to have birth – threshold
• Energy is lost by birth
Document1
•
Many ways to model Death
• Agent interactions (predator/prey, infected agent…)
• Agent/Environment interactions (toxins, locations…)
• Changes in the agent (disease, age, energy...)
 Energy < Death Threshold
• When energy is less than a threshold - die
Creating Agents In NetLogo
• Four types of agents
▫ Observer – no specific location, looks over entire NetLogo World
▫ Turtle Agents – Mobile agents
• Can have different shapes and names (breeds)
▫ Patches – Stationary agents
• NetLogo World is divided into a grid work of small squares or patches
▫ Links - Agents that connect two turtles
• Three ways to create turtles
▫ Create command – Observer creates turtles
create-turtles #
• Creates # new turtles at the origin
• Turtles have a random color and direction
• Sprout Command – Patches create turtles
sprout #
• Creates # turtles on a selected patch
• Turtles have a random color and direction
•
Hatch Command – Turtles create turtles
hatch #
• Must be an existing turtle
• Creates # new turtles at the same location as the “parent” turtle
• Each new turtle inherits of all the “parent” turtle properties
Being Random
 Random – no pattern, not predictable
 Problem with computers – they are deterministic – they are supposed to be!
o Computers are designed to be completely predictable and determinable –
o Inputs determine the same outputs
 Computers have Pseudo-Randomness
 PRNG = Pseudo Random Number Generators
o That’s what’s in a computer
o Algorithms to determine random numbers
o Randomness is only as good as the algorithm used
 Reseeding the random number generator – resetting the original number used in the
random number generator. Must avoid reseeding the random number generator to
prevent a repetition of the random numbers generated.
 No true randomness in computers .
Document1
Download