我正在 Julia 中建立一个微观模拟模型。我已经构建了我的函数结构,它对于 1 个“人”来说运行得很好。我想编写脚本通过模型运行 100000 多人并将结果保存在一个位置。
最终我想并行执行这个。
下面我包含了一个带有虚拟概率的简单工作版本的代码。
using Distributions
# Microsim function
function MicroSim(start_age, stages)
stage = 0
age = start_age
# Set all trackers to 0
Death_tracker = 0
Disease_tracker = 0
# While loop
while stage <= stages
age = age
###########################################################
# Probability of Death
pD = 0.02
if age == 100
pD = 1.0
else
pD = pD
end
# Coin flip
dist_pD = Bernoulli(pD)
Died = rand(dist_pD, 1)
if Died == [1]
Death_tracker = 1
# death tracker loop break
if Death_tracker == 1
# println("I died")
break
end
else
Death_tracker = Death_tracker
end
###########################################################
# Update age and stage
age = age + 1
stage = stage + 1
end
return age, Death_tracker
end
MicroSim(18,100)