Edit: It looks like the Apache Commons Math library has a statistics section. Specifically, a whole package on common Distributions. Hopefully theres some math people out there because I can't remember basic statistics... here's my attempt at using the their library. I just have a sliding window here and calculate the P between those values. Whats the real way to get a PDF from this? They only have a CDF function.
public void testNormalDist() throws MathException {
DistributionFactory f = DistributionFactory.newInstance();
NormalDistribution n = f.createNormalDistribution(0.0d, 1.0d);
double lastx = Double.NEGATIVE_INFINITY;
double nextx = Double.NEGATIVE_INFINITY;
for (int i=-100; i < 100; i++) {
nextx = i / 100d;
System.out.println(n.cumulativeProbability(lastx, nextx));
lastx = nextx;
}
}
I assume you want the probability density function for the graph. The equations are on wikipedia, since I don't know how to include math markup here. Just use p(x) as your Y value and X as your X value and you can get a pretty easy 2-d graph from that.
Have you looked at Mathtools under Java?
Ok, how about this... you give it an array of X points (normalized, of course, you can convert your X pixels to these by dividing each pixel position by the width of your image), and it will return the heights of the distribution curve (again, multiply by your normalization factor). This is for the basic case where mean is 0 and standard deviation is 1.
public double[] normalDistBasic(double[] xarray, double mu) {
double[] yarray = new double[xarray.length];
double rad2pi = 2.50662827d;
for (int off = 0; off < yarray.length; off++) {
double x = xarray[off];
double ss = -1d * x * x / 2d;
yarray[off] = (-1f / rad2pi) * Math.exp(ss);
}
return yarray;
}
It should be pretty easy to implement one that takes arbitrary mean and standard deviation if one can't be found on the net.