Skip to content

Commit

Permalink
Added Truncated Rayleigh distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
nicochunger committed Sep 14, 2018
1 parent 127eae6 commit 6efac95
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions run/priors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 6efac95

Please sign in to comment.