poisson_dist.cpp File Reference

Poisson statistics More...

`#include <cmath>`
`#include <iostream>`
Include dependency graph for poisson_dist.cpp:

## Functions

double | poisson_rate (double events, double timeframe)
double | poisson_expected (double rate, double time)
double | fact (double x)
double | poisson_x_successes (double expected, double x)
double | poisson_range_successes (double expected, double lower, double upper)
int | main ()

## Detailed Description

Poisson statistics

The Poisson distribution counts how many events occur over a set time interval.

## Function Documentation

## fact()

double fact | ( | double | x | ) |

Compute factorial of a given number

{
double x_fact = x;
for (int i = x - 1; i > 0; i--) {
x_fact *= i;
}
if (x_fact <= 0) {
x_fact = 1;
}
return x_fact;
}

## main()

int main | ( | void |  | ) |

main function

{
double rate, expected;
rate = poisson_rate(3, 1);
std::cout << "Poisson rate : " << rate << std::endl;
expected = poisson_expected(rate, 2);
std::cout << "Poisson expected : " << expected << std::endl;
std::cout << "Poisson 0 successes : " << poisson_x_successes(expected, 0)
<< std::endl;
std::cout << "Poisson 0-8 successes : "
<< poisson_range_successes(expected, 0, 8) << std::endl;
return 0;
}
std::cout
std::endl
T endl(T... args)
poisson_x_successes
double poisson_x_successes(double expected, double x)
Definition: poisson_dist.cpp:46
poisson_rate
double poisson_rate(double events, double timeframe)
Definition: poisson_dist.cpp:17
poisson_expected
double poisson_expected(double rate, double time)
Definition: poisson_dist.cpp:25
poisson_range_successes
double poisson_range_successes(double expected, double lower, double upper)
Definition: poisson_dist.cpp:54
Here is the call graph for this function:

## poisson_expected()

double poisson_expected | ( | double | rate,
|  | double | time
| ) |  |

calculate the expected value over a time e.g rate of 2.5 over 10 mins = 2.5 x 10 = 25

{ return rate * time; }
std::time
T time(T... args)

## poisson_range_successes()

double poisson_range_successes | ( | double | expected,
|  | double | lower,
|  | double | upper
| ) |  |

probability of a success in range for Poisson dist (inclusive, inclusive)

\[P = \sum_i p(\mu,i)\]

{
double probability = 0;
for (int i = lower; i <= upper; i++) {
probability += poisson_x_successes(expected, i);
}
return probability;
}
Here is the call graph for this function:

## poisson_rate()

double poisson_rate | ( | double | events,
|  | double | timeframe
| ) |  |

poisson rate:
calculate the events per unit time
e.g 5 dollars every 2 mins = 5 / 2 = 2.5

{
return events / timeframe;
}

## poisson_x_successes()

double poisson_x_successes | ( | double | expected,
|  | double | x
| ) |  |

Find the probability of x successes in a Poisson dist.

\[p(\mu,x) = \frac{\mu^x e^{-\mu}}{x!}\]

{
return (std::pow(expected, x) * std::exp(-expected)) / fact(x);
}
std::exp
T exp(T... args)
fact
double fact(double x)
Definition: poisson_dist.cpp:30
std::pow
T pow(T... args)
Here is the call graph for this function: