1 [section:bernoulli_dist Bernoulli Distribution]
3 ``#include <boost/math/distributions/bernoulli.hpp>``
5 namespace boost{ namespace math{
6 template <class RealType = double,
7 class ``__Policy`` = ``__policy_class`` >
8 class bernoulli_distribution;
10 typedef bernoulli_distribution<> bernoulli;
12 template <class RealType, class ``__Policy``>
13 class bernoulli_distribution
16 typedef RealType value_type;
17 typedef Policy policy_type;
19 bernoulli_distribution(RealType p); // Constructor.
21 RealType success_fraction() const
22 // Probability of success (as a fraction).
26 The Bernoulli distribution is a discrete distribution of the outcome
27 of a single trial with only two results, 0 (failure) or 1 (success),
28 with a probability of success p.
30 The Bernoulli distribution is the simplest building block
31 on which other discrete distributions of
32 sequences of independent Bernoulli trials can be based.
34 The Bernoulli is the binomial distribution (k = 1, p) with only one trial.
36 [@http://en.wikipedia.org/wiki/Probability_density_function probability density function pdf]
37 f(0) = 1 - p, f(1) = p.
38 [@http://en.wikipedia.org/wiki/Cumulative_Distribution_Function Cumulative distribution function]
39 D(k) = if (k == 0) 1 - p else 1.
41 The following graph illustrates how the
42 [@http://en.wikipedia.org/wiki/Probability_density_function probability density function pdf]
43 varies with the outcome of the single trial:
47 and the [@http://en.wikipedia.org/wiki/Cumulative_Distribution_Function Cumulative distribution function]
53 bernoulli_distribution(RealType p);
55 Constructs a [@http://en.wikipedia.org/wiki/bernoulli_distribution
56 bernoulli distribution] with success_fraction /p/.
58 RealType success_fraction() const
60 Returns the /success_fraction/ parameter of this distribution.
62 [h4 Non-member Accessors]
64 All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
65 that are generic to all distributions are supported: __usual_accessors.
67 The domain of the random variable is 0 and 1,
68 and the useful supported range is only 0 or 1.
70 Outside this range, functions are undefined, or may throw domain_error exception
71 and make an error message available.
75 The Bernoulli distribution is implemented with simple arithmetic operators
76 and so should have errors within an epsilon or two.
80 In the following table /p/ is the probability of success and /q = 1-p/.
81 /k/ is the random variate, either 0 or 1.
83 [note The Bernoulli distribution is implemented here as a /strict discrete/ distribution.
84 If a generalised version, allowing k to be any real, is required then
85 the binomial distribution with a single trial should be used, for example:
87 `binomial_distribution(1, 0.25)`
91 [[Function][Implementation Notes]]
92 [[Supported range][{0, 1}]]
93 [[pdf][Using the relation: pdf = 1 - p for k = 0, else p ]]
94 [[cdf][Using the relation: cdf = 1 - p for k = 0, else 1]]
95 [[cdf complement][q = 1 - p]]
96 [[quantile][if x <= (1-p) 0 else 1]]
97 [[quantile from the complement][if x <= (1-p) 1 else 0]]
99 [[variance][p * (1 - p)]]
100 [[mode][if (p < 0.5) 0 else 1]]
101 [[skewness][(1 - 2 * p) / sqrt(p * q)]]
102 [[kurtosis][6 * p * p - 6 * p +1/ p * q]]
103 [[kurtosis excess][kurtosis -3]]
107 * [@http://en.wikipedia.org/wiki/Bernoulli_distribution Wikpedia Bernoulli distribution]
108 * [@http://mathworld.wolfram.com/BernoulliDistribution.html Weisstein, Eric W. "Bernoulli Distribution." From MathWorld--A Wolfram Web Resource.]
110 [endsect] [/section:bernoulli_dist bernoulli]
113 Copyright 2006 John Maddock and Paul A. Bristow.
114 Distributed under the Boost Software License, Version 1.0.
115 (See accompanying file LICENSE_1_0.txt or copy at
116 http://www.boost.org/LICENSE_1_0.txt).