Archive for

Agent based modeling with Netlogo

In my meager attempts to get an idea of agent based modeling, I have recently had a chance to play a bit with Netlogo. I wanted to build a simple model where information is diffused in an interpersonal network of people, and where each one has a different taste for some kind of news. Netlogo is an easy entry into the agent based modeling world since it provides a nice interace and a easy language. Wikipedia says about NetLogo:

“It was designed in the spirit of the Logo programming language to be “low threshold and no ceiling,” that is to enable easy entry by novices and yet meet the needs of high powered users. The NetLogo environment enables exploration of emergent phenomena. It comes with an extensive models library including models in a variety of domains such as economics, biology, physics, chemistry, psychology, system dynamics and many other natural and social sciences. Beyond exploration, NetLogo enables the quick and easy authoring of models.”

The software comes with an abundance of already existing models from Art, Sociology, Network Theory, Mathematics, Biology…. and countless more domains. My purpose was to come up with some model that represents a bit of the communication theory. So after doing the great tutorials provided here everybody should be able to come up with his first attempt.

As a basis for mine I have chosen the SIR model (Stonedahl, F. and Wilensky, U. (2008)) from epidemiology: In its description it says:

This model demonstrates the spread of a virus through a network. Although the model is somewhat abstract, one interpretation is that each node represents a computer, and we are modeling the progress of a computer virus (or worm) through this network. Each node may be in one of three states: susceptible, infected, or resistant. In the academic literature such a model is sometimes referred to as an SIR model for epidemics.

I have only chosen to change a few of the details and have come up with this message theory driven model, which is build around a few loose thoughts.

  • A message can have a genre (10,20,30…100) where each number represents a given genre.
  • A message also has a value 1…10. The higher the value, the more valuable it is for the recipient.
  • Every person in the network has some kind of personal threshold 1…10. If a message is valued higher than my threshold i decide to pass it on to all my followers.
  • Every person has his personal favorite genre. If a message with this genre arrives I add up +5 to its value.
  •  A switchable on/off mechanism decides if there is some kind of broadcast mechanism that makes sure that everybody gets penetrated by the message at some point. (Like ads on tv)
  • Every person has a message spread chance which decides what certainity I forward the message to others. 10% would mean that a message has the chance of 10% to be forwarded to my followers, even if it matches my genre and the value is higher than my threshold.

The model itsself, is not an attempt to create something rigorous, but just get to know how netlogo works.

Download the model to play with it in netlogo

The good thing about netlogo is that you can compile your model into a java applet and put it online. So here is mine. Feel free to experiment with it.

  broadcasted?        ;; nodes reached by broadcasting
  infected?           ;; if true, the turtle is infectious
  genre               ;; has some sort of preference for a specific genre
  personal_threshold  ;; threshold an agent has

to setup
  ;; (for this model to work with NetLogo's new plotting features,
  ;; __clear-all-and-reset-ticks should be replaced with clear-all at
  ;; the beginning of your setup procedure and reset-ticks at the end
  ;; of the procedure.)
  ask n-of initial-outbreak-size turtles
    [ become-infected ]
  ask links [ set color white ]

to broadcast_to_turtle
  ask n-of initial-outbreak-size turtles
    [ become-infected_by_broadcast ]

to setup-nodes
  set-default-shape turtles "circle"
  crt number-of-nodes
    ; for visual reasons, we don't put any nodes *too* close to the edges
    setxy (random-xcor * 0.95) (random-ycor * 0.95)

to setup-spatially-clustered-network
  let num-links (average-node-degree * number-of-nodes) / 2
  while [count links < num-links ]
    ask one-of turtles
      let choice (min-one-of (other turtles with [not link-neighbor? myself])
                   [distance myself])
      if choice != nobody [ create-link-with choice ]
  ; make the network look a little prettier
  repeat 10
    layout-spring turtles links 0.3 (world-width / (sqrt number-of-nodes)) 1

to go
  if all? turtles [infected?]
    [ stop ]
  if broadcast

to become-infected  ;; turtle procedure
  set infected? true
  set color red

to become-infected_by_broadcast  ;; turtle procedure
  set infected? true
  set broadcasted? true
  set color red

to become-susceptible  ;; turtle procedure
  set infected? false
  set broadcasted? false
  let my_genre (random number_of_genres) * 10
  set personal_threshold global_personal_threshold
  set genre my_genre
  set color 32 + my_genre

to spread-virus
  ask turtles with [infected?]
     [ ask link-neighbors with [(not infected?) and (genre = message_genre)]
          if random-float 100 < message-spread-chance
             let personal_value message_value + 5
             if personal_value > personal_threshold
               [ become-infected ]
      ask link-neighbors with [(not infected?) and (genre != message_genre)]
      [ if random-float 100 < message-spread-chance
           if message_value > personal_threshold
             [ become-infected ]

to update-plot
  set-current-plot "Network Status"
  set-current-plot-pen "susceptible"
  plot (count turtles with [not infected?]) / (count turtles) * 100
  set-current-plot-pen "infected"
  plot (count turtles with [infected?]) / (count turtles) * 100
  set-current-plot-pen "broadcasted"
  plot (count turtles with [broadcasted?]) / (count turtles) * 100

; Copyright 2008 Uri Wilensky. All rights reserved.
; The full copyright notice is in the Information tab.

I find it quite interesting how hard it is to use some of the “viral” network effects once you assume that people are quite lazy and and forward only their own stuff. Also the less heterogenous (less number of people with different genres) the easier it is for the message to find a path and propagate.

@krittina had posted a small pdf from Duncan Watts about the nonexisting holy grail of marketing. (Check it out here ). I would be very interested what you think about it. Tell me on twitter.




A brief overview about opinion leaders

Research on opinion leaders dates back quite a while now. It was in 1944 when Lazarsfeld & Katz (The peoples choice) and his team researched public communication and found out that communication does not directly flow to the mass but is actually interpreted first by opinion leaders and then forwarded to the rest of the people. They have described this process as the “Two-Step-Flow of Communication”.

The Two-Step-Flow of Communicaiton asserts the following points:

  • Information is transferred not only by the (mass) medium but also through interpersonal communication
  • There are people between the medium and the interpersonal communication network which are called opinion leaders
  • The influence of such opinion leader is significantly larger than that of the medium

Characteristics of Opinion Leaders

Generally it is assumed that opinion leaders have certain characteristics which make them special.One definition of opinion leaders is the one of Kotler (in his book Marketing Management) where he defines them as “people who can influence members in the social community because of special techniques, knowledge, personalities and other uniqueness”

Rogers (in his book Diffusion of Innovations) describes opinion leaders as people with

  • high social participation
  • high social status
  • and a high social responsibility

Robertson (in his book Innovative Behavior and Communication) mentions that they are:

  • more directive
  • more innovative
  • and more professional

Impact of opinion leaders

According to Rogers, who describes the process of innovation, the decision process has five stages

  • Recognizing and understanding
  • Forming an attitude
  • evaluation of innovation
  • Testing and performing of innovation
  • Adoption or Rejection

Especially in the recognition and evaluation of innovations people are under the influences of their  interpersonal network. Here opinion leaders can play an important role.  In the recognition and understanding of an innovation opinion leaders can provide valuable information for members of their communication network. In the evaluation stage opinion leaders can serve as a norming element publicly deciding for a group
which innovations are good and which are bad.

Having a central role in their community opinion leaders can help to spread the word about an
innovation faster because of their many ties they have with the members.

Measurement of opinion leaders

Rogers provides four ways of identifying opinion leaders:

  • Observation ( e.g. recording the communication network chain and behavior of members in a community)
  • Identifying Key roles (e.g. find roles by instinct and grade them)
  • Interpersonal Relationship measurement (e.g. Ask people in the community who they ask for information and suggestions)
  • Self identification (e.g. ask everybody in the group if they feel like an opinion leader)

Identification of Opinion leaders

To identify opinion leaders in e.g. Twitter networks we can use the first suggested method since people in twitter leave tons of traces and their networks are public. A first attempt of doing this could be:

  1. Collect a community on a given topic
  2. Determine the connections between all members and save the data in a network format
  3. Find central players in the community by using social network analysis methods

In the next article I will show you how to achieve this and which problems and discussions we encounter on the way.