Libraries‎ > ‎Library‎ > ‎Social network‎ > ‎

Power law social network v3

BehaviourComposer: ignore everything before this.

Begin micro-behaviour

Begin description:

Create a social network with bi-directional links between all individuals where the number of acquaintances is distributed according to a power law.

End description

Power law social network

Begin NetLogo code:
substitute-text-area-for community-expression all-individuals
substitute-text-area-for power-expression 1.6                  
substitute-text-area-for maximum-as-a-fraction .33
let entire-community community-expression
let population count entire-community
let number-of-links 
    sort-by > power-law-list-no-zeros population 
                                      power-expression 
                                      round (population *
                                             maximum-as-a-fraction)
; any fixed order for the source end of links
let sources sort entire-community
; destination is shuffled so the most connected
; don't connect to themselves disproportionately
let destinations shuffle sources
let source-index 0
let destination-index 0
let source nobody
while [source-index < population - 1]
 [set source item source-index sources
  let source-links-required 
      item source-index number-of-links - [count my-links] of source
  ; next search for the other end of the link 
  ; that still requires some links
  while [source-links-required > 0 and destination-index < population]
    [let destination-links-required 0
     let destination nobody
     while [(destination-links-required = 0 or source = destination) and 
            destination-index < population]
        [set destination item destination-index destinations
         set destination-links-required 
             item (position destination sources) number-of-links - 
             [count my-links] of destination
         set destination-index destination-index + 1]
     if destination != nobody and source != destination
        [ask source [create-link-with destination]
         set source-links-required source-links-required - 1]]
  ; ready for the next source
  set source-index source-index + 1
  set destination-index 0
  set destinations shuffle destinations]
End NetLogo code

Variants

You can edit the text areas to change the average number of acquaintances per person or to change the set of individuals that are to be linked together.

Related behaviours

The Constant social network behaviour assigns the same number of acquaintances to each individual.

How this works

It computes a power law distribution of links. First it computes the random distribution of number of links for each member of the population. It then creates links between the agents according to the distribution. This relies upon  power-law-list which computes a random list of number of links with the desired distribution.

If you need a particular average number of links per individual then you should experiment with the power parameter to power-law-list.  For example in NetLogo run show mean power-law-list 10000 POWER round MAXIMUM-VALUE where POWER and MAXIMUM-VALUE are given different values. For example a power of 1.6 and maximum value of 33 yields very close to an average value of 4.

History

Power law social network was revised to avoid zero connections by Ken Kahn on 3 March 2016.

BehaviourComposer: ignore everything after this.
Comments