Article directory
Gaussian distribution
Normal distribution, also known as Gauss distribution, its probability density function is shown in the figure below
Normal distribution N ( μ , σ ) N(\mu, \sigma)N ( μ ,σ ) subject to expectationμ \muμ and varianceσ 2 \sigma^2p2 regulation, its probability density function is
1 2 π σ 2 exp [ − ( x − μ ) 2 2 σ 2 ] \frac{1}{\sqrt{2\pi\sigma^2}}\exp[-\frac{(x-\mu) ^2}{2\sigma^2}]2 p.s _21exp[−2 p2(x−m )2]
当μ = 0 \mu=0m=0 andσ = 1 \sigma=1p=When 1 , it is a standard normal distributionN ( 0 , 1 ) N(0,1)N(0,1 ) , the corresponding probability distribution function isΦ ( x ) = 1 2 π exp [ − x 2 2 ] \Phi(x)=\frac{1}{\sqrt{2\pi}}\exp[-\frac {x^2}{2}]Φ ( x )=2 p.m1exp[−2x2]。
Introduction to Inverse Gaussian Distribution
In Brownian motion, the Gaussian distribution describes the distribution of distance at a fixed moment; the inverse Gaussian distribution is the distribution of the time required to reach a fixed distance.
Therefore, the inverse of the inverse Gaussian distribution is taken from the physical meaning, rather than any "inverse" in the expression, and its PDF is
p ( x ) = λ 2 π x 3 exp [ − λ ( x − μ ) 2 2 μ 2 x ] p(x)=\sqrt{\frac{\lambda}{2\pi x^3}}\ exp[-\frac{\lambda(x-\mu)^2}{2\mu^2x}]p(x)=2πx3lexp[−2 m2x _λ ( x−m )2]
scipy.stats
function is provided in , invgauss
but its default λ = 1 \lambda=1l=1当λ \lambdaWhen λ approaches infinity, the inverse Gaussian distribution tends to a Gaussian distribution.
In particular, when μ = λ = 1 \mu=\lambda=1m=l=1 , the inverse Gaussian distribution is also called the Wald distribution, and its probability density function expression is
p ( x ) = 1 2 π x 3 exp [ − ( x − 1 ) 2 2 x ] p(x)=\frac{1}{\sqrt{2\pi x^3}}\exp[-\frac{(x-1)^2}{2x}] p(x)=2πx31exp[−2x _(x−1)2]
scipy.stats
wald
Functions are also encapsulated in , ie wald
.
Constructing an inverse Gaussian distribution from a Gaussian distribution
Random numbers of inverse Gaussian distribution can be generated through normal distribution and uniform distribution of random numbers, set ν \nuν obeys the standard normal distribution;z
obeys the standard uniform distribution, then let
x = μ + μ 2 ν 2 2 λ − μ 2 λ 4 μ λ ν 2 + μ 2 ν 4 x=\mu+\frac{\mu^2\nu^2}{2\lambda}-\frac{\ mu}{2\lambda}\sqrt{4\mu\lambda\nu^2+\mu^2\nu^4}x=m+2 minm2 n2−2 minm4 m l n2+m2 n4
若 z ⩽ μ μ + x z\leqslant\frac{\mu}{\mu+x} z⩽m + xm, then return xxx , otherwise returnμ 2 x \frac{\mu^2}{x}xm2
Considering invgauss
the default λ = 1 \lambda=1l=1 , soxxx的电视式改的x = μ + μ 2 ν 2 2 − μ 2 4 μ ν 2 + μ 2 ν 4 x=\mu+\frac{\mu^2\nu^2}{2}-\frac{ \mu}{2}\sqrt{4\mu\nu^2+\mu^2\nu^4}x=m+2m2 n2−2m4 m n2+m2 n4
import numpy as np
from scipy.stats import norm, invgauss, uniform
import matplotlib.pyplot as plt
nu = norm.rvs(size=10000)
mu = 1 # 设mu=1
n2, m2 = nu**2, mu**2
x = mu + m2*n2/2-mu/2*np.sqrt(4*mu*n2+m2*nu**4)
z = uniform.rvs(size=10000)
flag = z<(mu/(mu+x))
rs = flag*x + (1-flag)*m2/x
rv = invgauss(mu)
st, ed = rv.interval(0.995)
xs = np.linspace(st, ed, 200)
def drawPDF(rs, xs, ys):
plt.figure(figsize=(5,3))
plt.hist(rs, density=True, bins=100, alpha=0.8)
plt.plot(xs, ys)
plt.tight_layout()
plt.show()
drawPDF(rs, xs, rv.pdf(xs))
The result is as follows