All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lphy.base.math.MathUtils Maven / Gradle / Ivy

Go to download

The standard library of LPhy, which contains the required generative distributions and basic functions.

The newest version!
package lphy.base.math;

import org.apache.commons.math3.distribution.GammaDistribution;
import org.apache.commons.math3.random.RandomGenerator;

public class MathUtils {

    /**
     *
     * @param lambda the rate of the exponential distribution
     * @param random a random generator
     * @return a random variate from an exponential distribution with the given rate.
     */
    public static double nextExponential(double lambda, RandomGenerator random) {
        return Math.log(1-random.nextDouble())/(-lambda);
    }


    public static double randomGamma(double shape, double scale, RandomGenerator random) {
        return new GammaDistribution(random, shape, scale,
                GammaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy