我正在尝试使用netlogo模拟PDG,并研究内存在合作中的作用。我希望内存为系数m <1,该系数乘以当时的总和加上历史累计收益。我想研究记忆在合作模型中的作用,并观察世界上有无记忆的合作者的频率 预先谢谢你
globals [payoffs]
patches-own [payments]
to setup
clear-all
; green: cooperate, red: defect
ask patches [
set payments []
set pcolor green
ifelse ( random-float 1.0 < cooperative-probability) [
set pcolor green
] [
set pcolor red
]
;; cooperate: 0, defect 1
set payoffs [[3 0] [4 1]]
]
reset-ticks
end
to-report get-payment [my-color her-color]
let my-action ifelse-value (my-color = green) [0] [1]
let her-action ifelse-value (her-color = green) [0] [1]
report item her-action (item my-action payoffs)
end
to go
ask patches [
play
]
ask patches [
update
]
tick
end
; returns the first x elements in l, or fewer.
to-report first-x [x l]
let result []
if (length l = 0) [report []]
repeat x [
set result lput (first l) result
set l butfirst l
if (length l = 0) [
report result
]
]
report result
end
; patches methods
to play
let chosen-one one-of neighbors
set payments fput (get-payment pcolor [pcolor] of chosen-one) payments
end
to-report gain
report sum first-x history-length payments
end
to update
let chosen-one one-of neighbors
if ([gain] of chosen-one > gain) [
set pcolor [pcolor] of chosen-one
]
end
答案 0 :(得分:1)
我对您的问题的解释是,您想要一种计算衰减的累积变量值(收益)的方法。做到这一点的方法是存储变量的当前值,并在每个刻度时使用新收益的总和和旧累积收益的折现值来更新该值。这意味着,例如,过去两个滴答声的收益在累计中已被打折两次。
这里以完整模型为例。我已将收益固定为每勾5点,以便您可以查看记忆的效果。
globals [ memory ] ; how much to retain each tick
turtles-own [ payoff ]
to setup
clear-all
set memory 0.9
create-turtles 1
inspect one-of turtles
reset-ticks
end
to go
ask turtles
[ let new-payoff 5
set payoff new-payoff + memory * payoff
]
end
第一个刻度之后,收益为5。第二个刻度之后,收益为9.5(= 5 + 0.9 * 5)。在第三个刻度之后,收益为13.55(= 5 + 0.9 * 9.5,这也是5 + 0.9 * 5 + 0.9 * 0.9 * 5)