Pregunta

I have used multinomial logit model as the probability function to model the choice for a particular set of agents, my problem comes at the end when I have calculated the Probabilities which are P1, P2, and P3 and how I can use these to actually model the choice. My idea was to use something like the lotterywinning example from the modellibrary, but the problem is that in this case the Probabilities are not set but change for each tick and even though P1 has the lowest chance to occur it can have the highest chance in the next iteration. Thanks for your help.

ps. Eq for Multinomial Logit is P{ik}= {exp(utilityik) \sum exp(utilityjk)}, for each of the cases.

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
¿Fue útil?

Solución

You're on the right track. Your code should continue as follows:

...
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
  ]
]

You can generalize this with a function that takes a list, and it's a bit nicer in my opinion:

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

You'd use this as follows:

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 ]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top