Class DistBernoulli

All Implemented Interfaces:
Serializable

public class DistBernoulli extends DistDiscrete
The Bernoulli distribution, with p as the probability for success. For more information on this distribution see https://mathworld.wolfram.com/BernouilliDistribution.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
    DistBernoulli(StreamInterface stream, double p)
    constructs a new Bernoulli distribution, with p as the probability for success (X=1), where failure is associated with X=0.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    draws the next value from the Bernoulli distribution.
    double
    Return p, the probability for success (X=1), where failure is associated with X=0.
    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

    • DistBernoulli

      public DistBernoulli(StreamInterface stream, double p)
      constructs a new Bernoulli distribution, with p as the probability for success (X=1), where failure is associated with X=0.
      Parameters:
      stream - StreamInterface; is the stream
      p - double; the probability for success of the Bernoulli distribution
      Throws:
      IllegalArgumentException - when p < 0 or p > 1
  • Method Details

    • draw

      public long draw()
      draws the next value from the Bernoulli distribution. More information on this distribution can be found at
      https://mathworld.wolfram.com/ BernoulliDistribution.html.
      Specified by:
      draw in class DistDiscrete
      Returns:
      the next value {0,1}, where 1 denotes success (probability p), and 0 denotes failure (probability (1-p).
    • 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.
    • getP

      public double getP()
      Return p, the probability for success (X=1), where failure is associated with X=0.
      Returns:
      double; p, the probability for success (X=1)
    • toString

      public String toString()
      Overrides:
      toString in class Object