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

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

Introduction

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

Prototype

public HypergeometricDistributionImpl(int populationSize, int numberOfSuccesses, int sampleSize) 

Source Link

Document

Construct a new hypergeometric distribution with the given the population size, the number of successes in the population, and the sample size.

Usage

From source file:desmoj.core.dist.DiscreteDistHypergeo.java

/**
 * Creates a stream of pseudo random numbers following a Hypergeometrical
 * distribution. The specific parameters N (set size), n (marked amount) and
 * k (subset size) have to be given here at creation time.
 * //from ww w . j  a v a 2 s  .  c  om
 * @param owner
 *            Model : The distribution's owner
 * @param name
 *            java.lang.String : The distribution's name
 * @param setSize
 *            int : The size of the underlying set.
 * @param markedAmount
 *            int : The amount of marked objects within the underlying set.
 * @param subsetSize
 *            int : The size of the random subset of the underlying set.
 * @param showInReport
 *            boolean : Flag for producing reports
 * @param showInTrace
 *            boolean : Flag for producing trace output
 */
public DiscreteDistHypergeo(Model owner, String name, int setSize, int markedAmount, int subsetSize,
        boolean showInReport, boolean showInTrace) {
    super(owner, name, showInReport, showInTrace);
    this.setSize = setSize;
    this.markedAmount = markedAmount;
    this.subsetSize = subsetSize;
    valueList = new ArrayList<Entry>();
    Entry e;

    HypergeometricDistribution hgdist = new HypergeometricDistributionImpl(setSize, markedAmount, subsetSize);
    for (int i = 0; i <= this.subsetSize; i++) {
        try {
            e = new Entry(i, hgdist.cumulativeProbability(i));
            valueList.add(e);

        } catch (MathException e1) {
            sendWarning(
                    "Failed to compute cumulative Probability of value " + Integer.toString(i)
                            + ", entry ignored",
                    "CustomContDist : " + getName() + " at construction time",
                    "Impossible to compute cumulative Probability",
                    "Make sure the subset size as well as the amount of successes are smaller than the main set size");
        }
    }

}

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

HypergeometricDistribution getHypergeometricDistribution(int param, int param2, int param3) {
    if (hypergeometric == null)
        hypergeometric = new HypergeometricDistributionImpl(param, param2, param3);
    else {/*from w ww  .jav a 2 s.  c o  m*/
        hypergeometric.setPopulationSize(param);
        hypergeometric.setNumberOfSuccesses(param2);
        hypergeometric.setSampleSize(param3);
    }
    return hypergeometric;
}

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

/**
 * @param param//from  www  .  ja v  a 2 s.com
 *            population size
 * @param param2
 *            number of successes
 * @param param3
 *            sample size
 * @return hypergeometric distribution
 */
protected HypergeometricDistribution getHypergeometricDistribution(int param, int param2, int param3) {
    if (hypergeometric == null || hypergeometric.getNumberOfSuccesses() != param2
            || hypergeometric.getPopulationSize() != param || hypergeometric.getSampleSize() != param3)
        hypergeometric = new HypergeometricDistributionImpl(param, param2, param3);

    return hypergeometric;
}

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

/**
 * Prepares list1 and list2 for use with probability distribution bar charts
 *//*from  w  w w .j a  va 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) {
        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
 *//* ww  w  . ja  va 2  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) {
        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 .j av a 2  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 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 dhyper(final double x, final double whiteBalls, final double blackBalls,
        final double sampleSize, boolean log) {
    return d(new HypergeometricDistributionImpl((int) (whiteBalls + blackBalls), (int) whiteBalls,
            (int) sampleSize), x, log);
}

From source file:org.renjin.Distributions.java

public static double phyper(final double q, final double x, final double whiteBalls, final double blackBalls,
        final double sampleSize, boolean lowerTail, boolean logP) {
    return p(new HypergeometricDistributionImpl((int) (whiteBalls + blackBalls), (int) whiteBalls,
            (int) sampleSize), q, lowerTail, logP);
}

From source file:org.renjin.Distributions.java

public static double qhyper(double p, double m, double n, double k, boolean lowerTail, boolean logP) {
    return q(new HypergeometricDistributionImpl((int) m, (int) n, (int) k), p, lowerTail, logP);
}

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

public static double dhyper(@Recycle double x, @Recycle double whiteBalls, @Recycle double blackBalls,
        @Recycle double sampleSize, boolean log) {
    return d(new HypergeometricDistributionImpl((int) (whiteBalls + blackBalls), (int) whiteBalls,
            (int) sampleSize), x, log);
}