Know Your Network

No preview image

1 collaborator

Default-person David Weintrop (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.1.0 • Viewed 325 times • Downloaded 28 times • Run 0 times
Download the 'Know Your Network' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

extensions [ nw ]

turtles-own [
  ;; facebook data
  id
  name
  centrality
  
  ;; infection variables
  infected?
  
  heard-from
  
]
links-own [
  weight
]

to load-graph
  clear-all  
  
  ;; Hard-code your path if you don't want to get prompted every time:
  ;; let filename user-file "/path/to/your-network.graphml"
  let filename user-file
  
  if (filename != false) [
    nw:load-graphml filename [
      set shape "circle"
    ]
    nw:set-context turtles links
  ]
  
;  let no-of-components length (sentence nw:weak-component-clusters)
;  ifelse no-of-components > 0 [let degrees-separated 360 / no-of-components
;    let counter 0
;    foreach nw:weak-component-clusters [
;      let biggest-component-size max map [count ?] nw:weak-component-clusters
;      if count ? != biggest-component-size [ask turtle-set ? [die]]
;    ]
;    reset-ticks
;  ]
;  [
;    user-message "No network was loaded, please try again."
;  ]
end 

to remove-most-central
  ask max-one-of turtles [ count my-links ] [ die ]
  nw:set-context turtles links
end 

to update-layout
  layout-spring turtles links 0.2 .1 1
end 

to toggle-labels
  ;; if any have a label, turn off all labels
  ifelse any? turtles with [label != ""]
  [
    ask turtles [set label ""]
  ]
  [
    let the-number-of-turtles count turtles * (100 - label-threshold) / 100
    ask max-n-of the-number-of-turtles turtles [size] [set label name]
  ]
end 

to calc-centrality
  if centrality-measure = "random" [
    ask turtles [set size random 14 + 1]
    stop 
  ]
  if centrality-measure = "reset-size" [
    ask turtles [set centrality 1 set size 1]
    stop
  ]
  if centrality-measure = "degree-centrality" [
    ask turtles [set centrality count my-links]
    ask turtles [set size 10 * (normalize centrality min [centrality] of turtles max [centrality] of turtles)]
    stop
  ]
  let the-task (word "set centrality nw:" centrality-measure)
  ask turtles [run the-task]
  ask turtles [set size 10 * (normalize centrality min [centrality] of turtles max [centrality] of turtles)]
end 

to setup
  clear-all-plots

  ask turtles [
    set infected? false 
    set label "" 
    set color white
    set size 3
  ]
    
  ask links [
    set thickness 1
    set color grey
  ]
  
  reset-ticks
end 


; this normalizes a number

to-report normalize [value the-min the-max]
  set the-min ifelse-value (the-min = 0) [.001] [the-min]
  let normalized (value - the-min) / (the-max - the-min)
  report normalized
end 

to kill-smaller-components
  let the-component []
  foreach nw:weak-component-clusters [
    if length ? > length the-component [set the-component ?]
  ]

  set the-component (turtle-set the-component)
  show count the-component
  ask turtles with [not member? self the-component] [die]
end 


;; turtle procedure

to show-centralities
  show (word "Name: " name ", degree: " count my-links ", betweenness: " nw:betweenness-centrality ", closeness: " nw:closeness-centrality ", eigenvector:" nw:eigenvector-centrality ", page-rank: " nw:page-rank)
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Layouts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to redo-layout [ forever? ]
  repeat ifelse-value forever? [ 1 ] [ 50 ] [
    layout-spring turtles links 1 (80 / 1) (1 / 1)
    display
    if not forever? [ wait 0.005 ]
  ]
end 

to layout-once
  redo-layout false
end 

to spring-forever
  redo-layout true
end 

There is only one version of this model, created over 10 years ago by David Weintrop.

Attached files

File Type Description Last updated
dweintrop.graphml data GML Example over 10 years ago, by David Weintrop Download

This model does not have any ancestors.

This model does not have any descendants.