HOTnet

HOTnet preview image

1 collaborator

Tags

complex networks 

Tagged by Marcello Tomasini over 7 years ago

hot 

Tagged by Marcello Tomasini over 7 years ago

power law 

Tagged by Marcello Tomasini over 7 years ago

Parent of 3 models: HOTnet (a), HOTnet (b), and HOTnet-maps preview imageHOTnet-maps
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.3 • Viewed 320 times • Downloaded 23 times • Run 0 times
Download the 'HOTnet' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

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

Click to Run Model

;; the number of hops from a fixed center of the tree
turtles-own [ nhop ]

;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all
  set-default-shape turtles "circle"
  ;; make the initial network of two turtles and an edge
  crt 1 
  [
    set color green
    set nhop 0 
  ] ;; first node unattached is the root of the tree

  crt 1 
  [ 
    setxy random-xcor random-ycor
    set color red
    create-link-with turtle 0 [ set color green ]
    set nhop 1
  ]
  
  reset-ticks
end 

;;;;;;;;;;;;;;;;;;;;;;;
;;; Main Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;

to go
  ;; new edge is green, old edges are gray
  ask links [ set color gray ]  
  ;; The behavior of the model depends crucially on the value of alfa:
  ;; if alfa is less than a particular constant depending on the shape of the region, 
  ;; then Euclidean distances are not important, and the resulting network is easily seen to be a star,
  ;; the ultimate in degree concentration, and, depending on how you look at it, the exact opposite, or absurd extreme, of a power law.
  ;; If alfa grows at least as fast as sqrt(n), where n is the final number of points, then Euclidean distance becomes too important, 
  ;; and the resulting graph is a dynamic version of the Euclidean minimum spanning tree, in which high degrees do occur, 
  ;; but with exponentially vanishing probability.
  ;; If, however, alfa is anywhere in between — is larger than a certain constant, but grows slower than sqrt(n) if at all —
  ;; then, almost certainly, the degrees obey a power law.
  ;;let alfa 100
  let x random-xcor
  let y random-ycor
  let partner nobody
  ;; Node i attaches itself to the node j that minimizes the weighted sum of the two objectives:
  ;; alfa * dij + hj
  ;; where dij is the /normalized/ Euclidean distance, and hj is some measure of the “centrality” of node j, such as 
  ;; (a) the average number of hops from other nodes; 
  ;; (b) the maximum number of hops from another node; 
  ;; (c) the number of hops from a fixed center of the tree;
  ;; all three measures result in similar power laws, in this case we use (c).
  set partner min-one-of turtles
  [ 
    alfa * 
    sqrt 
    ( 
      ;;( (x - min-pxcor + 0.5) / (max-pxcor - min-pxcor) - (xcor - min-pxcor + 0.5) / (max-pxcor - min-pxcor) ) ^ 2 + 
      ( (x - xcor) / (max-pxcor - min-pxcor) ) ^ 2 +
      ;;( (y - min-pycor + 0.5) / (max-pycor - min-pycor) - (ycor - min-pycor + 0.5) / (max-pycor - min-pycor) ) ^ 2 
      ( (y - ycor) / (max-pycor - min-pycor) ) ^ 2
    ) 
    + nhop 
  ]
  crt 1
  [
    setxy x y
    set color red
    if partner != nobody
    [ 
      create-link-with partner [ set color green ]
      set nhop 1 + [ nhop ] of partner
    ]
  ]
 
  tick
end 
;;;;;;;;;;;;;;;;;;;;
;;; Compute s(g) ;;;
;;;;;;;;;;;;;;;;;;;;

to-report log-likelihood
  let s 0
  ;; for each link compute di*dj and sum it to s
  ask links 
  [ 
    set s s + [ count link-neighbors ] of end1 * [ count link-neighbors ] of end2 
  ]
  report s
end 
;;;;;;;;;;;;;;;;;;;;;;;;
;;; Compute S-metric ;;;
;;;;;;;;;;;;;;;;;;;;;;;; 

