TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Geometric Distribution More...
#include <cassert>
#include <cmath>
#include <cstdint>
#include <ctime>
#include <iostream>
#include <limits>
#include <random>
#include <vector>
Go to the source code of this file.
Classes | |
class | probability::geometric_dist::geometric_distribution |
A class to model the geometric distribution. More... | |
Namespaces | |
namespace | probability |
Probability algorithms. | |
namespace | geometric_dist |
Functions for the Geometric Distribution algorithm implementation. | |
Functions | |
float | probability::geometric_dist::generate_uniform () |
Returns a random number between [0,1]. | |
void | sample_test (const probability::geometric_dist::geometric_distribution &dist) |
Tests the sampling method of the geometric distribution. | |
static void | test () |
Self-test implementations. | |
int | main () |
Main function. | |
The geometric distribution models the experiment of doing Bernoulli trials until a sucess was observed. There are two formulations of the geometric distribution: 1) The probability distribution of the number X of Bernoulli trials needed to get one success, supported on the set { 1, 2, 3, ... } 2) The probability distribution of the number Y = X − 1 of failures before the first success, supported on the set { 0, 1, 2, 3, ... } Here, the first one is implemented.
Common variables used: p - The success probability k - The number of tries
Definition in file geometric_dist.cpp.
float probability::geometric_dist::generate_uniform | ( | ) |
Returns a random number between [0,1].
Definition at line 48 of file geometric_dist.cpp.
int main | ( | void | ) |
Main function.
Definition at line 256 of file geometric_dist.cpp.
void sample_test | ( | const probability::geometric_dist::geometric_distribution & | dist | ) |
Tests the sampling method of the geometric distribution.
Draws 1000000 random samples and estimates mean and variance These should be close to the expected value and variance of the given distribution to pass.
dist | The distribution to test |
Definition at line 165 of file geometric_dist.cpp.
|
static |
Self-test implementations.
Definition at line 197 of file geometric_dist.cpp.