Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. init:
  2. Let L ← e^(−λ), k ← 0 and p ← 1.
  3. do:
  4. k ← k + 1.
  5. Generate uniform random number u in [0,1] and let p ← p × u.
  6. while p > L.
  7. return k − 1.
  8.  
  9. public static int getPoisson(double lambda) {
  10. double L = Math.exp(-lambda);
  11. double p = 1.0;
  12. int k = 0;
  13.  
  14. do {
  15. k++;
  16. p *= Math.random();
  17. } while (p > L);
  18.  
  19. return k - 1;
  20. }
  21.  
  22. public static int getBinomial(int n, double p) {
  23. int x = 0;
  24. for(int i = 0; i < n; i++) {
  25. if(Math.random() < p)
  26. x++;
  27. }
  28. return x;
  29. }
  30.  
  31. implementation 'org.kie.modules:org-apache-commons-math:6.5.0.Final'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement