Skip to content

Instantly share code, notes, and snippets.

@thoolihan
Created November 23, 2016 03:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoolihan/641a38d5a8a512bf25f722920756218c to your computer and use it in GitHub Desktop.
Save thoolihan/641a38d5a8a512bf25f722920756218c to your computer and use it in GitHub Desktop.
Poisson Probability Mass Function in C++
#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