@@ -0,0 +1,2040 @@
+package net.imglib2.algorithm.stats;%0A%0Aimport net.imglib2.Cursor;%0Aimport net.imglib2.RandomAccessibleInterval;%0Aimport net.imglib2.type.numeric.RealType;%0Aimport net.imglib2.view.Views;%0A%0Apublic class RayleighDistribution%0A%7B%0A%09private static final double SQRT_PI_OVER_2 = Math.sqrt( Math.PI / 2 );%0A%0A%09private double sigmaSquared;%0A%09private long count;%0A%0A%09public double getSigma()%0A%09%7B%0A%09%09return Math.sqrt( sigmaSquared );%0A%09%7D%0A%0A%09public double getSigmaSquared()%0A%09%7B%0A%09%09return sigmaSquared;%0A%09%7D%0A%09%0A%09public double getMean()%0A%09%7B%0A%09%09return getSigma() * SQRT_PI_OVER_2;%0A%09%7D%0A%09%0A%09public double getMode()%0A%09%7B%0A%09%09return getSigma();%0A%09%7D%0A%0A%09public double getVariance()%0A%09%7B%0A%09%09return getSigmaSquared() * (( 4 - Math.PI ) / 2);%0A%09%7D%0A%09%0A%09/**%0A%09 * Only valid for x %3E= 0 but performs no checks%0A%09 * @param x the value%0A%09 * @return the value of the Rayleigh pdf at x%0A%09 */%0A%09public double pdfAt( double x )%0A%09%7B%0A%09%09double sigma2 = getSigmaSquared();%09%09%0A%09%09return (x / sigma2) * Math.exp( -(x * x) / (2 * sigma2) );%0A%09%7D%0A%09%0A%09/**%0A%09 * Computes the max-likelihood estimate of the scale parameter sigma%0A%09 * %0A%09 * @param rai%0A%09 * @return sigma%0A%09 */%0A%09public %3CT extends RealType%3C T %3E%3E void fit( RandomAccessibleInterval%3C T %3E rai )%0A%09%7B%0A%09%09sigmaSquared = 0.0;%0A%09%09count = 0;%0A%0A%09%09Cursor%3C T %3E c = Views.flatIterable( rai ).cursor();%0A%09%09while ( c.hasNext() )%0A%09%09%7B%0A%09%09%09T t = c.next();%0A%09%09%09sigmaSquared += (t.getRealDouble() * t.getRealDouble());%0A%09%09%09count++;%0A%09%09%7D%0A%09%09sigmaSquared = sigmaSquared / (2 * count);%0A%09%7D%0A%09%0A%09/*%0A%09public %3CT extends RealType%3C T %3E%3E double onlineUpdateFit( RandomAccessibleInterval%3C T %3E rai )%0A%09%7B%0A%09%09long newCount = 0;%0A%09%09double subsetSigmaSquared = 0.0;%0A%09%09%0A%09%09Cursor%3C T %3E c = Views.flatIterable( rai ).cursor();%0A%09%09while ( c.hasNext() )%0A%09%09%7B%0A%09%09%09T t = c.next();%0A%09%09%09subsetSigmaSquared += (t.getRealDouble() * t.getRealDouble());%0A%09%09%09newCount++;%0A%09%09%7D%0A%09%09subsetSigmaSquared = subsetSigmaSquared / (2 * count);%0A%09%09%0A%09%09sigmaSquared = ( sigmaSquared + subsetSigmaSquared ) / newCount;%0A%09%09count += newCount;%0A%0A%09%09return sigmaSquared;%0A%09%7D%0A%09*/%0A%0A%09public static void main( String%5B%5D args )%0A%09%7B%0A%09%09// TODO Auto-generated method stub%0A%0A%09%7D%0A%0A%7D%0A

add rayleigh distribution fitter