Created
November 23, 2016 03:31
-
-
Save thoolihan/641a38d5a8a512bf25f722920756218c to your computer and use it in GitHub Desktop.
Poisson Probability Mass Function in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include "math.h" | |
using namespace std; | |
float pmf(int k, double lambda) { | |
// https://en.wikipedia.org/wiki/Poisson_distribution#Definition | |
return pow(M_E, k * log(lambda) - lambda - lgamma(k + 1.0)); | |
} | |
int main(int argc, const char * argv[]) { | |
// insert code here... | |
cout << "Given a 50% female ratio, probability of 6 out of 6 girls at bus stop is " | |
<< setprecision(3) | |
<< pmf(6.0, 3.0) * 100.0 | |
<< "%" << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment