当前位置: 首页>>代码示例>>Java>>正文


Java MersenneTwisterFast.nextDouble方法代码示例

本文整理汇总了Java中ec.util.MersenneTwisterFast.nextDouble方法的典型用法代码示例。如果您正苦于以下问题:Java MersenneTwisterFast.nextDouble方法的具体用法?Java MersenneTwisterFast.nextDouble怎么用?Java MersenneTwisterFast.nextDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ec.util.MersenneTwisterFast的用法示例。


在下文中一共展示了MersenneTwisterFast.nextDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: nextTriangular

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
 * Returns a random number from the standard Triangular distribution in (-1,1).
 * <p>
 * <b>Implementation:</b> Inversion method.
 * This is a port of <tt>tra.c</tt> from the <A HREF="http://www.cis.tu-graz.ac.at/stat/stadl/random.html">C-RAND / WIN-RAND</A> library.
 * <p>
 */
    public static double nextTriangular(MersenneTwisterFast randomGenerator) {
/******************************************************************
 *                                                                *
 *     Triangular Distribution - Inversion: x = +-(1-sqrt(u))     *
 *                                                                *
 ******************************************************************
 *                                                                *
 * FUNCTION :   - tra samples a random number from the            *
 *                standard Triangular distribution in (-1,1)      *
 * SUBPROGRAM : - drand(seed) ... (0,1)-Uniform generator with    *
 *                unsigned long integer *seed.                    *
 *                                                                *
 ******************************************************************/

        double u;
        u=randomGenerator.nextDouble();
        if (u<=0.5) return(Math.sqrt(2.0*u)-1.0);                      /* -1 <= x <= 0 */
        else return(1.0-Math.sqrt(2.0*(1.0-u)));                 /*  0 <= x <= 1 */
        }
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:27,代码来源:Distributions.java

示例2: defaultParticleFilter

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
public static ParticleFilter<Double> defaultParticleFilter(
        double min, double max, double drift,
        int size, MersenneTwisterFast random)
{
    return new ParticleFilter<>(
            new Function<MersenneTwisterFast, Double>() {
                @Override
                public Double apply(MersenneTwisterFast mersenneTwisterFast) {
                    return mersenneTwisterFast.nextDouble() * (max - min) + min;
                }
            },
            new Function<Double, Double>() {
                @Override
                public Double apply(Double previous) {
                    return  Math.max(
                            Math.min(previous + random.nextGaussian()*drift,max),min);
                }
            },
            size,random
    );

}
 
开发者ID:CarrKnight,项目名称:POSEIDON,代码行数:23,代码来源:ParticleFilter.java

示例3: nextErlang

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
* Returns an erlang distributed random number with the given variance and mean.
*/
   public static double nextErlang(double variance, double mean, MersenneTwisterFast randomGenerator) {
       int k = (int)( (mean * mean ) / variance + 0.5 );
       k = (k > 0) ? k : 1;
       double a = k / mean;

       double prod = 1.0;
       for (int i = 0; i < k; i++) prod *= randomGenerator.nextDouble();
       return -Math.log(prod)/a;
       }
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:13,代码来源:Distributions.java

示例4: nextGeometric

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
 * Returns a discrete geometric distributed random number; <A HREF="http://www.statsoft.com/textbook/glosf.html#Geometric Distribution">Definition</A>.
 * <p>
 * <tt>p(k) = p * (1-p)^k</tt> for <tt> k &gt;= 0</tt>.
 * <p>
 * <b>Implementation:</b> Inversion method.
 * This is a port of <tt>geo.c</tt> from the <A HREF="http://www.cis.tu-graz.ac.at/stat/stadl/random.html">C-RAND / WIN-RAND</A> library.
 * @param p must satisfy <tt>0 &lt; p &lt; 1</tt>.
 * <p>
 */
    public static int nextGeometric(double p, MersenneTwisterFast randomGenerator) {
/******************************************************************
 *                                                                *
 *              Geometric Distribution - Inversion                *
 *                                                                *
 ******************************************************************
 *                                                                *
 * On generating random numbers of a discrete distribution by     *
 * Inversion normally sequential search is necessary, but in the  *
 * case of the Geometric distribution a direct transformation is  *
 * possible because of the special parallel to the continuous     *
 * Exponential distribution Exp(t):                               *
 *    X - Exp(t): G(x)=1-exp(-tx)                                 *
 *        Geo(p): pk=G(k+1)-G(k)=exp(-tk)*(1-exp(-t))             *
 *                p=1-exp(-t)                                     *
 * A random number of the Geometric distribution Geo(p) is        *
 * obtained by k=(long int)x, where x is from Exp(t) with         *
 * parameter t=-log(1-p).                                         *
 *                                                                *
 ******************************************************************
 *                                                                *
 * FUNCTION:    - geo samples a random number from the Geometric  *
 *                distribution with parameter 0<p<1.              *
 * SUBPROGRAMS: - drand(seed) ... (0,1)-Uniform generator with    *
 *                unsigned long integer *seed.                    *
 *                                                                *
 ******************************************************************/
        double u = randomGenerator.nextDouble();
        return (int)(Math.log(u)/Math.log(1.0-p));
        }
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:41,代码来源:Distributions.java

示例5: generateLocal

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
 * this gets called for each tile by the map as the tile is created. Do not expect it to come in order
 *  @param biology          the global biology (species' list) object
 * @param seaTile          the sea-tile to populate
 * @param random           the randomizer
 * @param mapHeightInCells height of the map
 * @param mapWidthInCells  width of the map
 * @param map
 */
@Override
public LocalBiology generateLocal(
        GlobalBiology biology, SeaTile seaTile,
        MersenneTwisterFast random, int mapHeightInCells,
        int mapWidthInCells, NauticalMap map) {

    //if there is no manager, we need to create and start it now
    if(manager == null)
    {
        manager = new AllocatorManager(false,
                                       allocators,
                                       biology);
        manager.start(map,random);
    }

    //create carrying capcities and put them in
    Double[] carringCapacities = new  Double[biology.getSize()];
    Double[] currentCapacity = new Double[biology.getSize()];
    for(Species species : biology.getSpecies())
    {
        Double k = carryingCapacity.get(species.getIndex()).apply(random) *
                manager.getWeight(species, seaTile,map ,random );
        carringCapacities[species.getIndex()] = k;

        Double min = minInitialCapacity.apply(random);
        Double max = maxInitialCapacity.apply(random);
        currentCapacity[species.getIndex()] =
                ((max - min)*random.nextDouble(true, true) + min)
                        * k;
    }
    BiomassLocalBiology local = new BiomassLocalBiology(currentCapacity, carringCapacities);
    biologies.put(seaTile,local);

    return local;

}
 
开发者ID:CarrKnight,项目名称:POSEIDON,代码行数:46,代码来源:GenericBiomassInitializer.java

示例6: randomRounding

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
 * 8.123 is rounded to 9 with probability of 12.3%
 * @param x number to round
 * @param random randomiser
 * @return x either ceiled or floored
 */
public static int randomRounding(double x, MersenneTwisterFast random){
    double signum = Math.signum(x);
    x = Math.abs(x);
    boolean ceiling = random.nextDouble() < x- (int)x;
    int toReturn = (int)(ceiling ? Math.ceil(x) : Math.floor(x));

    return signum > 0 ? toReturn : -toReturn;
}
 
开发者ID:CarrKnight,项目名称:POSEIDON,代码行数:15,代码来源:FishStateUtilities.java

示例7: GeographicallyWeightedRegression

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
public GeographicallyWeightedRegression(
        NauticalMap map, double exponentialForgetting,
        Distance distance, double rbfBandwidth,
        ObservationExtractor[] nonInterceptExtractors,
        double initialMin,
        double initialMax,
        double initialUncertainty,
        MersenneTwisterFast random) {
    this.distance = distance;
    this.map = map;
    Preconditions.checkArgument(initialMax>initialMin);
    //get extractors and add intercept
    this.extractors = new ObservationExtractor[nonInterceptExtractors.length+1];
    for(int i=0; i<nonInterceptExtractors.length; i++)
        this.extractors[i+1] = nonInterceptExtractors[i];
    this.extractors[0] = new InterceptExtractor();

    this.kernel = new RBFDistance(rbfBandwidth);

    //each tile its own lowess with a random intercept
    List<SeaTile> tiles = map.getAllSeaTilesExcludingLandAsList();
    for(SeaTile tile : tiles) {
        double[] beta = new double[nonInterceptExtractors.length+1];
        beta[0] = random.nextDouble() *(initialMax-initialMin) + initialMin;
        lowesses.put(tile, new LeastSquareFilter(nonInterceptExtractors.length + 1,
                                                 initialUncertainty, beta,
                                                 exponentialForgetting));
    }



}
 
开发者ID:CarrKnight,项目名称:POSEIDON,代码行数:33,代码来源:GeographicallyWeightedRegression.java

示例8: nextBurr2

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
 * Returns a random number from the Burr III, IV, V, VI, IX, XII distributions.
 * <p>
 * <b>Implementation:</b> Inversion method.
 * This is a port of <tt>burr2.c</tt> from the <A HREF="http://www.cis.tu-graz.ac.at/stat/stadl/random.html">C-RAND / WIN-RAND</A> library.
 * C-RAND's implementation, in turn, is based upon
 * <p>
 * L. Devroye (1986): Non-Uniform Random Variate Generation, Springer Verlag, New York.                                      
 * <p>
 * @param r must be &gt; 0.
 * @param k must be &gt; 0.
 * @param nr the number of the burr distribution (e.g. 3,4,5,6,9,12).
 */
    public static double nextBurr2(double r, double k, int nr, MersenneTwisterFast randomGenerator) {
/******************************************************************
 *                                                                *
 *      Burr III, IV, V, VI, IX, XII Distribution - Inversion     *
 *                                                                *
 ******************************************************************
 *                                                                *
 * FUNCTION :   - burr2 samples a random number from one of the   *
 *                Burr III, IV, V, VI, IX, XII distributions with *
 *                parameters r > 0 and k > 0, where the no. of    *
 *                the distribution is indicated by a pointer      *
 *                variable.                                       *
 * REFERENCE :  - L. Devroye (1986): Non-Uniform Random Variate   *
 *                Generation, Springer Verlag, New York.          *
 * SUBPROGRAM : - drand(seed) ... (0,1)-Uniform generator with    *
 *                unsigned long integer *seed.                    *
 *                                                                *
 ******************************************************************/
        double y,u;
        u = randomGenerator.nextDouble();                     // U(0/1)       
        y = Math.exp(-Math.log(u)/r)-1.0;              // u^(-1/r) - 1 
        switch (nr) {
        case 3  :               // BURR III 
            return(Math.exp(-Math.log(y)/k));      // y^(-1/k) 

        case 4  :               // BURR IV  
            y=Math.exp(k*Math.log(y))+1.0;         // y^k + 1 
            y=k/y;
            return(y);

        case 5  :               // BURR V  
            y=Math.atan(-Math.log(y/k));           // arctan[log(y/k)] 
            return(y);

        case 6  :               // BURR VI  
            y=-Math.log(y/k)/r;
            y=Math.log(y+Math.sqrt(y*y +1.0));
            return(y);

        case 9  :               // BURR IX  
            y=1.0+2.0*u/(k*(1.0-u));
            y=Math.exp(Math.log(y)/r)-1.0;         // y^(1/r) -1 
            return Math.log(y);

        case 12 :               // BURR XII 
            return Math.exp(Math.log(y)/k);        // y^(1/k) 
            }
        return 0;
        }
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:63,代码来源:Distributions.java

示例9: apply

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
@Override
public PeriodicUpdateGearStrategy apply(FishState model) {

    locker.presentKey(
            model,
            new Supplier<Startable>() {
                @Override
                public Startable get() {

                    model.registerStartable(SELECTIVITY_DATA_GATHERERS);
                    return SELECTIVITY_DATA_GATHERERS;

                }
            }
    );
    return new PeriodicUpdateGearStrategy
            (
                    yearly,
                    new RandomStep<Gear>() {
                        @Override
                        public Gear randomStep(FishState state,
                                               MersenneTwisterFast random,
                                               Fisher fisher,
                                               Gear current) {
                            SelectivityAbundanceGear actualGear =
                                    (SelectivityAbundanceGear)
                                            DecoratorGearPair.getActualGear(current).getDecorated();


                            double newAParameter = actualGear.getaParameter() *(1d-maxPercentageChangeA + 2 * random.nextDouble()*maxPercentageChangeA);
                            double newBParameter = actualGear.getbParameter() *(1d-maxPercentageChangeB + 2 * random.nextDouble()*maxPercentageChangeB);
                            if(actualGear.getRetention()==null)
                                return new SelectivityAbundanceGear(
                                        actualGear.getLitersOfGasConsumedEachHourFishing(),
                                        actualGear.getCatchabilityFilter(),
                                        new LogisticAbundanceFilter(newAParameter,newBParameter,
                                                actualGear.getSelectivity().isMemoization(),
                                                actualGear.getSelectivity().isRounding())
                                );
                            else
                                return new SelectivityAbundanceGear(
                                        actualGear.getLitersOfGasConsumedEachHourFishing(),
                                        actualGear.getCatchabilityFilter(),
                                        new LogisticAbundanceFilter(newAParameter,newBParameter,
                                                actualGear.getSelectivity().isMemoization(),
                                                actualGear.getSelectivity().isRounding()),
                                        actualGear.getRetention()
                                );
                        }
                    },
                    probability.apply(model)
            );


}
 
开发者ID:CarrKnight,项目名称:POSEIDON,代码行数:56,代码来源:PeriodicUpdateSelectivityFactory.java

示例10: hmdu

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
* Returns a random number from the distribution.
*/
   protected int hmdu(int N, int M, int n, MersenneTwisterFast randomGenerator) {

       int            I, K;
       double              p, nu, c, d, U;

       if (N != N_last || M != M_last || n != n_last) {   // set-up           */
           N_last = N;
           M_last = M;
           n_last = n;

           Mp = (double) (M + 1);
           np = (double) (n + 1);  N_Mn = N - M - n;

           p  = Mp / (N + 2.0);
           nu = np * p;                             /* mode, real       */
           if ((m = (int) nu) == nu && p == 0.5) {     /* mode, integer    */
               mp = m--;
               }
           else {
               mp = m + 1;                           /* mp = m + 1       */
               }

           /* mode probability, using the external function flogfak(k) = ln(k!)    */
           fm = Math.exp(Arithmetic.logFactorial(N - M) - Arithmetic.logFactorial(N_Mn + m) - Arithmetic.logFactorial(n - m)
               + Arithmetic.logFactorial(M)     - Arithmetic.logFactorial(M - m)    - Arithmetic.logFactorial(m)
               - Arithmetic.logFactorial(N)     + Arithmetic.logFactorial(N - n)    + Arithmetic.logFactorial(n)   );

           /* safety bound  -  guarantees at least 17 significant decimal digits   */
           /*                  b = min(n, (long int)(nu + k*c')) */
           b = (int) (nu + 11.0 * Math.sqrt(nu * (1.0 - p) * (1.0 - n/(double)N) + 1.0));  
           if (b > n) b = n;
           }

       for (;;) {
           if ((U = randomGenerator.nextDouble() - fm) <= 0.0)  return(m);
           c = d = fm;

           /* down- and upward search from the mode                                */
           for (I = 1; I <= m; I++) {
               K  = mp - I;                                   /* downward search  */
               c *= (double)K/(np - K) * ((double)(N_Mn + K)/(Mp - K));
               if ((U -= c) <= 0.0)  return(K - 1);

               K  = m + I;                                    /* upward search    */
               d *= (np - K)/(double)K * ((Mp - K)/(double)(N_Mn + K));
               if ((U -= d) <= 0.0)  return(K);
               }

           /* upward search from K = 2m + 1 to K = b                               */
           for (K = mp + m; K <= b; K++) {
               d *= (np - K)/(double)K * ((Mp - K)/(double)(N_Mn + K));
               if ((U -= d) <= 0.0)  return(K);
               }
           }
       }
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:59,代码来源:HyperGeometric.java

示例11: b00

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
* 
*/
   protected double b00(double a, double b, MersenneTwisterFast randomGenerator) {
       double             U, V, X, Z;

       if (a != a_last || b != b_last) {
           a_last = a;
           b_last = b;

           a_ = a - 1.0;
           b_ = b - 1.0;
           c = (b * b_) / (a * a_);                            // b(1-b) / a(1-a) 
           t = (c == 1.0) ? 0.5 : (1.0 - Math.sqrt(c))/(1.0 - c);  // t = t_opt      
           fa = Math.exp(a_ * Math.log(t));
           fb = Math.exp(b_ * Math.log(1.0 - t));              // f(t) = fa * fb  

           p1 = t/a;                                           // 0 < X < t       
           p2 = (1.0 - t)/b + p1;                              // t < X < 1       
           }

       for (;;) {
           if ((U = randomGenerator.nextDouble() * p2) <= p1) {       //  X < t  
               Z = Math.exp(Math.log(U/p1) / a);  X = t*Z;
               // squeeze accept:   L(x) = 1 + (1 - b)x                                 
               if ((V = randomGenerator.nextDouble() * fb) <= 1.0 - b_*X)  break;
               // squeeze reject:   U(x) = 1 + ((1 - t)^(b-1) - 1)/t * x                
               if (V <= 1.0 + (fb - 1.0)*Z) {
                   // quotient accept:  q(x) = (1 - x)^(b-1) / fb                           
                   if (Math.log(V) <= b_ * Math.log(1.0 - X))  break;
                   }
               }
           else {                                                      //  X > t  
               Z = Math.exp(Math.log((U-p1)/(p2-p1)) / b);  X = 1.0 - (1.0 - t)*Z;
               // squeeze accept:   L(x) = 1 + (1 - a)(1 - x)                           
               if ((V = randomGenerator.nextDouble() * fa) <= 1.0 - a_*(1.0 - X))  break;
               // squeeze reject:   U(x) = 1 + (t^(a-1) - 1)/(1 - t) * (1 - x)          
               if (V <= 1.0 + (fa - 1.0)*Z) {
                   // quotient accept:  q(x) = x^(a-1) / fa                                 
                   if (Math.log(V) <= a_ * Math.log(X))  break;
                   }
               }
           }
       return(X);
       }
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:46,代码来源:Beta.java

示例12: b01

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
* 
*/
   protected double b01(double a, double b, MersenneTwisterFast randomGenerator) {
       double             U, V, X, Z;

       if (a != a_last || b != b_last) {
           a_last = a;
           b_last = b;

           a_ = a - 1.0;
           b_ = b - 1.0;
           t = a_/(a - b);                   // one step Newton * start value t   
           fb = Math.exp((b_ - 1.0) * Math.log(1.0 - t));  fa = a - (a + b_)*t;
           t -= (t - (1.0 - fa) * (1.0 - t)*fb / b) / (1.0 - fa*fb);
           fa = Math.exp(a_ * Math.log(t));
           fb = Math.exp(b_ * Math.log(1.0 - t));             // f(t) = fa * fb  
           if (b_ <= 1.0) {
               ml = (1.0 - fb) / t;                           //   ml = -m1     
               mu = b_ * t;                                   //   mu = -m2 * t 
               }
           else {
               ml = b_;
               mu = 1.0 - fb;
               }
           p1 = t/a;                                           //  0 < X < t     
           p2 = fb * (1.0 - t)/b + p1;                         //  t < X < 1      
           }

       for (;;) {
           if ((U = randomGenerator.nextDouble() * p2) <= p1) {       //  X < t  
               Z = Math.exp(Math.log(U/p1) / a);  X = t*Z;
               // squeeze accept:   L(x) = 1 + m1*x,  ml = -m1                          
               if ((V = randomGenerator.nextDouble() ) <= 1.0 - ml*X)  break;
               // squeeze reject:   U(x) = 1 + m2*x,  mu = -m2 * t                      
               if (V <= 1.0 - mu*Z) {
                   // quotient accept:  q(x) = (1 - x)^(b-1)                                
                   if (Math.log(V) <= b_ * Math.log(1.0 - X))  break;
                   }
               }
           else {                                                      //  X > t  
               Z = Math.exp(Math.log((U-p1)/(p2-p1)) / b);  X = 1.0 - (1.0 - t)*Z;
               // squeeze accept:   L(x) = 1 + (1 - a)(1 - x)                           
               if ((V = randomGenerator.nextDouble()  * fa) <= 1.0 - a_*(1.0 - X))  break;
               // squeeze reject:   U(x) = 1 + (t^(a-1) - 1)/(1 - t) * (1 - x)          
               if (V <= 1.0 + (fa - 1.0)*Z) {
                   // quotient accept:  q(x) = (x)^(a-1) / fa                               
                   if (Math.log(V) <= a_ * Math.log(X))  break;
                   }
               }
           }
       return(X);
       }
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:54,代码来源:Beta.java

示例13: nextInt

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
* Returns a random number from the distribution; bypasses the internal state.
*/
   private int nextInt(double theMean) {
       /* 
        * Adapted from "Numerical Recipes in C".
        */
       double xm = theMean;
       double g = this.cached_g;

       if (xm == -1.0 ) return 0; // not defined
       if (xm < SWITCH_MEAN ) {
           int poisson = -1;
           double product = 1;
           do {
               poisson++;
               product *= randomGenerator.nextDouble();
               } while ( product >= g );
           // bug in CLHEP 1.4.0: was "} while ( product > g );"
           return poisson;
           }
       else if (xm < MEAN_MAX ) {
           double t;
           double em;
           double sq = this.cached_sq;
           double alxm = this.cached_alxm;

           MersenneTwisterFast rand = this.randomGenerator;
           do { 
               double y;
               do {
                   y = Math.tan(Math.PI*rand.nextDouble());
                   em = sq*y + xm;
                   } while (em < 0.0);
               em = (double) (int)(em); // faster than em = Math.floor(em); (em>=0.0)
               t = 0.9*(1.0 + y*y)* Math.exp(em*alxm - logGamma(em + 1.0) - g);
               } while (rand.nextDouble() > t);
           return (int) em;
           }
       else { // mean is too large
           return (int) xm;
           }
       }
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:44,代码来源:PoissonSlow.java

示例14: generateZeta

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
 * Returns a zeta distributed random number.
 */
    protected long generateZeta(double ro, double pk, MersenneTwisterFast randomGenerator) {
/******************************************************************
 *                                                                *
 *            Zeta Distribution - Acceptance Rejection            *
 *                                                                *
 ******************************************************************
 *                                                                *
 * To sample from the Zeta distribution with parameters ro and pk *
 * it suffices to sample variates x from the distribution with    *
 * density function  f(x)=B*{[x+0.5]+pk}^(-(1+ro)) ( x > .5 )     *
 * and then deliver k=[x+0.5].                                    *
 * 1/B=Sum[(j+pk)^-(ro+1)]  (j=1,2,...) converges for ro >= .5 .  *
 * It is not necessary to compute B, because variates x are       *
 * generated by acceptance rejection using density function       *
 * g(x)=ro*(c+0.5)^ro*(c+x)^-(ro+1).                              *
 *                                                                *                                                                *
 * Integer overflow is possible, when ro is small (ro <= .5) and  *
 * pk large. In this case a new sample is generated. If ro and pk *
 * satisfy the inequality   ro > .14 + pk*1.85e-8 + .02*ln(pk)    *
 * the percentage of overflow is less than 1%, so that the        *
 * result is reliable.                                            *
 * NOTE: The comment above is likely to be nomore valid since     *
 * the C-version operated on 32-bit integers, while this Java     *
 * version operates on 64-bit integers. However, the following is *
 * still valid:                                                   *                                                                *
 *                                                                *                                                                *
 * If either ro > 100  or  k > 10000 numerical problems in        *
 * computing the theoretical moments arise, therefore ro<=100 and *
 * k<=10000 are recommended.                                      *
 *                                                                *
 ******************************************************************
 *                                                                *
 * FUNCTION:    - zeta  samples a random number from the          *
 *                Zeta distribution with parameters  ro > 0  and  *
 *                pk >= 0.                                        *
 * REFERENCE:   - J. Dagpunar (1988): Principles of Random        *
 *                Variate  Generation, Clarendon Press, Oxford.   *
 *                                                                *
 ******************************************************************/
        double u,v,e,x;
        long k;

        if (ro != ro_prev || pk != pk_prev) {                   // Set-up 
            ro_prev = ro;
            pk_prev = pk;
            if (ro<pk) {
                c = pk-0.5;
                d = 0;
                }
            else {
                c = ro-0.5;
                d = (1.0+ro)*Math.log((1.0+pk)/(1.0+ro));
                }
            }
        do {
            do {
                u=randomGenerator.nextDouble();
                v=randomGenerator.nextDouble();
                x = (c+0.5)*Math.exp(-Math.log(u)/ro) - c;
                } while (x<=0.5 || x>=maxlongint);
                
            k = (int) (x+0.5);
            e = -Math.log(v);
            } while ( e < (1.0+ro)*Math.log((k+pk)/(x+c)) - d );
        
        return k;
        }
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:71,代码来源:Zeta.java

示例15: generateLocal

import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
  * this gets called for each tile by the map as the tile is created. Do not expect it to come in order
  *  @param biology          the global biology (species' list) object
  * @param seaTile          the sea-tile to populate
  * @param random           the randomizer
  * @param mapHeightInCells height of the map
  * @param mapWidthInCells  width of the map
  * @param map
  */
 @Override
 public LocalBiology generateLocal(
         GlobalBiology biology, SeaTile seaTile, MersenneTwisterFast random, int mapHeightInCells,
         int mapWidthInCells, NauticalMap map) {

     if(seaTile.getAltitude() > 0)
         return new EmptyLocalBiology();

     //start by assuming both species are in
     double firstSpeciesCapacity = this.firstSpeciesCapacity.apply(random);
     double secondSpeciesRatio = ratioFirstToSecondSpecies.apply(random);
     Preconditions.checkArgument(firstSpeciesCapacity > 0);
     Preconditions.checkArgument(secondSpeciesRatio>=0);
//     Preconditions.checkArgument(secondSpeciesRatio<=1);
     double secondSpeciesCapacity;
     if(secondSpeciesRatio == 1)
         secondSpeciesCapacity = firstSpeciesCapacity;
     else if(secondSpeciesRatio>1)
     {
         secondSpeciesCapacity = secondSpeciesRatio* firstSpeciesCapacity;

     }
     else
         secondSpeciesCapacity = firstSpeciesCapacity *
                 secondSpeciesRatio/(1-secondSpeciesRatio);

     //and if it's inside the box
     if(isInsideTheBox(seaTile))
     {
         if(!species0InsideTheBox)
             firstSpeciesCapacity = 0;
     }
     else
     {
         secondSpeciesCapacity = 0;
     }


     BiomassLocalBiology toReturn =  new BiomassLocalBiology(
             new Double[]{random.nextDouble() * firstSpeciesCapacity,random.nextDouble() * secondSpeciesCapacity},
             new Double[]{firstSpeciesCapacity,secondSpeciesCapacity});
     biologies.put(seaTile,toReturn);
     return toReturn;
 }
 
开发者ID:CarrKnight,项目名称:POSEIDON,代码行数:54,代码来源:TwoSpeciesBoxInitializer.java


注:本文中的ec.util.MersenneTwisterFast.nextDouble方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。