to-report relative-log-likelihood
  let smax 0
  let counter 0
  let di 0
  let child 0

  ;; D = { d1, d2, d3, ..., dn }, d1 >= d2 >= d3 >= ... >= dn
  let degree-sequence sort-by > [ count  link-neighbors ] of turtles
  set di item 0 degree-sequence
  set degree-sequence remove-item 0 degree-sequence
  foreach degree-sequence
  [
    set smax smax + di * ?
    set counter counter + 1
    if di = counter ;; we have iterated through all di's childs; if di = 0 select the highest degree.
    [
      set counter 1 ;; count the parent if it's not the root
      set di item child degree-sequence ;; select child; child = 0 is the root.
      set child child + 1
    ]
  ]

  report log-likelihood / smax
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Save Nodes Degrees to file ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to save-node-degree-to-file
  if file-exists? "NodeDegrees.txt" [ file-delete "NodeDegrees.txt" ]
  
  file-open "NodesDegree.txt"
  
  ;; save in descending orders
  ;; D = { d1, d2, d3, ..., dn }, d1 >= d2 >= d3 >= ... >= dn
  foreach sort-by > [ count link-neighbors ] of turtles
  [
    file-print ?
  ]
  file-close
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Export Graph Connectivity to txt ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to export-graph
  if file-exists? "HOTGraph.txt" [ file-delete "HOTGraph.txt" ]
  
  file-open "HOTGraph.txt"
  
  ;; write each linked couple of tourtles and their degree
  ask links 
  [ 
    file-type [who] of end1 ;; writes without blank spaces
    file-write [who] of end2 ;; write a space value space
    file-print "" ;; write carriage return
  ]
  file-close
end 

;;;;;;;;;;;;;;
;;; Layout ;;;
;;;;;;;;;;;;;;
;; resize-nodes, change back and forth from size based on degree to a size of 1

to resize-nodes
  ifelse all? turtles [size <= 1]
  [
    ;; a node is a circle with diameter determined by
    ;; the SIZE variable; using SQRT makes the circle's
    ;; area proportional to its degree
    ask turtles [ set size sqrt count link-neighbors ]
    ask turtles with [ size >= 4 ] [ set color violet ]
  ]
  [
    ask turtles 
    [ 
      set size 1 
      set color red
    ]
  ]
end 

to layout
  ;; the number 3 here is arbitrary; more repetitions slows down the
  ;; model, but too few gives poor layouts
  repeat 2 [
    ;; the more turtles we have to fit into the same amount of space,
    ;; the smaller the inputs to layout-spring we'll need to use
    let factor sqrt count turtles
    ;; numbers here are arbitrarily chosen for pleasing appearance
    layout-spring turtles links (3 / factor) (5 / factor) (0.5 / factor)
    display  ;; for smooth animation
  ]
  ;; don't bump the edges of the world
  let x-offset max [xcor] of turtles + min [xcor] of turtles
  let y-offset max [ycor] of turtles + min [ycor] of turtles
  ;; big jumps look funny, so only adjust a little each time
  set x-offset limit-magnitude x-offset 0.1
  set y-offset limit-magnitude y-offset 0.1
  ask turtles [ setxy (xcor - x-offset / 2) (ycor - y-offset / 2) ]
end 

to-report limit-magnitude [number limit]
  if number > limit [ report limit ]
  if number < (- limit) [ report (- limit) ]
  report number
end 

; Copyright 2012 Tomasini Marcello.
; See Info tab for full copyright and license.

There is only one version of this model, created over 7 years ago by Marcello Tomasini.

Attached files

File Type Description Last updated
HOTnet.png preview model view over 7 years ago, by Marcello Tomasini Download
TesinaHOTnet.pdf pdf A small elaborate on HOT over 7 years ago, by Marcello Tomasini Download

This model does not have any ancestors.

Children:

Graph of models related to 'HOTnet'