簡體   English   中英

如何 select 海龜在網絡上具有最大或最小中心度並為其分配特定狀態

[英]How to select turtles with maximum or minimum centrality on network and assign them certain status

我是 Netlogo 的初學者,正在嘗試 Emilio Sulis 和 Marcella Tambuscio 的“信息傳播過程模型”。 這個 Netlogo model 顯示了錯誤信息如何在具有不同值的新聞傳播率、惡作劇可信度、事實檢查概率和代理的遺忘率的網絡上傳播。

我已經更改了原始 model 的部分代碼,並嘗試在開始時僅設置具有最大接近中心度的海龜“信徒”和其他海龜“易感”。 如果選擇“外圍”模式,則僅將具有最小接近中心性的海龜設置為“信徒”,將其他海龜設置為“易感”。

但是,當我運行 Netlogo 代碼時,集線器模式以中心度小於最大值的“信徒”海龜開始,而外圍模式以存在大於 0.2 的最小中心度值時的零個“信徒”開始。

這是腳本的相關部分。

 if mode = "hub"
    [set centrality nw:closeness-centrality
      ifelse centrality = max [centrality] of turtles
        [ set state "B" ][ set state "S" ]]


  if mode = "periphery"[
      set centrality nw:closeness-centrality
    ifelse centrality = min [centrality] of turtles
        [ set state "B" ][ set state "S" ]]

我想知道這是否是由於 Netlogo 語言中的一些錯誤。

我也很好奇是否有什么辦法可以對中心度排名中中心度最大的5只海龜進行排序並將它們設置為'Believer,然后對排名中中心度最小的5只海龜進行排序設置它們'信徒,再把他們定為'信徒'。

這是完整的代碼:

extensions [ nw ]


turtles-own [ state
              alpha-hoaxC

              pForget
              centrality

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

links-own [ weight ]  ;; 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
      ]
    ]
  ]

  if Type-of-network = "Star Network" [nw:generate-star turtles links (number-of-agents) ]


 init-edges
end



to init-edges
  ask links [set color 3]

  ask turtles
  [ setxy random-xcor random-ycor
    set shape "person"


    if mode = "random" [
    set centrality nw:closeness-centrality
    ifelse random 100 <= initial-prop [ set state "S" ][ set state "B" ]

  ]
    
    

  if mode = "hub"
    [set centrality nw:closeness-centrality
      ifelse centrality = max [centrality] of turtles
        [ set state "B" ][ set state "S" ]]


  if mode = "periphery"[
      set centrality nw:closeness-centrality
    ifelse centrality = min [centrality] of turtles
        [ set state "B" ][ set state "S" ]]



  if distribution = "fixed"
    [set alpha-hoaxC avg-alpha-hoaxC
      set pForget avg-pForget]


  if distribution = "uniform"
    [set alpha-hoaxC random-float avg-alpha-hoaxC * 2
     set pForget random-float avg-pForget * 2 ]
]




  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-hoaxC)
    let _1MinusA ( 1 - alpha-hoaxC)
    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

當您說“NetLogo 語言中的一些錯誤”時,您是指實際 NetLogo 語言本身的錯誤,還是您用 NetLogo 編寫的代碼中的錯誤?

無論如何,這是 model 中的所有相關代碼:

  ask turtles
  [ setxy random-xcor random-ycor
    set shape "person"
    if mode = "random"
    [ set centrality nw:closeness-centrality
      ifelse random 100 <= initial-prop
      [ set state "S" ]
      [ set state "B" ]
    ]
    if mode = "hub"
    [ set centrality nw:closeness-centrality
      ifelse centrality = max [centrality] of turtles
      [ set state "B" ]
      [ set state "S" ]
    ]
    if mode = "periphery"
    [ set centrality nw:closeness-centrality
      ifelse centrality = min [centrality] of turtles
      [ set state "B" ]
      [ set state "S" ]
    ]
   ...
  ]

這里重要的是您提供的代碼位於ask turtles塊中。 ask會以隨機順序一一遍歷所有海龜並運行每個海龜的代碼。 假設它以“烏龜 A”開頭。

  1. 計算海龜 A 的中心性值
  2. 該值與其他海龜的中心變量的所有值進行比較 - 但它們尚未計算,因此存儲值為 0
  3. 由於計算的中心度值不為0,它大於所有其他海龜的存儲值,所以它是最大值
  4. 海龜 A 獲得最大的 state

多只海龜也會發生同樣的事情。 第一個海龜,然后是中心值大於所有先前海龜的任何海龜,都將分配給您想要的最大值 state。

解決這個問題的方法是首先計算所有海龜的中心性。 然后您可以根據它分配狀態。

對於您的其他問題,請查找max-n-of 如果您在該問題上需要更多幫助,請提出單獨的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM