Class DistBinomial

All Implemented Interfaces:
Serializable

public class DistBinomial extends DistDiscrete
The Binomial distribution. The binomial distribution is the probability of the number of successes in a sequence of n independent experiments, each with success (probability p) or failure (probability q = 1 − p). For more information on this distribution see https://mathworld.wolfram.com/BinomialDistribution.html

Copyright (c) 2002-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.

Author:
Peter Jacobs , Alexander Verbraeck
See Also:
  • Field Summary

    Fields inherited from class nl.tudelft.simulation.jstats.distributions.Dist

    stream
  • Constructor Summary

    Constructors
    Constructor
    Description
    DistBinomial(StreamInterface stream, int n, double p)
    constructs a Binomial distribution.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    draws the next long from the stream.
    int
    Return the number of independent experiments for the Binomial distribution.
    double
    Return the probability of success for each individual trial in the binomial distribution.
    double
    probability(long observation)
    returns the probability of the observation in this particular distribution.

    Methods inherited from class nl.tudelft.simulation.jstats.distributions.Dist

    getStream, setStream

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • DistBinomial

      public DistBinomial(StreamInterface stream, int n, double p)
      constructs a Binomial distribution. It calculates the probability for a number of successes in n independent Bernoulli trials with probability p of success on each trial.
      Parameters:
      stream - StreamInterface; the random number stream
      n - long; the number of independent experiments for the Binomial distribution
      p - double; the probability of success for each individual trial in the binomial distribution
      Throws:
      IllegalArgumentException - when n <= 0 or p <= 0 or p >= 1
  • Method Details

    • draw

      public long draw()
      draws the next long from the stream.
      Specified by:
      draw in class DistDiscrete
      Returns:
      long
    • probability

      public double probability(long observation)
      returns the probability of the observation in this particular distribution.
      Specified by:
      probability in class DistDiscrete
      Parameters:
      observation - long; the discrete observation.
      Returns:
      double the probability.
    • getN

      public int getN()
      Return the number of independent experiments for the Binomial distribution.
      Returns:
      int; the number of independent experiments for the Binomial distribution
    • getP

      public double getP()
      Return the probability of success for each individual trial in the binomial distribution.
      Returns:
      double; the probability of success for each individual trial in the binomial distribution
    • toString

      public String toString()
      Overrides:
      toString in class Object