This code library has been built to help people explore how altruistic punishment, bribes, status anxiety, influence and privacy play in causing / preventing the tragedy of the commons.
Fabio sent through the COMSES 2011 Challenge which seems to fit this work very well. Increasingly it seems people are seeing ABM as a valuable communication tool. A plan would be to get something out and trial it at the John Mason school.
After lots of messing around with the code described earlier in the week I made the change a patch attribute within concentric circles micro-behaviour (MB). There were lots of lessons learned in the making of this MB, how to implement input boxes, let/set statements and general code. I now want to take this forward to implement MBs that control how agents link to each other as they move around.
Earlier I implemented linking with these ideas:
It would be best to break this into several MBs:
Another example of setting patch attributes according to a distribution:
x ;; circumference
c ;; patch color
set x 18
set c 20
ask turtle 0 [
repeat x [
ask patches in-radius x [ set pcolor c ]
set x ( x - 1 )
set c ( c + 1 )
ask turtle 0 [ die ]
ask patches [ set plabel pcolor ]
The code can be made more succinct and flexible:
This then is the basis for a micro-behaviour where 1 or more circles that set an attribute (doesn't have to be pcolor) at increments from the circumference to the center. The main point being that you can create an agent at setup and make it move around and change patch attributes. To be usable as a micro-behaviour we'd want to call it and pass in the relevant parameters i.e. circumference, color, xcor and ycor.
After discussion with Ken I am not sure about implementing my understanding of OO in the BC. The code above in can be implemented as in the
First we need to create a micro-world where a resource is available for human consumption. The resource could be distributed evenly, randomly or according to some pattern. The resource could deplete at a fixed or variable rate, deplete as consumed, or it could grow evenly or at a rate that fluctuates over time. There could also be different types of resource where agents gain utility from consumption in different ways.
resource quantity at start (RQs)
Patch attributes can be set according to some pattern by:
Let's play with these approaches in NL:
After a lengthy delay I am back to thinking about the ideal chunking of MBs so that they can be both easy to understand and expressive. This will require some field work with social scientists who are new to modelling - it will be an interesting juggling act.
I have made two models while thinking about how people relate to energy (a resource) and each other (see top of the page). The question now is how to re-author these MBs so that they can be part of a more general energy and people library. A library is a super-set of a specific model so requires more careful consideration. Taking a specific example - how to model the growth of a resource. I have:
There are many ways to do this and the BC is slightly confusing with respect to how it has to be done for the following reasons:
This can all be done in one MB or broken up as is. Wrt modelling energy, the MBs could do things like:
It is important to:
So this really comes down to developing an easy language for people to use to build the kinds of models they are interested. How to get them thinking along the lines? Well the general class of model I am thinking about is one relating to how individuals interact within different types of energy/resource distributions. This is a tragedy of the commons problem that emphasizes modelling realistic interactions between people e.g. status anxiety, altruism etc. Early in this diary I raised the idea of using a story to help people build ever more interesting models.
It occurs to me now that this sounds like the numerous optimisation game theory simulations. I guess this is making that math more tractable and also allowing people to model changes in strategy e.g. agents showing for-thought for instance i.e. there being agents that can stabilise systems that are at tipping points. In other words, agents are not simple self-optimisation units, more sophisticated decision-makers that inter-relate according to different societal roles.
I've noticed two trends lately:
I am doing things like working out why patch energy levels drop below 0, re-writing code to be more efficient and understandable, changing variable value ranges so that one change doesn't swamp another e.g. some agents can put others too much in debt. Somehow mathematically it doesn't feel right - its like I am making up numbers to steer the simulation in a direction...which I am not totally sure what it should be. I really need some kind of data set to tune things towards.
As I've been saying the last few days I need to turn more attention back to the original questions that are meant to underpin this model. I also need to think about how this model (and ones perhaps more directly related to the environment) can be used by researchers to communicate with policy-makers and the general public. Regarding the later I am thinking of a guide divided up into several chapters:
hatch 1 [ set shape "circle" set size 0.5 set color report culture-shade (my-culture / the-max-culture ) rt random 360 fd random-float 1 set my-culture n ]
set my-culture my-culture - 1
Finally for today - a reminder how to use to-report:
;; then define this "answer" reporter remembering to give the input variables a name here e.g. " v"
change my-greed/punish/bribe to variables in range 0-8
make my-defect a variable range so that it is part of the influence behaviour
change the influence behaviour so that the difference of the abs (bribe - punish) is added/taken from my-defect and my-greed
change the manage funds so that a fund is only topped up to a maximum value of 100
add the idea that an agent can spend assets to move its defect/greed values back towards the set point it initialised with
add culture and privacy interactions between patches and agents
add attribute cloaking to agents ( another instantiation of privacy )
break up the behaviours into smaller chunks that are aggregated together
- make a range of behaviours that implement different rules (so they can be activated as desired)
think whether I need to implement life-cycles to get the desired heterogeneity and multiple stable equilibria? actually - how will I know when the model is finished...i need to return to my original question.
then i need to start simplifying and return back to the original question
create a page on Sites that has sections for each of the main type of behaviour.
describe the story of how each type can be used (he order). describe the conceptual range of each type e.g. the possibilities in terms of the end game.
i think this goes back to privacy - I want to show that in an open world over-exploitation of resources wouldn't happen ( if people agreed what defecting is ) but when the information is not available defecting comes the norm.
after re-reading the altruistic punishment paper, it is the addition of bribes to the interaction that is different. Fehr and Gachter only used punishment/no punishment. in this sense the end-game is to show this by plotting data created using the Behaviour Space.
in terms of the paper, then I should focus on saying that education is the key to tackling climate change, that the learning must focus on complexity, and that contemporary discourse over-simplifies humans when it talks about the future, we are denigrated to simplistic agents who will repeat the mistakes of the past. we after all live in a deeply right-wing and conservative world (UK/ USA etc).
with respect to education, I could mention serious games but most of all mention constructionism. learning with graphics might also be worth emphasizing.
Thinking about the end game for the simulation - I want to generate data on:
the types of agents that exist at different stages of a simulation run and how these population mixes correlate to the state of the environment e.g. energy and culture
i could also experiment to see how robust different states are to shock e.g. sudden reduction in energy availability
The latest model seems stable but the agent interaction behaviours ( links, bribe, punish ) quickly result in a homogenous population with respect to 'my-greed'.
I need to come up with a way of analysing the model so that it can be more realistic and preferably evolve to a range of interesting stable states. I suspect I can do this by eye (so to speak) and then will need to use the BehaviourSpace.
First I am working on making the link behaviour more flexible/expressive. I think this means using NL primitives like max-n-of, with-max, max-one-of etc i.e. the agents are making a decision about which other agent to link to based on an attribute such as my-assets, my-greed or even my-culture. Code examples:
Here's a finished program that asks agents to link to half of their surround agents with the highest number score within their vision:
The question now is how to store the linked agents so that they can be used within the interact behaviour:
The program above is a good general template for simulating how agents might decide which other agents to link to at any one moment i.e. combining vision, knowledge about another agents attribute(s) (- here 'number), and then acting on the attributes of the linked agent (- here just changing the size).
(This is a teaching note). To build a model you need to move often between several tools and perform a range of tasks repeatedly i.e.
Very small syntax changes can completely change a model e.g. a bracket in the wrong place. To an inexperienced programmer these changes seem small but with more practice when you spot them you think ' how could I be so stupid '. What develops is a way of reading code, and parsing it into your own mental logic.
This code had me confused for a while:
I can change the code to the below to use directed instead of undirected links:
but why do I end up with agents that have 2 links? (Something to do with ask and ask-concurrent?)
Anyway, I think I should use directed links within the link micro-behaviour and write the code so that it can be easily extended to model many different forms of social interaction each step.
Pedagogic note: if things aren't working as you'd expect e.g. no influence seems to be happening - check the scheduling!!!
By downloading the model into NL and running some queries at the command line while the model is running e.g.
I can quickly check various aspects of the model configuration. For instance this command shows me that by setting a random number of defectors at the start, each simulation run will vary greatly e.g. if there are none by chance. However the model currently set so that non-defecting agents quickly influence defectors to change their ways - the result of which is that defection quickly disappears (and the model is not interesting or realistic). Actually I just tested this some more and the number of defectors as the simulation runs is more to do with the fraction of them at the start compared to non-defectors. Again this is not interesting - I need to change things so that a more interesting parameter sweep occurs and the model evolves as I outlined yesterday.
Second sitting (2pm ) I just changed the interface so that agents relative asset ownership is illustrated by size (color was difficult to distinguish). Now I have the interesting situation where some agents have massively negative assets - should I kill them or is this indicative of debt...should they go insolvent instead?
To fix next time:
The big lesson of today is very small - be careful of square brackets! I spent too long working out how to change one agents attributes to be the same as an agent that it is linked:
the documentation for 'of' and 'other-end' don't make it clear to me my 'other-end' needs to be in squared brackets. I found out though by playing with simple programs in NL:
I also had the annoying issue that I had named a set of variables in two ways: punish-fund and punishment-fund. Since modelling4all auto-creates variables the compiler through no errors.
So the next step is to work out exactly what I want to happen as agents influence each other. This approach is not very interesting since it will result in a homogeneous population eventually. I want the population to evolve into one that has an interesting optimization landscape e.g. with a number of stable states, or perhaps several states that exhibit chaotic behaviour e.g. bifurcations etc.
To do next: change the influence MB so that the transaction winner subtly influences the loser attributes rather than simply over-writing them i.e. simulate a nudge rather than a complete domination. This could be done by changing my-defect so that it is a scale and defection occurs when the value is over a tipping point i.e. 1 - 10 with defection at 5. Or there could be an influence variable that is the factor and this could be calculated based on a population-wide norm i.e. ...
Refer to Dan Ariely: http://danariely.com/the-books/excerpted-from-chapter-4-%E2%80%93-the-cost-of-social-norms/
The main thing is to think about the conference, what I need to do for it e.g. how does this model relate to the themes of the event? In particular I need to think about how extensible these behaviours are.
First some reflections on coming back to the model.
Being able to come back to a model and fix/enhance it after a period away (when you've forgotten most of the detail or thinking behind it) is a good test of how expressive and clearly it has been designed. Because of the limitations of programming through a browser modelling4all does not make it easy to follow the logical flow of the program because of all the nested micro-behaviours and the difficulty in remembering how all the variables (attributes and parameters) are being used. I remember that just before I went away I started to use a great deal of agent attributes to get bribes/punishment working and coming back now I can't quite remember why I decided to use some of them. This amounts to saying that the program outline description above is very useful and should be encouraged in the video guides.
I am starting to see a programming skill might be to kind of relax using variables and trust that they work as you use them e.g. I created sustainable share of energy of patch variable which is calculated by looking at the parameter the-energy-quota to find how close to zero a patch energy should go, then look at how much patch energy there is, and divide this by the number of agents that are on the patch. I do not necessarily need to remember all this each time I use this variable, I just need to trust that it is what it infers i.e. how much energy an agent can take from a patch. If they take more they have defected.
The two frozen models:
I had before the break are useful, the first works, the second makes a flawed attempt at modeling bribe/punishment behaviour. I think I will start again with how I want this to work and return to the pseudocode description above.
A pedagogical note: when you get to the step of comparing and setting agent attributes then the 'log specific attributes' behaviour is very useful to make sure the model/MBs are behaving as you expect. This was particularly true of the way Cindy modeled in that we were not sure after several weeks what was going on
After lengthy break...
the latest model doesn't run because there is a problem with the MB 'change attributes after bribe/punishment'. Will be fixed tomorrow with fresh eyes.
Today I fixed the division by zero error - this was caused by me naming an agent attribute incorrectly (my-punish-preference instead of my-punishment-preference) which mean the wrongly named attribute was created on the fly (a feature of modelling4all) and set to zero.
Using NL to get the hang of linking wrt this model:
bribes and punishment:
The task today has been to get agents linking and setting link attributes to break the links. An example model shows this working but we've decided to raise an enhancement request because of the non-intuitive way that the BC currently schedules the naming of prototypes. Ken's religiosity model also shows some more advanced used of links working in the BC.
There are 3 things to remember about the example model with regards to linking:
The example code works in the main model (which it just occurs to me needs a name).
A short NL program that shows how links attributes can be created and used, but I am not sure how to do this in modelling4all yet. we might need to write some more extension code to allow attributes to be created and set on the fly as for
There is a pedagogical issue here that the model description above has become so complex it is difficult to hold in memory. This makes it difficult to imagine whether it is interesting, coherent, consistent etc. One approach to dividing the implementation up into smaller chunks is to create a story script (see pedagogical section above) and use it to build the micro-behaviours. Each story chunk should contain the following elements:
During the build lots of new ideas will pop out - these should be recorded and parked if they are overly complicated.
10:45: started to add reproduction - how can I hatch an agent and reset some of the attributes once i.e. my-assets
Current model has reproduction (based on an assets threshold which is a little artificial). The coloring of agents is now achieved by using a list [( 255 * fraction) 0 0] which means agents are always a shed of pure red (no green/blue).
Next steps: add a histogram to watch main parameters
focus on decision-making of agents e.g. how agents decide whether to punish/bribe AND how the agents will respond to environmental stimuli
plan for today:
another way to model privacy would be to implement attribute cloaking (rather than allowing agents to set patch-entry-cost).
to model agent decisions based on attributes?
So the focus needs to be in creating a pattern for coding behaviours that model agent decision-making. As is the case in the current model - the difficulty here is deciding on sensible numbers i.e. how much my-assets would be needed to create culture, how much should culture effect agents.
One approach to this 'arbitrary numbers' problem is to let the numbers evolve in the system. This can be done by (a) letting agents breed, and the offspring have attributes that are the sum of the two parents (b) let agents effect each other's attributes during transactions. At this stage I am veering towards option B i.e. change attributes like my-love-of-culture in favour of the agent that wins a transaction e.g. if an agent successfully bribes another, then this other's attributes will be changed to resemble those of the briber.
So what might be a general schema for coding behaviours?:
if condition e.g. have enough assets to do something like bribe
and another if condition
do something e.g. bribe/punish/set entry-cost
normalise attributes between two agents in favour of the 'winner' e.g. the briber, the punisher
by normalise i don't mean make the loser's attributes the same as the winner. this might quickly emerge into a homogeneous model. i want the agents to explore the bribe/control/punishment space comprehensively.
The model so far has made me re-focus what I want to do so I have re-written the overall model description above. The general idea is to model assets (money) as an expression of power that agents can use to (a) control access to a resources (b) avoid altruistic punishment by bribing the agent dishing out the punishment (c) spend on building culture.
The model I've been building to-date was not focused enough on an interesting question. This one gets back (I think) to understanding how an agent's attitude to openness can skew an economy.
The model I ended up with yesterday had quite a few problems because of the way parameters are scheduled. Basically the parameters were set to zero because their value was dependent on agents existing, and none were when the parameter is created. Also patch behaviours cannot be scheduled in the same way agent attributes can. These issues are fixed in this model. Now I need to get the numbers right, and think some more about how I want the model to grow from here.
turtles-own [control cash]
patches-own [energy-on-patch price ]
ask turtles [ set control random 9 set color control set cash 100]
ask patches [ set energy-on-patch random 8 set pcolor 60 + energy-on-patch ]
ask turtles [
set cash cash - cost-of-living
if [price] of patch-here > 0 [
ask patch-here [ set pcolor price ]]
ask patches [
if price > 0 [ set price price - decay ]
if count turtles-here > 0 and price <= 0 [ set pcolor energy-on-patch]
;; patches continuously grow energy to a threshold
ask patches [
if energy-on-patch <= 8 [
set energy-on-patch energy-on-patch + 0.1
set pcolor 60 + energy-on-patch]
;; agents find cheapest neighboring patch and move to it if they have enough cash
;; find the patch with the best energy to price ration
ask turtles [
let x first sort [price] of neighbors
face one-of neighbors with [ price = x ]
if x <= cash [ fd 1 ]
;; agents take energy according to their control, only limited by the energy available on the patch
ask turtles [
let energy [energy-on-patch] of patch-here
let c control
ifelse energy >= control
set cash cash + energy
ask patch-here [ set energy-on-patch energy-on-patch - c ]
;; the finite earth view of the world i.e. can't take more energy than there is on a patch
set cash cash + energy
ask patch-here [ set energy-on-patch energy-on-patch - energy ]
;; turtles can put a price on land
;; set price a multiplier of control
ask turtles [
let p [price] of patch-here
let c control
if cash >= p [
set cash cash - p
ask neighbors [
set price price + c ]
or something like this. Point being this could serve as a process for stepping through when designing models, and improving them to be ever more complex yet simple.
It has also occurred to me that openness/control is only one aspect that needs modelling with reference to the open to change project. The other is responsiveness of agents to environmental parameters...which is another type of openness.
turtles-own [greed wealth]
patches-own [energy-of-patch price ]
ask turtles [ set color red fd random 15 set greed random 9 set wealth 0]
ask patches [
set energy-of-patch random 9
set pcolor 60 + energy-of-patch ]
;; turtles find cheapest patch
ask turtles [
let x sort [price] of neighbors
let y first x
face one-of neighbors with [price = y]
;; main thing here is not to take more energy than there exists on a patch (hence the ifelse)
ask turtles [
let energy [energy-of-patch] of patch-here
let g greed
ifelse energy >= greed [
set wealth wealth + energy
ask patch-here [ set energy-of-patch energy-of-patch - g ]]
[set wealth wealth + energy
ask patch-here [ set energy-of-patch energy-of-patch - energy ]]
;; patches keep growing energy to a threshold
ask patches [
if energy-of-patch <= 9 [
set energy-of-patch energy-of-patch + 0.1
set pcolor 60 + energy-of-patch]
;; when rich enough turtles can put a price on land
ask turtles [
if wealth >= 200 [
ask neighbors [ set price price + 200 ]
set wealth wealth - 200 ]
With the basic model now working I can start listing basic agent (and patch) behaviours and attributes:
The issues were caused with a bug in the new 'remove enhancement' micro-behaviour functionality. After re-making the behaviours I now have a model that works as expected. I also received a reply from the netlogo yahoo group from JL that gives me a cunning solution to report all the patches under a symmetrical shape like a circle. I still find it surprising that a more general reporter is not available since this is something that the eye can see easily but NL cannot report easily, especially if the agent was an irregular shape like a star:
It is not difficult to get the agentset of all patches whose center is inside a circle. You would use the `in-radius` primitive. In the context of a turtle whose circular shape goes all the way to the edge of the shape editor grid, you might use a reporter like this:
I just tested this and it does give some strange results:
...easily solved by (size / 2) but I could not get this code working in a NL model i.e. using to-report/report. I think I will take the other approach of simply enabling agents to take ownership of patches and so exert some control over access to these patches.