Agent-Based Modeling for Sociologists is a crash course on how to build ABM in the social sciences. This presentation has an introduction to OOP and then discusses three models in details, along with their NetLogo implementation
2. Brief Outline of the course
Today: Programming concepts and NetLogo hands-on
Tuesday: Nowak and Latane’s model
Wednesday: Axelrod’s model
Thursday: Flache & Macy’s model
Friday: Teamwork
3. A new way to organize your
mind…
or how Object-Oriented Programming will save
your academic life (no kidding)
4. Computational Sociology
Hummon and Fararo (1995) in “Actors and
Networks as Object” claim support for the
emergence of computational sociology: computer
sciences ideas and technologies, like simulation
models, will help advance sociological theory
Macy and Willer (2002) in “From factors to actors:
computational sociology and agent-based modeling” identify
agent-based model as the right tool for advancing sociological
theory: human group processes are highly complex, non-linear,
path dependent, and self-organizing. A bottom-up approach
should be more efficient than a top-down and aggregate one.
5. Generative Principle
agent-based models are used
within the conceptual framework
of what Epstein’s (2006) called
generative social science
The research question is: “how
could the decentralized local
interactions of heterogeneous
autonomous agents generate
the given regularity?”
(Epstein, 2006, p. 5)
Epstein’s formalization: ¬S ⇐ ¬G
6. Object-Oriented
Programming (OOP)
OOP is a programming paradigm - a set of concepts and
abstractions used to represent a computer program and the
algorithms used
OOP represents the concept of objects that have data fields
(attributes that describe the object known as properties) and
associated procedures known as methods
Objects, which are instances of classes, are used to interact
with one another to design applications and computer programs
OOP is the new way of organizing data since 1990
7. OOP Key Concepts*
Objects are key to
understanding OOP.
Real-world objects share
two characteristics: They all
have state and behavior.
Show and tell: Take a
minute right now to observe
the real-world objects that
are in your immediate area
From Oracle: http://docs.oracle.com/javase/tutorial/java/concepts/index.html
8. What is an Object: ride a
software bicycle!
An object stores its state in
properties (variables or
fields in some programming
languages) and exposes its
behavior through methods
Methods operate on an
object's internal state and
serve as the primary
mechanism for object-to-
object communication.
9. What is a Class: wait, is that
my bicycle???
In the real world, you'll often
find many individual objects
all of the same kind.
In object-oriented terms, we
say that your bicycle is an
instance of the class of
objects known as bicycles.
10. Key Concepts: data
encapsulation
Hiding internal state and
requiring all interaction to be
performed through an object's
methods is known as data
encapsulation
By interacting only with an
object's methods, the details
of its internal implementation
remain hidden from the outside
world (information-hiding)
11. Key Concepts: Inheritance
Different kinds of objects often
have a certain amount in
common with each other.
OOP allows classes to inherit
commonly used state and
behavior from other classes.
In OOP, each class is allowed to
have one direct superclass, and
each superclass has the potential
for an unlimited number of
subclasses
12. Why OOP is useful for us?
because we want to
simulate artificial societies
and generate social
phenomena in silico
but how OOP actually helps
us?
13. What does the trick?
property 1 property 2 property 3
flaminio 10 3 25
simone 18 1 20
you 23 321 12
… … … …
flaminio
simone you
10
325
20
118
12
32123
each row is an object, with
the same properties
!
!
!
14. What does the trick?
property 1 property 2 property 3
flaminio 10 3 25
simone 18 1 20
you 23 321 12
… … … …
flaminio
simone you
10
325
20
118
12
32123
each row is an object, with
the same properties but
also with methods that can
change these values
!
a method
a method
a method
16. Brief recap
an object is an instance of a class
when an object is created, a space in the memory is
occupied
an object has some properties
an object has methods to change its properties
objects can communicate through methods
17. But what is an agent?
An agent is a thing which does
things to things (Kauffman)
An agent is a persistent thing which
(Shalizi, 2004):
has some state you find worth
representing (it’s up to you!)
interacts with other agents, mutually
modifying each others’ states (your
model your rules!)
Question: can you reformulate this
definition using OOP concepts?
18. Yes, agents are objects!
Computationally, the
nicest way to implement
an agent is with objects
What if we do not use
objects?
19. So what is an ABM?
An ABM is a computer
program:
a collection of agents
and their states
the rules governing the
interactions of the agents
the environment within
which they live.
20. What are ABM suited for?
agent-based models
represent individuals, their
behaviors and their interactions
equation-based models
represent aggregates and their
dynamics.
Agents have decision-making
abilities and an understanding
of their environment
21. What is simulated time?
A schedule implies a
timeline
ask agents [
# do something
]
advance-tick
22. What is randomness?
How can a deterministic
device produce random
events?
How can we use pseudo-
random numbers?
We also need a seed, like
123456789
23. We have a model, then?
Every model has a
parameters space
Select a granularity
Simulate each possible
combination many times
Compare what you have
found with empirical values
24. About platforms…
Many available (SWARM, RePast, MASON…)
NetLogo is not OOP, but uses a Procedural
Language called Logo
What is Logo?
Why using a procedural language instead of OOP?
26. How to ask for help… and
actually receive it!
netlogo-users@yahoogroups.com
netlogo-devel@googlegroups.com (for extensions developers)
Ask a question on www.stackoverflow.com
Please be smart in the title:
“I need help”, “this doesn’t work”, “I have a problem”
Please be specific in the message:
tell people what is your goal, what have you done already, and
report the complete error message you get
27. From Private Attitude to
Public Opinion: a Dynamic
Theory of Social Impact
Authors: Nowak, Szamrej and Latané
Published in: Psychological review, 1990, 97: 3, 362-376
28. Introduction
Simulate Latane’s social impact theory, which specifies a number of
principles that describe how individuals are influenced by their social
context
In doing so, we will observe how some phenomena at the macro level
can emerge from this simple theoretical micro-foundation, in particular:
incomplete polarization of opinions reaches a stable equilibrium
minorities form on the margins of the population
Computer simulations, neglected in group dynamics for 20 years, may, as
in modern physics, help determine the extent to which group-level
phenomena result from individual-level processes. (micro-macro link)
29. Introduction
The authors starts from the Coleman’s Boat:
“The functioning of higher level units (e.g., social groups) may be partly or completely
determined and therefore explained by mechanisms known from theories describing
phenomena at lower levels (e.g., human individuals). Alternatively,the functioning of lower
level units (e.g., individuals) may be affected by the higher level units to which they
belong. In other words, individuals in a given social context behave differently than they
would outside that context”.
They insist on the concept of simulations as the right tool to develop sociological theory:
“we examine some possible consequences of simulating on a computer a theory
describing the functioning of individuals in the presence of others”
“we simulate Latané's (1981) theory of social impact as applied to attitudes and explore
the consequences for public opinion of the operation of social processes affecting
individual attitude change”
30. Personal influence and
public opinion
Many studies show that people tend to change their minds when
compelled with persuasive arguments
we can deduce that, if the trial period is long enough, we should see
the emergence of a generalized consensus, where everybody
converge on the majority’s view, but we know this does not happen:
“Social influence processes do not by themselves create
uniformity of opinion”
“Social influence processes do not lead to the convergence
of public opinion on the mean of the initial distribution of
private attitudes”
31. Social Impact Theory
Latané defines social impact as: “any influence on individual
feelings, thoughts, or behavior that is exerted by the real,
implied, or imagined presence or actions of others” thus its goal
is to define the impact that a subject receives from an external
source (a group)
Impact (î) is a multiplicative function (f) of strength (S), distance
(I) and size (N) of the external source:
î = f(SIN)
Social impact theory is a static theory
32. Social impact theory
How do we change our attitudes?
To the extent that individuals are relatively uninvolved in an issue, they
should be influenced by the strength, immediacy, and number of people
advocating a contrary position.
It seemed desirable to distinguish two forms of communicator strength
one with respect to people who share the communicator's opinions
one with respect to people who oppose them.
What happens when individuals with these characteristics come together
in a dynamic process?
33. How to simulate social
impact
Attitude: 1 or 0, it is a dichotomous variable, it is used to divide the
population into two groups. Its interpretation does not affect the
result of the simulation (numbers, letters, boolean, whatever)
Persuasiveness: a random number from 0 to 100, it represents
how good you are in persuading people that do not share your
opinion
Supportiveness: a random number from 0 to 100, it represents
how good you are in support people that share your opinion
Immediacy: a number that represents distance between pairs of
agents
35. Model rules
Change rule: if an individual undergoes a persuasiveness greater
than the supportiveness offered, the individual changes his mind
(if ip / is > 1 then new attitude = 1 - attitude)
Frequency: the initial state of the simulation requires that a
percentage chosen by us has a certain attitude. The initial
distribution of attitudes is random
Tick: at each tick, each agent observes his neighborhood and
decides what to do, whether to change its opinion or not
World: square matrix 40x40 = 1600 agents, each agent "sees" only
agents at a distance <= 10
36. Results / 1
Initial Condition:
1600 agents,
70% starts with opinion: I
30% starts with opinion: -
Typical final distribution:
90% adopts dominance
10% resists and is
organized into
neighborhoods
37. Results / 2
At first, changes are very frequent, then
tend to an equilibrium state
The majority acquires many members while
the minority loses many
Change attitudes in order to create
consistent areas*
The frequency of changing attitudes
decreases over the course of the simulation
The simulation reaches a state of
equilibrium
The time required to reach equilibrium
depends on the initial distribution of skills
(the more egalitarian, the longer the
simulation)
38. Discussion
The model shows how to apply social impact theory
to dynamic groups while producing two emerging
phenomena:
incomplete polarization at equilibrium state
clustered groups of homogeneous opinions
Again on polarization
40. The Dissemination of Culture:
a Model with Local Convergence
and Global Polarization
Author: Axelrod
Published in: Journal of Conflict Resolution, 1997, 41: 2,
203-226
41. Introduction
If people tend to become more alike in their beliefs, attitudes and behavior when they
interact, why do not all such differences eventually disappear?
We start from a mechanism that forces agents to converge:
similarity leads to interaction and interaction leads to more similarity
The novelty of this model is twofold:
the effect of a cultural feature depends on the presence or absence of other
cultural features (social influence)
homophily is taken into account (social selection)
The model shows how local convergence generates global polarization, and how this
polarization varies according to the scope and possibilities of the cultural landscape
41
42. What is “culture”?
Culture is something people learn from each others:
culture is what social influence influences
Many ways to explain why minorities resist
Culture is represented as a set of features, each of which
has a trait. This representation allows us to introduce
homophily (the more we are similar, the more we will
interact)
Here’s a simple example: 1 7 2 9
42
43. Why ABM?
Bottom-up approach with micro-founded mechanisms
and consequences are investigated using simulations
No central authority
Adaptive agents: no rationality, no benefit/cost analysis,
they simply adapt to their environment
Consequences on global level depends on cultural size
and complexity, neighborhood extension and world size
43
44. The model
The basic idea is that the more two agents are similar, the higher the chance they will interact, thus
becoming even more similar: to achieve this behavior, the chance to interact is proportional to their
cultural similarity
Agents are on a 10x10 grid
Each agent controls his neighborhood:
agents in the middle: Von Neuman neighborhood - north south west est, 4 neighbors
agents at the border: north south est/west, 3 neighbors
agents in the corner: 2 neighbors
Agents are initialized with a random culture:
they all have the same number of dimensions
cultural traits are assigned randomly
44
45. Scheduling
An agent is extracted at random
One of his neighbors is extracted at random
They interact with a probability proportional to their cultural similarity
If they interact, the calling agent picks at random one of his cultural
dimensions where the two agents differ and copies his neighbors’
value, thus becoming more similar to his neighbor
Time is measured in events, where an event represents the
activation of an agent
45
47. The emergence of
homogenous cultural zones
how do homogeneous
zones form?
does homogeneity is
achieved or does
minority cultures form?
does the system achieve
an equilibrium?
47
48. The emergence of
homogenous cultural zones
a cultural region is a
contiguous region where
agents share the same culture
time 20.000 some cultural
regions emerged
time 40.000 cultural regions
got bigger
time 81.000 is the equilibrium
state: just 3 regions left, a
majority and two minorities
cultural region
cultural region
cultural region
48
49. The emergence of
homogenous cultural zones
Cultural complexity depends upon two variables:
number of cultural features
number of traits for each feature
Hypothesis: more variability between cultures will
produce more cultural regions
49
51. Discussion
We observed two results:
the number of stable cultural regions increases as the number of traits increases (intuitive)
the number of stable cultural regions decreases as the number of cultural features increase
(counter-intuitive)
What have we learned:
the model can be stated in one single sentence: “with probability equal to their cultural
similarity, a randomly chosen agent will adopt one of the cultural features of a randomly
chosen neighbor”
it is hard to forecast how many stable cultural regions will form at equilibrium
functionalist explanations are not necessarily the simplest
polarization is not necessarily produced by negative selection
51
59. Back to this model
Research on small worlds suggests that weak ties
(i.e. bridges between clusters) foster integration,
homogeneity and cultural diffusion
This model shows that such a result is based on
implicit micro-level assumptions
It’s theory-building, baby…
59
60. Introduction
Empirical and theoretical research suggests two very different effects
of long-range ties in clustered social networks:
An earlier generation of studies predicted the inevitable collapse of
diversity into an emergent monoculture unless clusters are entirely
disconnected
More recent studies suggest the preservation and even the
enhancement of diversity in an increasingly connected world
There is also a third possibility: long-range ties can reduce cultural
diversity leading to consensus and at the same time deepen
cultural divisions leading to polarization: let’s see how
60
61. Introduction
What is the effects of long-range ties on cultural diversity
in an otherwise locally clustered social network?
Recall Axelrod’s model to explain diversity?
social influence (how you change your mind) +
social selection (homophily to select who to pick)
Axelrod showed how homophily can preserve diversity
despite the convergent tendencies created by cultural
influence
61
62. Introduction
If social influence is driven by
homophily you are attracted by people
alike you
if social influence is driven by
xenophobia you differentiate from people
not alike you
The access network limits/fosters
interaction opportunities and is modeled as
an exogenously imposed, static
neighborhood structure that defines the
structural constraints within which the
dynamics of social influence and selection
operate.
62
63. Why AMB?
An important reason is that the combination of assimilation and
differentiation implies an inherently nonlinear dynamic, while previous
analytical models assumed linear social influence functions
When negative valence of interaction is assumed away, long-range
ties have an intuitively obvious integrative effect.
When this restriction is relaxed, we find that long-range ties deepen
cultural divisions.
This turns out to be robust against variations in the number and local
density of network clusters and the number of salient cultural issues.
63
64. -0.9899 -0.4345
The model
0.23232 0.32323
i j
K = 2 K = 2
-1 ≤ s ≤ 1 -0.3244 0.5416
K = 4
0.89898 -0.3456
K = 4
wij = wji
state 1 state 2 state 1 state 2
64
65. Update weights
i
-1≤wij≤1
s1 = 0.23232
s2 = 0.32323
s1 = 0.89898
s2 = -0.3456
0≤wij≤1wij=0.33225
j
The more similar nodes i and j are in
their states at time t, the higher is
the value of the weight wijt
66. Opinions update rules
the change of agent i’s state k
is an aggregated result of the
influences imposed by all
other agents who influence i
What happens when a small
number of long-range ties is
introduced between
disconnected clusters?
66
67. Disconnected caveman graph
Cave 1
Cave 2
67
Caves are the technical
implementation of network clusters
Local structure captured by Watt’s
clustering coefficient (C=1)
Global structure captured by mean
geodesic (L=1)
What is the effects on consensus and
polarization when a small number of
long-range ties are added to a
disconnected caveman graph (thus
making it a small-world)?
68. Scheduling
At each time step, an agent is picked at random
The agent selects randomly to update his state or his weights
to avoid artifacts
Agents are extracted with replacement
The duration of a single realization of the model is expressed
in the number of iterations
An iteration corresponds to N time steps, where N refers to
the number of individuals in the population
68
69. Polarization captures the degree to which a
population can be separated into two equal-sized
factions who are maximally dissimilar in the opinion
space and have maximal internal agreement
Opinion distance:
!
Global polarization:
Polarization measure
69
71. Experimental results/1
In a model with no negative
weights, consensus forms
within each of the network
components, and opinion
differences remain only between
components
In sum, the micro-theory
assuming positive influence and
selection implies that long-range
ties increase consensus and
reduce polarization
71
73. Experimental results/2
The effect of greater
connectedness on social
integration and polarization may
decisively depend on the micro-
mechanisms underlying cultural
interaction.
With only positive influence and
selection, long-range ties promote
greater cultural integration and
assimilation. When both positive
and negative valences are
assumed, the effect is reversed.
73
74. Discussion
Research on ‘‘small-world’’ networks suggests that a small proportion of
long-range ties that bridge otherwise distant or disconnected clusters can
promote cultural integration.
This model shows that such a macro-social effect depends decisively on the
micro-level assumption that interaction is limited to positive influence and
selection.
When homophily and assimilation are combined with their negative
moments, xenophobia and differentiation, then long-range ties fostered
cultural polarization rather than integration
This result should caution modelers of cultural dynamics against
overestimating the integrative effects of greater cultural contact.
74
76. References
Axelrod, R. M. (1997). The complexity of cooperation:
agent-based models of competition and collaboration.
Princeton, N.J.: Princeton University Press.
Axelrod, (1997), The Dissemination of Culture: a Model
with Local Convergence and Global Polarization,
Journal of Conflict Resolution, 41: 2, 203-226
Epstein, J. M. (2006). Generative Social Science:
Studies in Agent-Based Computational Modeling.
Princeton University Press.
Erdős, P and Rényi, A: On Random Graph, Publ. Math.
Debrecen, (1959)
Falche, A and Macy, M, (2011) Small worlds and
cultural polarization, Journal of Mathematical
Sociology, 5: 1-3, 146-176
Granovetter, M.: The strength of weak ties: a network
theory revisited. Sociological Theory 1, 201–233 (1983)
Gilbert, G. N. and K. G. Troitzsch (1999). Simulation for
the social scientist. Buckingham: Open University
Press.
Hedström, P. (2006). Anatomia del sociale. Milano:
Bruno Mondadori.
Hummon, N.P. and Fararo, T. J., Actors and Networks
as Object, Social Networks 17 (1995) 1-26
Macy, M. W. and R. Willer (2002, August). From factors
to actors: computational sociology and agent-based
modeling. Annual Review of Sociology 28, 143–166.
Manzo, G. (2007). Variables, mechanisms and
simulations: can the three methods be syntesized.
Revue Française de Sociologie 48(5), 35–71.
Nowak, Szamrej and Latané (1990), From Private
Attitude to Public Opinion: a Dynamic Theory of Social
Impact, Psychological review, 97: 3, 362-376
Shalizi, C.R: (2004), Methods and Techniques of
Complex Systems Science: An Overview, arXiv:nlin/
0307015v4
Squazzoni, F. (2013). Agent-based computational
sociology. Springer.
Terna, P. (1998). Simulation tools for social scientists:
building agent based models with swarm. Journal of
Artificial Societies and Social Simulations vol. 1, n. 2.
Watts, D.J., Strogatz, S.H.: Collective dynamics of
small-world networks. Nature, 393, 440–442 (1998)
76
77. Testo
Thank you for your attention!
email me: simone.gabbriellini@gmail.com
77