vendredi 14 mai 2021

How to assign different values to each turtles in network based on normal distribution in Netlogo

I am a beginner with Netlogo, experimenting with 'Information diffusion process model' by Emilio Sulis and Marcella Tambuscio. This Netlogo model shows how misinformation spreads with different values for the spreading rate of the news, the hoax credibility, the probability of fact-checking and the forgetting rate of the agents.

I have changed a few parts of the code from the original model, among which are using 'random-normal' commands in such a way that each turtle could be assigned a different hoax credibility (alpha-hoaxCredibility) and a different probability of fact-checking (pVerify) based on normal distribtion method.

Here is the the relate lines of from code:

set alpha-hoaxCredibility random-normal avg-alpha-hoaxCredibility avg-alpha-hoaxCredibility / 4
set pVerify random-normal avg-pVerify avg-pVerify / 4

Yet when I set the model, it turns out that the histogram of pVerify displays a skewed shape pattern that's quite diifferent from what we know a standard normal distribution should be. The model uses nw extention to create a network of tutrles, but as far as I understand, alpha-hoaxCredibility and pVerify are supposed to be assigned to each nodes of network so the distribution of pVerify should be typical bell-shaped pattern, not the skewed pattern that is seen in distributions of degrees or centralities in networks. I am wondering what caused the pattern, and if there is way to create a standard normal distribution of pVerify assinged to each turtles.

Here is the full code :

extensions [ nw ]

turtles-own [ state
              alpha-hoaxCredibility
              pVerify
              centrality

] ;; Three states of agents: "B" (believer) ;  "F" (factChecker) ; "S" (susceptible)

links-own [ weigth ]  ;; the weight of the links between agents

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   SETUP   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  ca

  setup-turtles
  update-plot

  reset-ticks

end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   GO   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  tick
  if ticks > 1000 [stop]   ;; stop condition (300 units of time)

  spreading               ;
  forgetting              ;-- Three main procedures for agent's behavior
  veryfing                ;

  update-colors           ;; just to improve the visualisation
  update-plot             ;; update plots of the Interface

end


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  SETUP PROCEDURES  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup-var
  set-default-shape turtles "person"
  set-default-shape links "curved link"
  update-output
end

to update-output
  clear-output
  output-print "* Diffusion model in social networks *"
  if Type-of-network = "BA" [output-print "Barabási–Albert network"]
  if Type-of-network = "ER" [output-print "Erdős–Rényi network"]
end

to setup-turtles


  if Type-of-network = "Barabási–Albert algorithm" [ nw:generate-preferential-attachment turtles links number-of-agents 3]
  if Type-of-network = "Erdős–Rényi model" [
    if number-of-agents > 100 [
      if PC-low-performance? and ask-proceed? [
        clear-output output-print (word "Erdős–Rényi model with " number-of-agents " nodes.")
        nw:generate-random turtles links number-of-agents 0.00585
      ]
    ]
  ]
set-plot-y-range 0 1
  set-plot-x-range 0 (max [ reward ] of turtles + 1)

 init-edges
end

to init-edges
  ask links [set color 3]
  ask turtles
  [ setxy random-xcor random-ycor
    set centrality nw:betweenness-centrality
    ifelse centrality >= min [centrality] of max-n-of initial-n turtles [centrality]
    [ set state "B" ][ set state "S" ]
    set alpha-hoaxCredibility random-normal avg-alpha-hoaxCredibility avg-alpha-hoaxCredibility / 4
   

    set pVerify random-normal avg-pVerify avg-pVerify / 4
  ]
  update-colors
end

to update-colors
  ask turtles [
    if state = "B" [ set color blue ]
    if state = "F" [ set color red ]
    if state = "S" [ set color gray ]
  ]
end

to update-plot
  set-current-plot "State-of-people"
  set-current-plot-pen "BELIEVERS"
  plot count turtles with [state = "B"]
  set-current-plot-pen "FACT-CHECKERS"
  plot count turtles with [state = "F"]
  set-current-plot-pen "SUSCEPTIBLES"
  plot count turtles with [state = "S"]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  GO PROCEDURES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to spreading  ;; each agent modifies with some probability its state considering the points of view (states) of its neighbors;
  ; S -> B and S -> F according to:
  ; S -> B : "spreading" function for the hoax (fi)
  ; S -> F : disseminate among the immediate neighborhood of a vertex (gi)


  ask turtles with [state = "S"][
    let nB count link-neighbors with [state = "B"] ; n-of neighbors Believers
    let nF count link-neighbors with [state = "F"] ; n-of neighbors Fact-checkers


    let _1PlusA ( 1 + alpha-hoaxCredibility)
    let _1MinusA ( 1 - alpha-hoaxCredibility)
    let den (nB * _1PlusA + nF * _1MinusA)
    let f 0
    let g 0
    if den != 0 [
      set f beta-spreadingRate * ( nB * _1PlusA / den )
      set g beta-spreadingRate * ( nF * _1MinusA / den )
    ]

    let random-val-f random-float 1
    ifelse random-val-f < f
    [ set state "B" ]
    [ if (random-val-f < (f + g) and ticks > delay-time ) [ set state "F" ]
    ]
  ]
end



to forgetting  ;; B -> S; F -> S  -- Each agent, regardless of belief state, forgets the news with a fixed probability pforget
  ask turtles with [state = "B" or state = "F"][
    if random-float 1 < pForget [
      set state "S"
    ]
  ]
end

to veryfing  ;; B-> F ; each agent can fact-check the hoax with a fixed probability pverify;
  ask turtles with [state = "B"][
    if random-float 1 < pVerify [
      set state "F"
    ]
  ]
end

;;;;;;;;;;;;;;;;;;;;;;; UTILS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to-report ask-proceed?
  report user-yes-or-no? "The network can be too wide to display in old PC: may suggest you to disable 'view updates' before press 'GO' button? Press Y to continue"
end



Aucun commentaire:

Enregistrer un commentaire