Decision Optimization

 View Only
  • 1.  random value in normal distribution

    Posted Sun December 26, 2010 08:55 AM

    Originally posted by: victortkl


    hi, how can i create a variable that is in normal distribution. in the reference, only rand() and rand(int) is available.


  • 2.  Re: random value in normal distribution

    Posted Wed January 05, 2011 09:08 AM
    Hi,

    have you thought about using Box Muller transform?

    I would write

    int n=1000000;
     int BIG=1000000;
     
     float x[i in 1..n]=-1+2*rand(BIG)/BIG;
     float y[i in 1..n]=-1+2*rand(BIG)/BIG;;
     
     float w[i in 1..n]=sqrt(x[i]*x[i]+y[i]*y[i]);
     
     
     float w2[i in 1..n]=(w[i]<=1)?(-2*ln(w[i])/w[i]):-1;
     
     float x2[i in 1..n]=(w[i]<=1)?x[i]*w2[i]:-1;
     float y2[i in 1..n]=(w[i]<=1)?y[i]*w2[i]:-1;
    


    the values of x2 and y2 when w<=1 obey a normal distribution

    Regards

    Alex


  • 3.  Re: random value in normal distribution

    Posted Wed January 05, 2011 09:30 AM

    Originally posted by: victortkl


    thank you. it's a good idea
    but it needs much codes.
    now i prefer to generate the random value in database...


  • 4.  Re: random value in normal distribution

    Posted Wed January 05, 2011 09:47 AM
    Hi,

    what you can also do if you accept to use external ways is to use the java class java.util.Random with the function nextGaussian.
    You are able to call this from OPL with the function IloOplCallJava

    regards

    Alex


  • 5.  Re: random value in normal distribution

    Posted Wed January 05, 2011 08:52 PM

    Originally posted by: victortkl


    thank you. but using java is a bit difficult to me. :-)


  • 6.  Re: random value in normal distribution

    Posted Thu January 06, 2011 01:13 PM

    Originally posted by: Ferenc Katai


    Hello there,
    may I know in what context do you want to use normal distribution? is a search you are designing or maybe some perturbation to data?
    cheers


  • 7.  RE: Re: random value in normal distribution

    Posted Mon June 20, 2022 06:40 AM
    Hi,

    full example at https://github.com/AlexFleischerParis/howtowithopl/blob/master/randomnumber.mod

    And you can also rely on java rand through IloOplCallJava

    regards

    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------