问题描述
我想进行加权随机抽取,以获取拟议的here中NetLogo中代理类型的属性。因此,我想使用rnd扩展名。我还想将存储在表中的数据用于概率。下面是我到目前为止有效的方法。
但是,我必须手动将表中的数据存储在列表中以备将来使用。我的问题是,是否有必要这样做,或者因为我拥有更多的属性和年龄组,是否有一种更有效(更快)的方法。
extensions[csv rnd]
globals[prob-age]
turtles-own [ age ]
breed [ AT1 AT1s ]
breed [ AT2 AT2s ]
to setup
clear-all
file-close-all ; Close any files open from last run
; uncomment here and comment below to run the code without the data table
;let age_written["65-69" "70-74" "75+"]
;let prob1[0.08 0.87 0.05]
;let prob2[0.09 0.1 0.81]
load-age ;load the csv file
;store attributes as lists
let age_written (list item 1 (item 0 prob-age) item 2 (item 0 prob-age) item 3 (item 0 prob-age) )
let prob1 (list item 1 (item 1 prob-age) item 2 (item 1 prob-age) item 3 (item 1 prob-age) )
let prob2 (list item 1 (item 2 prob-age) item 2 (item 2 prob-age) item 3 (item 2 prob-age) )
;map lists
let pairs_AT1 (map list age_written prob1)
let pairs_AT2 (map list age_written prob2)
;create turtles (agent typologies)
create-AT1 100 [ ;create first agent-typology with a weighted random draw
set age first rnd:weighted-one-of-list pairs_AT1 [ [p] -> last p ]
]
create-AT2 100 [
set age first rnd:weighted-one-of-list pairs_AT2 [ [p] -> last p ]
]
reset-ticks
end
; procedure to load a csv file
to load-age
file-close-all ; close all open files
if not file-exists? "Age_prob_1.csv" [
user-message "No file 'Age_prob_1.csv' exists!"
stop
]
file-open "Age_prob_1.csv" ; open the file with the turtle data
set prob-age csv:from-file "Age_prob_1.csv" ; load data into variable
file-close ; make sure to close the file
end
数据可用here。但是我也将其存储为代码中的列表。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)