@@ -0,0 +1,2757 @@
+package beast.math.distributions;%0A%0A%0Aimport org.apache.commons.math.distribution.ContinuousDistribution;%0Aimport org.apache.commons.math.distribution.GammaDistributionImpl;%0Aimport org.apache.commons.math.MathException;%0A%0Aimport beast.core.Description;%0Aimport beast.core.Input;%0Aimport beast.core.parameter.RealParameter;%0A%0A@Description(%22Laplace distribution.    f(x%7C%5C%5Cmu,b) = %5C%5Cfrac%7B1%7D%7B2b%7D %5C%5Cexp %5C%5Cleft( -%5C%5Cfrac%7B%7Cx-%5C%5Cmu%7C%7D%7Bb%7D %5C%5Cright)%22 +%0A        %22The probability density function of the Laplace distribution is also reminiscent of the normal distribution; %22 +%0A        %22however, whereas the normal distribution is expressed in terms of the squared difference from the mean ?, %22 +%0A        %22the Laplace density is expressed in terms of the absolute difference from the mean. Consequently the Laplace %22 +%0A        %22distribution has fatter tails than the normal distribution.%22)%0Apublic class LaplaceDistribution extends ParametricDistribution %7B%0A    public Input%3CRealParameter%3E m_mu = new Input%3CRealParameter%3E(%22mu%22, %22location parameter, defaults to 0%22);%0A    public Input%3CRealParameter%3E m_scale = new Input%3CRealParameter%3E(%22scale%22, %22scale parameter, defaults to 1%22);%0A%0A    // the mean parameter%0A    double mu;%0A    // the scale parameter%0A    double scale;%0A    // the maximum density%0A    double c;%0A%0A    @Override%0A    public void initAndValidate() %7B%0A        refresh();%0A    %7D%0A%0A    /**%0A     * make sure internal state is up to date *%0A     */%0A    void refresh() %7B%0A        double fMu;%0A        double fScale;%0A        if (m_mu.get() == null) %7B%0A            fMu = 0;%0A        %7D else %7B%0A            fMu = m_mu.get().getValue();%0A        %7D%0A        if (m_scale.get() == null) %7B%0A            fScale = 1;%0A        %7D else %7B%0A            fScale = m_scale.get().getValue();%0A        %7D%0A        setParameters(fMu, fScale);%0A    %7D%0A%0A    /**%0A     * Set parameters of this distribution%0A     *%0A     * @param m mean%0A     * @param s scale%0A     */%0A    protected void setParameters(double m, double s) %7B%0A        if (s %3C= 0) s = 1;%0A        mu = m;%0A        scale = s;%0A%0A        //Normalizing constant%0A        c = 1 / (2 * scale);%0A    %7D%0A%0A    @Override%0A    public double density(double x) %7B%0A        return c * Math.exp(-Math.abs(x - mu) / scale);%0A    %7D%0A%0A    @Override%0A    public double logDensity(double x) %7B%0A        return Math.log(c) - (Math.abs(x - mu) / scale);%0A    %7D%0A%0A    @Override%0A    public double cumulativeProbability(double x) throws MathException %7B%0A        if (x == mu) %7B%0A            return 0.5;%0A        %7D else %7B%0A            return (0.5) * (1 + ((x - mu) / Math.abs(x - mu)) * (1 - Math.exp(-Math.abs(x - mu) / scale)));%0A        %7D%0A    %7D%0A%0A    @Override%0A    public ContinuousDistribution getDistribution() %7B%0A//%09%09refresh();%0A//%09%09return null;%0A        throw new UnsupportedOperationException();%0A    %7D%0A%0A%7D // class

add Laplace Distribution