我使用多项logit模型作为概率函数来模拟特定代理集的选择,当我计算出P1,P2和P3的概率以及我如何使用这些概率时,我的问题就出现了。实际建模选择。我的想法是使用类似于模型库中的彩票获取示例,但问题在于,在这种情况下,概率未设置但是每个滴答都会改变,即使P1具有最低的发生机会,它也可能具有最高的机会。下一次迭代。 谢谢你的帮助。
PS。对于每种情况,多项Logit的Eq是P {ik} = {exp(utilityik)\ sum exp(utilityjk)}。
to flightchoice-business
let flight-time1 mean [time1] of airline1
let airfare-airline1 mean [airfare] of airline1
set beta1 .8
set beta2 .2
set utility1 beta1 * (airfare-airline1) + beta2 * abs((time - flight-time1) * 10)
let flight-time2 mean [time1] of airline2
let airfare-airline2 mean [airfare] of airline2
set beta1 .8
set beta2 .2
set utility2 beta1 * (airfare-airline2) + beta2 * abs((time - flight-time2) * 10)
let flight-time3 mean [time1] of airline3
let airfare-airline3 mean [airfare] of airline3
set beta1 .8
set beta2 .2
set utility3 beta1 * (airfare-airline3) + beta2 * abs((time - flight-time3) * 10)
let cumulsum exp(utility1) + exp(utility2) + exp(utility3)
let P1 exp(utility1) / cumulsum
let P2 exp(utility2) / cumulsum
let P3 exp(utility3) / cumulsum
let buy random-float P1 + P2 + P3
end
答案 0 :(得分:2)
你走在正确的轨道上。您的代码应继续如下:
...
let buy random-float P1 + P2 + P3
ifelse buy < P1 [
do-stuff-with-P1
] [
ifelse buy < P1 + P2 [
do-stuff-with-P2
] [
do-stuff-with-P3
]
]
你可以用一个列表的函数来概括它,在我看来它更好一些:
to-report weighted-random [ weights ]
let pick random-float sum weights
let total 0
let i 0
foreach weights [
set total total + ?
if pick < total [ report i ]
set i i + 1
]
end
您可以按如下方式使用:
let buy weighted-random (list P1 P2 P3)
if buy = 0 [ do-stuff-with-P1 ]
if buy = 1 [ do-stuff-with-P2 ]
if buy = 2 [ do-stuff-with-P3 ]