Answer e.

advertisement
CS151L Fall 2013
Week 12: DO NOW QUESTIONS
1. Monitors
Very often a programmer will want to keep track of a variable as it changes
within a program. One of the ways to do this in NetLogo involves using
Monitors. Monitors are output windows that show a value based on some
underlying code.. The value that the monitor uses to generate its display is either
a global variable, a reporter or and expression that evaluates to a value.
In the image below, an entry in which field(s) will not have any impact on the
value that appears in the monitor.
,
a.
b.
c.
d.
e.
Reporter field
Decimal place field
Display name field
Font size field
C and D
Answer e.
2. Reporters
Suppose that we have built a model that involves agents (turtles) that wander
the world eating grass. The grass (individual patches) have a patches-own
variable called “grass-energy” which goes down as turtles visit each patch. Each
patch is recolored to visually show the grass-energy available in that particular
patch. You are interested in keeping track of overall amounts of energy left in
the world (aggregate data). The monitor that displays this information probably
gets its value from code that looks like which of the line(s) below
a. a reporter that says Report sum [grass-energy] of patches
b. a global value called global-grass-energy that is updated anytime
any patch changes its grass-energy level.
c. An expression in the reporter that sums a list containing all the individual
values of the custom grass-energy variable.
d. An expression that says count turtles energy-level.
e. A, b and c.
Answer e.
3. If you build a game in NetLogo and create a reporter to display the score. What
kind of code might you see in your program?
Assume:
globals [score]
a.
b.
c.
d.
e.
report scores
if something = true [set score score + 1]
plot score
count turtles = score
turtles-own [score]
Answer b
4. Plots are also used to display changes to values within a model as a model runs.
There can be multiple values plotted in the model because it is possible to have
plots with multiple pens. In a model of disease spreading through a population
which lines might be used to plot outcomes?
Assume turtles-own [is-sick? Is-infected?]
a.
b.
c.
d.
e.
plot [is-sick?] of turtles
plot count turtles with [is-sick? = true]
plot count turtles with [is-sick? = false]
plot count turtles with [is-infected? = true]
b c and d above.
Answer e
5. Assume that you are creating a model that requires a plot. You are not sure how
to use plots. Which approach or approaches might help you figure out how plots
work.
a.
b.
c.
d.
e.
Use the built in NetLogo manual under Help > NetLogo Manual
Ask somebody who knows how to work with plots.
Add a plot widget to your model’s interface and play with it.
Look at other models that use plots and examine the code.
All of the above.
Answer e.
6. When modeling the spread of infectious disease there are many factors that can
affect the spread of the disease and the ultimate impact of the disease on society.
These factors are often called the parameters of a NetLogo model. It is interesting to
see the effects that changing these parameters have on the overall system.
Consequently, NetLogo programmers often represent these parameters as sliders
in their models so that the model can be easily run at different settings.
Which variable or variables would be a good parameter or “slider” for an infectious
disease model?
a. wiggle-rate (rate turtle move through the world)
b. number-contacts-before-infected
c. profession (“professional” “student” “wage earner”)
d. initial-population-density
e. All except c
Answer e.
Answers:
1. The Reporter is the field that directly produces the value that you see in the
reporter. The Decimal place field also changes the precision (the accuracy) of the
answer. The other two fields are important for formatting and labeling the
monitor’s value but do not change the value displayed.
2.[grass-energy] of patches produces a list values for each of the patch.
Summing this list with sum gives you the desired value. This code can be in a
reporter or simply in an expression. Another (more cumbersome) approach would
be to keep track of each and every change to a patch by updating a global variable.
If you wanted to monitor the average value of the grass-energy your would use a
reporter that looked like:
mean [grass-energy] of patches
3.The answer is b.
It will very likely be the case that the score changes as some event occurs. You test
for the event with a condition (if … then) and increment the score if the condition
happened.
The others statements are wrong for a variety of reasons:
Answer a. Note that the global is called score not scores.
Answer c. You could plot the score but that would be odd.
Answer d would probably generate an error.
Answer e. If there is a global variable called “score” there cannot be a turtlesown with the same name. (not e).
4. All of the answers except A are quite reasonable. A is wrong because [is-sick?] of
turtles returns a list of true false values , for example [true true false true false false
….] It is possible to histogram values that appear in a list but it is not possible to plot
them.
5. All of the above answers point to important tools for novice programmers to
have as they teach themselves to program. The answers are listed approximately in
the order that I use them when I (a veteran NetLogo programmer) encounter a new
situation.
6. There are many values that a modeler might want to parameterize to explore the
impact on the spread of disease. It might be valuable to brainstorm a great number
of variables that could play a role in the rate of infection, the rate of recovery and
the course of the disease in individuals and society at large.
If rate of contact with others is a variable the wiggle-rate would certainly be an
important variable . number-contacts-before-infected might control the
sensitivity to infection, again, a reasonable variable to consider. Likewise, answer d,
the population density could be important variable. Only c, profession, would not be
an appropriate variable and only because it is categorical rather than continuous i.e.
it is not obvious how to smoothly change from one profession to another.
Download