package jasext.hist.function;
import jas2.hist.*;
/**
* The function represents the Landau distribution.
* This class represents a Landau distribution, as
* approximated by the Moyal formula
* \[ Moyal(\lambda) = \frac{\exp{-0.5(\lambda+\exp{-\lambda})}}{\sqrt{2\pi}} \]
* See J.E. Moyal, Theory of ionization fluctuations, Phil. Mag. 46 (1955) 263.
* Note that this analytical approximation is too low in the tail.
* In order to allow for a fit, we define
* \[ \lambda = \frac{x - m}{s} \]
* with x the dataset variable.
*
**/
public class LandauFunction extends Fittable1DFunction implements HasHandles
{
/**
*
*/
private static final long serialVersionUID = 1L;
public LandauFunction(double amplitude, double mean, double sigma)
{
this.max = amplitude;
this.mean = mean;
this.sigma = sigma;
}
public LandauFunction(double xmin, double xmax, double ymin, double ymax)
{
this.max = ymin + (ymax - ymin)*.8;
this.mean = (xmin + xmax)/2;
this.sigma = (xmax - xmin)/6;
}
public double valueAt(double x)
{
double yy = ( x - mean ) / sigma;
double tt = Math.exp ( -0.5 * ( yy + Math.exp ( -1.0 * yy ) ) )
/ Math.sqrt ( 2.0 * Math.PI );
return max * tt;
// return max * Math.exp(-Math.pow((x-mean)/sigma,2)/2);
}
public double valueAt(double x, double[] a)
{
double yy = ( x - a[1] ) / a[2];
double tt = Math.exp ( -0.5 * ( yy + Math.exp ( -1.0 * yy ) ) )
/ Math.sqrt ( 2.0 * Math.PI );
return a[0] * tt;
}
public String[] getParameterNames()
{
final String[] result = { "amplitude","mean","sigma" };
return result;
}
public double[] getParameterValues()
{
final double[] result = { max, mean, sigma };
return result;
}
public void setParameter(int index, double value)
{
if (index == 0) max = value;
else if (index == 1) mean = value;
else if (index == 2) sigma = value;
else throw new IllegalArgumentException("Invalid index to setParameter");
clearFit();
setChanged();
}
public void setFit(Fitter fit, double[] value)
{
if (value.length != 3)
throw new IllegalArgumentException("Argument to setParameters is of wrong length");
max = value[0];
mean = value[1];
sigma = value[2];
setFit(fit);
setChanged();
}
public String getTitle()
{
return "Landau";
}
public Statistics getStatistics()
{
return this;
}
public Handle[] getHandles(double xLow, double xHigh, double yLow, double yHigh)
{
Handle[] result = new Handle[3];
result[0] = new Handle()
{
public void moveTo(double x, double y)
{
mean = x;
max = y;
clearFit();
setChanged();
}
public double getX()
{
return mean;
}
public double getY()
{
return max;
}
};
result[1] = new Handle()
{
public void moveTo(double x, double y)
{
sigma = (mean - x)/fwhm;
clearFit();
setChanged();
}
public double getY()
{
return max/2;
}
public double getX()
{
return mean-sigma*fwhm;
}
};
result[2] = new Handle()
{
public void moveTo(double x, double y)
{
sigma = (x - mean)/fwhm;
clearFit();
setChanged();
}
public double getY()
{
return max/2;
}
public double getX()
{
return mean+sigma*fwhm;
}
};
return result;
}
private final static double fwhm = 2.354/2;
private double max;
private double mean;
private double sigma;
}
Ads help maintain this website.