Example usage for org.apache.commons.math3.distribution GammaDistribution GammaDistribution

List of usage examples for org.apache.commons.math3.distribution GammaDistribution GammaDistribution

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution GammaDistribution GammaDistribution.

Prototype

public GammaDistribution(double shape, double scale) throws NotStrictlyPositiveException 

Source Link

Document

Creates a new gamma distribution with specified values of the shape and scale parameters.

Usage

From source file:com.trickl.stats.GammaDistributionOutlier.java

@Override
public IntPredicate apply(int[] edgeFlows) {
    // Calculate the distribution of flow across edges
    SummaryStatistics flowSummaryStatistics = new SummaryStatistics();
    for (int flow : edgeFlows) {
        flowSummaryStatistics.addValue(flow);
    }//from   w ww.  j a  va  2 s .co m
    double flowVar = flowSummaryStatistics.getVariance();
    double flowMean = flowSummaryStatistics.getMean();
    double gammaShape = (flowMean * flowMean) / flowVar;
    double gammaScale = flowVar / flowMean;
    GammaDistribution gammaDistribution = new GammaDistribution(gammaShape, gammaScale);
    return new ValueAboveHasProbabilityBelow(gammaDistribution, probability);
}

From source file:info.rmarcus.birkhoffvonneumann.samplers.DirichletBistochasticSampler.java

DirichletBistochasticSampler() {
    gamma = new GammaDistribution(1.0, 1.0);
}

From source file:jasima.core.random.continuous.DblGamma.java

public DblGamma(double shape, double scale) {
    super();
    setDistribution(new GammaDistribution(shape, scale));
}

From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.trafficgen.IATGen.java

/**
 * Constructor/*from ww  w  . j av  a 2  s.co m*/
 *
 * @param distribution Distribution as String
 * @param para1 Parameter 1
 * @param para2 Parameter 2 (only needed when applicable)
 */
public IATGen(String distribution, double para1, double para2) {

    logger.trace("Distribution selected: {} with Parameters {} & {}", distribution, para1, para2);

    switch (distribution) {
    case "ChiSquared":
        this.distri = new ChiSquaredDistribution(para1);
        break;
    case "Exponential":
        this.distri = new ExponentialDistribution(para1);
        break;
    case "Gamma":
        this.distri = new GammaDistribution(para1, para2);
        break;
    case "Poisson":
        this.intDistri = new PoissonDistribution(para1, para2);
        break;
    default:
        this.distri = new NormalDistribution(para1, para2);
        break;
    }
}

From source file:distributions.Gamma.java

public void process(int pickedinstances, int totalinstances, int deletedattribute) {
    System.out.println("Process");
    double value;
    double gamma_func_r;
    computeMean();/*w w  w.  j a  v  a2s.  c o  m*/
    computevariance();
    //computeparameters();
    gamma_func_r = factorial((int) (alfa - 1));
    ///compute gamma distribution
    GammaDistribution gd = new GammaDistribution(alfa, beta);
    for (int row = 0; row < data.length; row++) {
        //value = getGammaDistribution(gamma_func_r, normalizedData[row], alfa, beta);
        value = gd.density(normalizedData[row]);
        Prob[row] = value;
        System.out.println(Prob[row]);
    }
    //generateCSVFile();
    //find the pairs of the picked instances to delete
    findpairs(pickedinstances, totalinstances);
    //delete the attribue of the instances to create missign data set
    deletedata(deletedattribute);
    generateCSVFile();

    for (int i = 0; i < data.length; i++) {
        System.out.print("\n");
        for (int j = 0; j < data[0].length; j++) {
            System.out.print(data[i][j] + "\t");
        }
        // System.out.print("\n");
    }
}

From source file:jasima.core.random.continuous.DblGamma.java

/**
 * Sets the shape parameter for this distribution.
 * /*from w  w w  .ja va 2 s. co  m*/
 * @param shape
 *            The shape parameter to use.
 * @throws NotStrictlyPositiveException
 *             If the parameter value was {@code <=0.0}.
 */
public void setShape(double shape) throws NotStrictlyPositiveException {
    setDistribution(new GammaDistribution(shape, dist.getScale()));
}

From source file:com.mapr.synth.samplers.RandomWalkSamplerTest.java

