Skip to content

Instantly share code, notes, and snippets.

@tleonardi
Created December 7, 2016 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tleonardi/3e4d3b591f8329559790229f9f297f40 to your computer and use it in GitHub Desktop.
Save tleonardi/3e4d3b591f8329559790229f9f297f40 to your computer and use it in GitHub Desktop.
#!/bin/awk -f
function logfactorial(n, f, i){
f=0
for(i=1;i<=n;i++){
f+=log(i)
}
return f
}
# m: Mean
# x: Poisson random var
function poisson(m, x, i, e, TOT, lt, ut){
e=exp(1)
for(i=0;i<=x;i++){
TOT+=exp(-m + i*log(m) - logfactorial(i))
}
# Lower tail probability
lt=TOT
# Upper tail probability
ut=1-TOT
return ut
}
BEGIN{
print poisson(10, 20)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment