2 :filename: distributions.py
3 :synopsis: Analytic expressions for fracture radii distributions
5 :maintainer: Jeffrey Hyman
6 :moduleauthor: Jeffrey Hyman <jhyman@lanl.gov>
9 from scipy
import stats, special
15 """ Returns the analytical values of the power law CDF with exponent a
20 The lower bound of the truncated power law distribution.
22 The alpha parameter in the power law distribution.
29 Analytical values of the power law CDF
31 cdf = 1 - ((xmin / x)**alpha)
36 """ Returns the analytical power laws PDF values.
41 The normalization constant for the PDF
43 The lower bound of the truncated power law distribution.
45 The alpha parameter (decay rate / exponent) in the power law distribution.
47 x-values of the function
51 Analytical values of the power law PDF
54 pdf = norm_const * ((alpha * (xmin**alpha)) / x**(alpha + 1))
58 def tpl(alpha, xmin, xmax):
59 """ Returns the PDF and CDF of a truncated Power-law distribution with exponent alpha over the range [xmin,xmax].
64 The alpha parameter (decay rate / exponent) in the power law distribution. (alpha > 0)
73 x-values of the function
75 pdf values of the truncated powerlaw
77 cdf values of truncated powerlaw distribution
81 dfnWorks uses the convention of pdf(x) = C x^{-(alpha +1)}, rather than pdf(x) = C x^{-alpha} for a powerlaw.
85 x = np.linspace(xmin, xmax, 1000)
86 norm_const = 1.0 / (
tpl_cdf(xmin, alpha, xmax) -
88 pdf =
tpl_pdf(norm_const, xmin, alpha, x)
95 """ Returns the analytical values of the PDF of the exponential distribution with exponent eLambda for values of x.
100 The normalization constant for the PDF
102 The exponent of the exponential distribution
104 x-values of the function
108 Analytical values of the power law PDF
114 pdf = norm_const * eLambda * np.e**(-eLambda * x)
119 """ Returns the analytical values of the CDF of the exponential distribution with exponent eLambda for values of x.
124 The exponent of the exponential distribution
126 x-values of the function
130 Analytical values of the exponential CDF
137 cdf = 1 - (np.e**(-eLambda * (x - xmin)))
142 """ Returns the PDF and CDF of an exponential distribution with exponent eLambda over the range [xmin,xmax].
147 The exponent of the exponential distribution
156 x-values of the function
158 pdf values of the exponential distribution
160 cdf values of exponential distribution
167 x = np.linspace(xmin, xmax, 1000)
169 pdf =
exp_pdf(const, eLambda, x)
176 """ Returns the analytical values of the CDF of the lognormal distribution with parameters mu and sigma
181 x-values of the function
183 Lognormal distribution parameter #1
185 Lognormal distribution parameter #1 (sigma > 0)
189 Analytical values of the CDF for the Log-Normal distribution
195 cdf = 0.5 + (0.5 * special.erf((np.log(x) - mu) / (np.sqrt(2) * sigma)))
200 """ Returns the analytical values of the CDF of the lognormal distribution with parameters mu and sigma
205 x-values of the function
207 Lognormal distribution parameter #1
209 Lognormal distribution parameter #1 (sigma > 0)
213 Analytical values of the PDF for the Log-Normal distribution
219 constant = 1 / (x * sigma * np.sqrt(2 * np.pi))
220 exp_term = (-1.0 * (np.log(x) - mu)**2 / (2 * sigma**2))
221 pdf = constant * np.exp(exp_term)
226 """ Returns the PDF and CDF of a LogNormal distribution with parameters mu and sigma over the range [xmin,xmax].
231 Lognormal distribution parameter #1
233 Lognormal distribution parameter #1 (sigma > 0)
242 x-values of the function
244 pdf values of the lognormal distribution
246 cdf values of lognormal distribution
250 dfnGen uses the mean and standard deviation of the underlying normal distribution that creates the lognormal distribution.
252 In order to produce a LogNormal distribution with a desired mean (m) and variance (s) one uses
254 mu = ln [ m^2 / sqrt(m^2 + s^2)]
258 sigma = ln ( 1 + m^2 / s^2)
260 For more details see https://en.wikipedia.org/wiki/Log-normal_distribution
263 x = np.linspace(xmin, xmax, 1000)
272 """ Returns the Empirical Cumulative Density function of provided values
277 array of values to be binned
284 values of the cdf, normalized so cumulative sum = 1
293 cdf = np.ones(len(vals))
294 cdf = np.cumsum(cdf) / sum(cdf)
def tpl_pdf(norm_const, xmin, alpha, x)
def lognormal_pdf(x, mu, sigma)
def lognormal_cdf(x, mu, sigma)
Log-Normal Distribution Functions ########.
def exp_pdf(norm_const, eLambda, x)
Exponential Distribution Functions ########.
def lognormal(mu, sigma, xmin, xmax)
def tpl(alpha, xmin, xmax)
def tpl_cdf(xmin, alpha, x)
Truncated Power Law Distribution Functions ########.
def exponential(eLambda, xmin, xmax)