Hi Ole:
Thank you very much. This is exactly what I was looking for.
Thanks,
David
-----Original Message-----
From: Ole Ersoy [mailto:ole.ersoy@gmail.com]
Sent: Monday, August 31, 2015 12:42 PM
To: Commons Users List
Subject: Re: [math] Poisson distribution to show how many ambulances are dispatched per hour
Hi David,
public static void main(String[] args)
{
int numberOfAmbulances = 20;
PoissonDistribution ambulanceDistribution = new PoissonDistribution(9);
for (int dispatched = 0; dispatched <= numberOfAmbulances; dispatched++) {
System.out.println("Likelihood of " + dispatched + " ambulances dispatched is " + ambulanceDistribution.probability(dispatched) + "\n");
}
}
Cheers,
- Ole
On 08/31/2015 11:21 AM, Kulpanowski, David wrote:
> 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
> // derived from your database.
> 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;
> System.out.format("%10.3f:%n ", answer);
> 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.
>
> Under Florida law, email addresses are public records. If you do not want your email address 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.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org