# commons-user mailing list archives

##### Site index · List index
Message view
Top
From "Kulpanowski, David" <DKulpanow...@leegov.com>
Subject [math] Poisson distribution to show how many ambulances are dispatched per hour
Date Mon, 31 Aug 2015 16:21:23 GMT
```Hi:
I am working on a relatively simple project. I am attempting to generate a Poisson distribution
for the number of ambulances that are dispatched. I have looked at my database and determined
the average number of ambulances dispatched is 9
How do I get a Poisson distribution to be generated using the Commons Math?

The output I am expecting to generate looks like this....

Likelihood of 1 ambulance dispatched is 0.005
Likelihood of 2 ambulances dispatched is 0.015
Likelihood of 3 ambulances dispatched is 0.034
Likelihood of 4 ambulances dispatched is 0.61
Likelihood of 5 ambulances dispatched is 0.091
Likelihood of 6 ambulances dispatched is 0.117
Etc.

This is probably a very simple programming question for many of you. But for me as a novice
it is not easy.

So far, here is what I have using Commons Math;

import org.apache.commons.math3.distribution.PoissonDistribution;

public class poissonDistribution
{
public static void main(String[] args)
{
PoissonDistribution ambulanceDistribution = new PoissonDistribution(9);
System.out.println(ambulanceDistribution);
}
}

The console output is; "org.apache.commons.math3.distribution.PoissonDistribution@27716f4"

I did try and take matters into my own hands and write the equation out (shown below). But
I have a very strong preference to use a method provided by Commons Math. I am much more confident
in Commons Math than my own abilities.

The following is my code. It works in a fashion, but I am not confident in it. Shown below
is what I am currently using - but prefer to avoid using this;
import java.lang.Math;
public class PoissonExperiment1
{
public static void main(String[] args)
{
// c is the average number of calls per hour. This is a variable that is
double c = 9.0;
// k is the number of expected calls we want to determine the probability
int k = 1;
while (k <= 20)
{
int factorialResult = 1;
for (int i = 1; i <= k; i++)
{
factorialResult = factorialResult * i;
}
double term1 = (Math.pow(Math.E, -c));
double term2 = Math.pow(c, k);
double numerator = term1 * term2;
double answer = numerator / factorialResult;
k++;
}
}
}

Thank you for your consideration and time,
David

David Kulpanowski
Database Analyst
Lee County Public Safety
PO Box 398
Fort Myers, FL 33902
DKulpanowski@Leegov.com
239-533-3962

________________________________
Please note: Florida has a very broad public records law. Most written communications to or
from County Employees and officials regarding County business are public records available
to the public and media upon request. Your email communication may be subject to public disclosure.

released in response to a public records request, do not send electronic mail to this entity.
Instead, contact this office by phone or in writing.

```
Mime
• Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message