@Test
public void testBasics() throws IOException {
    // this sampler has four variables
    // g1 is gamma distributed with alpha = 0.2, beta = 0.2
    // v1 is unit normal
    // v2 is normal with mean = 0, sd = 2
    // v3 is gamma-normal with dof=2, mean = 0.
    SchemaSampler s = new SchemaSampler(
            Resources.asCharSource(Resources.getResource("schema015.json"), Charsets.UTF_8).read());

    TDigest tdG1 = new AVLTreeDigest(500);
    TDigest tdG2 = new AVLTreeDigest(500);
    TDigest td1 = new AVLTreeDigest(500);
    TDigest td2 = new AVLTreeDigest(500);
    TDigest td3 = new AVLTreeDigest(500);

    double x1 = 0;
    double x2 = 0;
    double x3 = 0;

    for (int i = 0; i < 1000000; i++) {
        JsonNode r = s.sample();// ww  w  .ja va2 s .c  o  m
        tdG1.add(r.get("g1").asDouble());
        tdG2.add(r.get("g2").asDouble());

        double step1 = r.get("v1").get("step").asDouble();
        td1.add(step1);
        x1 += step1;
        assertEquals(x1, r.get("v1").get("value").asDouble(), 0);
        assertEquals(x1, r.get("v1-bare").asDouble(), 0);

        double step2 = r.get("v2").get("step").asDouble();
        td2.add(step2);
        x2 += step2;
        assertEquals(x2, r.get("v2").get("value").asDouble(), 0);

        double step3 = r.get("v3").get("step").asDouble();
        td3.add(step3);
        x3 += step3;
        assertEquals(x3, r.get("v3").get("value").asDouble(), 0);
    }

    // now compare against reference distributions to test accuracy of the observed step distributions
    NormalDistribution normalDistribution = new NormalDistribution();
    GammaDistribution gd1 = new GammaDistribution(0.2, 5);
    GammaDistribution gd2 = new GammaDistribution(1, 1);
    TDistribution tDistribution = new TDistribution(2);
    for (double q : new double[] { 0.001, 0.01, 0.1, 0.2, 0.5, 0.8, 0.9, 0.99, 0.99 }) {
        double uG1 = gd1.cumulativeProbability(tdG1.quantile(q));
        assertEquals(q, uG1, (1 - q) * q * 10e-2);

        double uG2 = gd2.cumulativeProbability(tdG2.quantile(q));
        assertEquals(q, uG2, (1 - q) * q * 10e-2);

        double u1 = normalDistribution.cumulativeProbability(td1.quantile(q));
        assertEquals(q, u1, (1 - q) * q * 10e-2);

        double u2 = normalDistribution.cumulativeProbability(td2.quantile(q) / 2);
        assertEquals(q, u2, (1 - q) * q * 10e-2);

        double u3 = tDistribution.cumulativeProbability(td3.quantile(q));
        assertEquals(q, u3, (1 - q) * q * 10e-2);
    }
}

From source file:jasima.core.random.continuous.DblGamma.java

/**
 * Sets the scale parameter for this distribution.
 * /*from  ww  w  .j  ava 2s  .  c o  m*/
 * @param scale
 *            The scale parameter to use.
 * @throws NotStrictlyPositiveException
 *             If the parameter value was {@code <=0.0}.
 */
public void setScale(double scale) throws NotStrictlyPositiveException {
    setDistribution(new GammaDistribution(dist.getShape(), scale));
}

From source file:es.csic.iiia.planes.util.InverseWishartDistribution.java

private void initialize() {
    final int dim = scaleMatrix.getColumnDimension();

    // Build gamma distributions for the diagonal
    gammas = new GammaDistribution[dim];
    for (int i = 0; i < dim; i++) {

        gammas[i] = new GammaDistribution(df - i - .99 / 2, 2);
    }//from  w w  w.  java 2s  .c om

    // Build the cholesky decomposition
    cholesky = new CholeskyDecomposition(scaleMatrix);
}

From source file:hivemall.topicmodel.OnlineLDAModel.java

public OnlineLDAModel(int K, float alpha, float eta, long D, double tau0, double kappa, double delta) {
    super(K);//from   w  w w  .j  a v a  2  s. c  o m

    if (tau0 < 0.d) {
        throw new IllegalArgumentException("tau0 MUST be positive: " + tau0);
    }
    if (kappa <= 0.5 || 1.d < kappa) {
        throw new IllegalArgumentException("kappa MUST be in (0.5, 1.0]: " + kappa);
    }

    this._alpha = alpha;
    this._eta = eta;
    this._D = D;
    this._tau0 = tau0;
    this._kappa = kappa;
    this._delta = delta;

    this._isAutoD = (_D < 0L);

    // initialize a random number generator
    this._gd = new GammaDistribution(SHAPE, SCALE);
    _gd.reseedRandomGenerator(1001);

    // initialize the parameters
    this._lambda = new HashMap<String, float[]>(100);
}