[AMPL 15235] Random numbers considering different probabilities

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[AMPL 15235] Random numbers considering different probabilities

fernandafreitasufmg
Good night,

I have 20 numbers which have different probabilities of being selected. How can I randomly generate one number based on these probabilities?
Thank you!

Best regards,
Fernanda

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

[AMPL 15249] Re: Random numbers considering different probabilities

ptiwari
You can use Uniform(0,1) to generate the random number on [0,1). You need to map the uniform random results to your probabilities to generate the number. One way to map is to compute the cumulative probability distribution. For example:

number: {4, 8, 3}
Prob: {0.2, 0.7, 0.1}
Cumulative Probability Distribution: {0.2, 0.9, 1}

Let x = uniform(0,1)
then
number = 4 if 0<= x<0.2
number = 8 if 0.2<=x<0.9
number = 3 if 0.9<=x<1

Thanks,
Paras

On Tuesday, November 28, 2017 at 1:23:28 PM UTC-8, [hidden email] wrote:
Good night,

I have 20 numbers which have different probabilities of being selected. How can I randomly generate one number based on these probabilities?
Thank you!

Best regards,
Fernanda

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

[AMPL 15256] Re: Random numbers considering different probabilities

fernandafreitasufmg
Thank you!!

Em quarta-feira, 29 de novembro de 2017 18:50:54 UTC-2, ptiwari escreveu:
You can use Uniform(0,1) to generate the random number on [0,1). You need to map the uniform random results to your probabilities to generate the number. One way to map is to compute the cumulative probability distribution. For example:

number: {4, 8, 3}
Prob: {0.2, 0.7, 0.1}
Cumulative Probability Distribution: {0.2, 0.9, 1}

Let x = uniform(0,1)
then
number = 4 if 0<= x<0.2
number = 8 if 0.2<=x<0.9
number = 3 if 0.9<=x<1

Thanks,
Paras

On Tuesday, November 28, 2017 at 1:23:28 PM UTC-8, [hidden email] wrote:
Good night,

I have 20 numbers which have different probabilities of being selected. How can I randomly generate one number based on these probabilities?
Thank you!

Best regards,
Fernanda

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.