Binomial
Represents the number of successes in a fixed number of independent and identically distributed Bernoulli trials (each trial having two possible outcomes: success or failure)
Create a new Binomial distribution
Binomial X = Binomial(n, p); creates a discrete Binomial probability distribution.
Distribution properties:
n
int
Number of executed events
p
double -> [0, 1]
Probability of a succesful event
E()
double
Returns the expected value of succesful events after executing n independend events, all with constant probability of p.
D()
double
Represents variance, that measures the spread of dispersion of the random variable around its expected value E(X).
P(int k)
double
Probability of obtaining exactly 𝑘 successes in 𝑛 trials: P(X = k)
P_LT(int k)
double
Probability of obtaining less than 𝑘 successes in 𝑛 trials: P(X < k)
P_LTE(int k)
double
Probability of obtaining less than or exactly 𝑘 successes in 𝑛 trials: P(X ≤ k)
P_HT(int k)
double
Probability of obtaining more than 𝑘 successes in 𝑛 trials: P(X > k) = P(X ≤ k)
P_HTE(int k)
double
Probability of obtaining more than or exactly 𝑘 successes in 𝑛 trials: P(X ≥ k) = P(X < k)
Example
//Example: what's the probability of getting exactly 5 heads
//when flipping a coin 10 times?
double p = 0.5; //probability of getting heads is 50%
int n = 10; //10 independed events
Binomial X = Binomial(n, p);
std::cout << X.P(5) << std::endl; //0.246094Binomial X = Binomial(25, -0.5); //Error: Probability cannot be less than 0 or more than 1.
std::cout << X.P(30) << std::endl; //Error: The number of succesful trials cannot exceed the number of all trials or be less than 0. Last updated