Example usage for org.apache.commons.math.distribution PascalDistributionImpl PascalDistributionImpl

List of usage examples for org.apache.commons.math.distribution PascalDistributionImpl PascalDistributionImpl

Introduction

In this page you can find the example usage for org.apache.commons.math.distribution PascalDistributionImpl PascalDistributionImpl.

Prototype

public PascalDistributionImpl(int r, double p) 

Source Link

Document

Create a Pascal distribution with the given number of trials and probability of success.

Usage

From source file:geogebra.kernel.statistics.AlgoDistribution.java

PascalDistribution getPascalDistribution(int param, double param2) {
    if (pascal == null)
        pascal = new PascalDistributionImpl(param, param2);
    else {//  w w w. j av  a 2s.c  om
        pascal.setNumberOfSuccesses(param);
        pascal.setProbabilityOfSuccess(param2);
    }
    return pascal;
}

From source file:geogebra.common.kernel.statistics.AlgoDistribution.java

/**
 * @param param/*from   w  w  w .jav  a2  s. co  m*/
 *            number of successes
 * @param param2
 *            prob. of success
 * @return Pascal distribution
 */
protected PascalDistribution getPascalDistribution(int param, double param2) {
    if (pascal == null || pascal.getNumberOfSuccesses() != param || pascal.getProbabilityOfSuccess() != param2)
        pascal = new PascalDistributionImpl(param, param2);

    return pascal;
}

From source file:geogebra.common.kernel.algos.AlgoBarChart.java

/**
 * Prepares list1 and list2 for use with probability distribution bar charts
 *//*from  w ww  .  j  a v  a2 s .co m*/
private boolean prepareDistributionLists() {
    IntegerDistribution dist = null;
    int first = 0, last = 0;
    try {
        // get the distribution and the first, last list values for given
        // distribution type
        switch (type) {
        case TYPE_BARCHART_BINOMIAL:
            if (!(p1geo.isDefined() && p2geo.isDefined()))
                return false;
            int n = (int) Math.round(p1.getDouble());
            double p = p2.getDouble();
            dist = new BinomialDistributionImpl(n, p);
            first = 0;
            last = n;
            break;

        case TYPE_BARCHART_PASCAL:
            if (!(p1geo.isDefined() && p2geo.isDefined()))
                return false;
            n = (int) Math.round(p1.getDouble());
            p = p2.getDouble();
            dist = new PascalDistributionImpl(n, p);

            first = 0;
            last = (int) Math.max(1, (kernel).getXmax() + 1);
            break;
        case TYPE_BARCHART_ZIPF:
            if (!(p1geo.isDefined() && p2geo.isDefined()))
                return false;
            n = (int) Math.round(p1.getDouble());
            p = p2.getDouble();
            dist = new ZipfDistributionImpl(n, p);

            first = 0;
            last = n;
            break;
        case TYPE_BARCHART_POISSON:
            if (!p1geo.isDefined())
                return false;
            double lambda = p1.getDouble();
            dist = new PoissonDistributionImpl(lambda);
            first = 0;
            last = (int) Math.max(1, kernel.getXmax() + 1);
            break;

        case TYPE_BARCHART_HYPERGEOMETRIC:
            if (!(p1geo.isDefined() && p2geo.isDefined() && p3geo.isDefined()))
                return false;
            int pop = (int) p1.getDouble();
            int successes = (int) p2.getDouble();
            int sample = (int) p3.getDouble();
            dist = new HypergeometricDistributionImpl(pop, successes, sample);
            first = Math.max(0, successes + sample - pop);
            last = Math.min(successes, sample);
            break;
        }

        // load class list and probability list
        loadDistributionLists(first, last, dist);
    }

    catch (Exception e) {
        App.debug(e.getMessage());
        return false;
    }

    return true;
}

From source file:geogebra.kernel.AlgoFunctionAreaSums.java

/**
 * Prepares list1 and list2 for use with probability distribution bar charts
 *///  w  w  w.  j  a v a  2  s  .c om
private boolean prepareDistributionLists() {
    IntegerDistribution dist = null;
    int first = 0, last = 0;
    try {
        // get the distribution and the first, last list values for given distribution type
        switch (type) {
        case TYPE_BARCHART_BINOMIAL:
            if (!(p1geo.isDefined() && p2geo.isDefined()))
                return false;
            int n = (int) Math.round(p1.getDouble());
            double p = p2.getDouble();
            dist = new BinomialDistributionImpl(n, p);
            first = 0;
            last = n;
            break;

        case TYPE_BARCHART_PASCAL:
            if (!(p1geo.isDefined() && p2geo.isDefined()))
                return false;
            n = (int) Math.round(p1.getDouble());
            p = p2.getDouble();
            dist = new PascalDistributionImpl(n, p);

            first = 0;
            last = (int) Math.max(1, kernel.getXmax() + 1);
            break;
        case TYPE_BARCHART_ZIPF:
            if (!(p1geo.isDefined() && p2geo.isDefined()))
                return false;
            n = (int) Math.round(p1.getDouble());
            p = p2.getDouble();
            dist = new ZipfDistributionImpl(n, p);

            first = 0;
            last = n;
            break;
        case TYPE_BARCHART_POISSON:
            if (!p1geo.isDefined())
                return false;
            double lambda = p1.getDouble();
            dist = new PoissonDistributionImpl(lambda);
            first = 0;
            last = (int) Math.max(1, kernel.getXmax() + 1);
            break;

        case TYPE_BARCHART_HYPERGEOMETRIC:
            if (!(p1geo.isDefined() && p2geo.isDefined() && p3geo.isDefined()))
                return false;
            int pop = (int) p1.getDouble();
            int successes = (int) p2.getDouble();
            int sample = (int) p3.getDouble();
            dist = new HypergeometricDistributionImpl(pop, successes, sample);
            first = Math.max(0, successes + sample - pop);
            last = Math.min(successes, sample);
            break;
        }

        // load class list and probability list
        loadDistributionLists(first, last, dist);
    }

    catch (Exception e) {
        Application.debug(e.getMessage());
        return false;
    }

    return true;
}

From source file:geogebra.common.kernel.algos.AlgoFunctionAreaSums.java

/**
 * Prepares list1 and list2 for use with probability distribution bar charts
 *///from  w ww .ja va  2s. c  o  m
private boolean prepareDistributionLists() {
    IntegerDistribution dist = null;
    int first = 0, last = 0;
    try {
        // get the distribution and the first, last list values for given
        // distribution type
        switch (type) {
        case BARCHART_BINOMIAL:
            if (!(p1geo.isDefined() && p2geo.isDefined()))
                return false;
            int n = (int) Math.round(p1.getDouble());
            double p = p2.getDouble();
            dist = new BinomialDistributionImpl(n, p);
            first = 0;
            last = n;
            break;

        case BARCHART_PASCAL:
            if (!(p1geo.isDefined() && p2geo.isDefined()))
                return false;
            n = (int) Math.round(p1.getDouble());
            p = p2.getDouble();
            dist = new PascalDistributionImpl(n, p);

            first = 0;
            last = (int) Math.max(1, (kernel).getXmax() + 1);
            break;
        case BARCHART_ZIPF:
            if (!(p1geo.isDefined() && p2geo.isDefined()))
                return false;
            n = (int) Math.round(p1.getDouble());
            p = p2.getDouble();
            dist = new ZipfDistributionImpl(n, p);

            first = 0;
            last = n;
            break;
        case BARCHART_POISSON:
            if (!p1geo.isDefined())
                return false;
            double lambda = p1.getDouble();
            dist = new PoissonDistributionImpl(lambda);
            first = 0;
            last = (int) Math.max(1, kernel.getXmax() + 1);
            break;

        case BARCHART_HYPERGEOMETRIC:
            if (!(p1geo.isDefined() && p2geo.isDefined() && p3geo.isDefined()))
                return false;
            int pop = (int) p1.getDouble();
            int successes = (int) p2.getDouble();
            int sample = (int) p3.getDouble();
            dist = new HypergeometricDistributionImpl(pop, successes, sample);
            first = Math.max(0, successes + sample - pop);
            last = Math.min(successes, sample);
            break;
        }

        // load class list and probability list
        loadDistributionLists(first, last, dist);
    }

    catch (Exception e) {
        App.debug(e.getMessage());
        return false;
    }

    return true;
}

From source file:org.renjin.Distributions.java

public static double dnbinom(final double x, final int size, final double prob, boolean log) {
    return d(new PascalDistributionImpl(size, prob), x, log);
}

From source file:org.renjin.Distributions.java

public static double pnbinom(final double x, final int size, final double prob, boolean lowerTail,
        boolean logP) {
    return p(new PascalDistributionImpl(size, prob), x, lowerTail, logP);
}

From source file:org.renjin.primitives.random.Distributions.java

public static double dnbinom(@Recycle double x, @Recycle int size, @Recycle double prob, boolean log) {
    return d(new PascalDistributionImpl(size, prob), x, log);
}

From source file:org.renjin.primitives.random.Distributions.java

public static double pnbinom(@Recycle double x, @Recycle int size, @Recycle double prob, boolean lowerTail,
        boolean logP) {
    return p(new PascalDistributionImpl(size, prob), x, lowerTail, logP);
}

From source file:org.renjin.stats.internals.Distributions.java

@DataParallel
@Internal//from w  w  w. j a va 2  s. c  o m
public static double dnbinom(@Recycle double x, @Recycle int size, @Recycle double prob, boolean log) {
    return d(new PascalDistributionImpl(size, prob), x, log);
}