Edit: It looks like the Apache Commons Math library has a statistics section. In particular, a whole package on General Distributions . Hope some mathematical people are there because I can't remember the basic statistics ... here is my attempt to use their library. I just have a sliding window here and compute P between these values. What is the real way to get a PDF from here? 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 that you need a probability density function for the graph. the equations are in wikipedia , since I donโt know how to include mathematical markup. Just use p (x) as your Y value, and X as your X value, and you can get a pretty simple 2nd plot.
Have you looked at Mathtools under Java ?
Well, how about this ... you give it an array of X points (normalized, of course, you can convert your X-pixels into them by dividing each pixel position by the width of your image), and it will return to the height of the distribution curve (again multiply by the normalization factor). This is for the main case, when the average value is 0, and the 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 is easy enough to implement one that takes an arbitrary mean and standard deviation if it cannot be found on the network.
source share