From 6efac9556cfc427fb9b5adfe897b99ed8ea79960 Mon Sep 17 00:00:00 2001 From: Nicolas Unger Date: Fri, 14 Sep 2018 17:40:35 +0200 Subject: [PATCH] Added Truncated Rayleigh distribution --- run/priors.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/run/priors.py b/run/priors.py index 7930dac..1e997dd 100644 --- a/run/priors.py +++ b/run/priors.py @@ -242,6 +242,30 @@ def _ppf(self, q, mu, sigma, xmin, xmax): # Interpolate the _inverse_ CDF return interpolate.interp1d(cdf, x)(q) +class truncrayleigh_gen(rv_continuous): + def _argcheck(self, sigma, xmax): + return (sigma > 0) + + def _pdf(self, x, sigma, xmax): + A1 = 1 - n.exp(-xmax**2/(2*sigma**2)) + n1 = ((x/sigma**2) * n.exp(-x**2/(2*sigma**2)))/A1 + return n.where((x >= 0) & (x < xmax), n1, 0.0) + + def _cdf(self, x, sigma, xmax): + A1 = 1 - n.exp(-xmax**2/(2*sigma**2)) + cdf = 1 - n.exp(-x**2/(2*sigma**2)) + cdf = cdf/A1 + # Consider the limits of the uniform + cdf = n.where((x >= 0), cdf, 0.0) + cdf = n.where((x < xmax), cdf, 1.0) + return cdf + + def ppf(self, q, sigma, xmax): + A = 1 - n.exp(-xmax**2/(2*sigma**2)) + ppf = n.sqrt(-2*sigma**2*n.log(1-(q*A))) + return ppf + + class truncnormJ_gen(rv_continuous): def _argcheck(self, mu, sigma, xmin, xmax): @@ -434,6 +458,8 @@ def _ppf(self, q, alpha, beta): shapes='mu, sigma1, sigma2') TruncatedUNormal = truncnormU_gen(name='Truncated normal distribution', shapes='mu, sigma, xmin, xmax') +TruncatedRayleigh = truncrayleigh_gen(name='Truncated Rayleigh Distribution', + shapes='sigma, xmax') PowerLaw = powerlaw_gen(name='Power law distribution', shapes='alpha, xmin, xmax') DoublePowerLaw = doublepowerlaw_gen(name='Double Power law distribution',