numpy.random.Generator.laplace

方法

random.Generator.laplace(loc=0.0, scale=1.0, size=None)

从拉普拉斯或双指数分布中提取具有指定位置(或平均值)和刻度(衰减)的样本。

拉普拉斯分布类似于高斯/正态分布,但在峰值处更明显,尾部更粗。它表示两个独立的、相同分布的指数随机变量之间的差异。

参数
loc浮点数或类似浮点数的数组,可选

位置, \mu ,分布峰。默认值为0。

scale浮点数或类似浮点数的数组,可选

\lambda ,指数衰减。默认值为1。必须是非负的。

sizeint或int的元组,可选

输出形状。如果给定的形状是,例如, (m, n, k) 然后 m * n * k 取样。如果尺寸是 None (默认),如果 locscale 都是标量。否则, np.broadcast(loc, scale).size 取样。

返回
outndarray或scalar

从参数化拉普拉斯分布中提取样本。

笔记

它有概率密度函数

System Message: WARNING/2 (f(x;\mu,\lambda)=\frac{1}{2\lambda})

latex exited with error [stdout] This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=latex) restricted \write18 enabled. entering extended mode (./math.tex LaTeX2e <2018-12-01> (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls Document Class: article 2018/09/03 v1.4i Standard LaTeX document class (/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo)) (/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `?' option. (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty)) (/usr/share/texlive/texmf-dist/tex/latex/anyfontsize/anyfontsize.sty) (/usr/share/texlive/texmf-dist/tex/latex/tools/bm.sty) (./math.aux) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...��\lambda)=\frac{1}{2\lambda}\end{split} ! Package inputenc Error: Unicode character ; (U+FF1B) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...��\lambda)=\frac{1}{2\lambda}\end{split} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...��\lambda)=\frac{1}{2\lambda}\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...��\lambda)=\frac{1}{2\lambda}\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...��\lambda)=\frac{1}{2\lambda}\end{split} ! Package inputenc Error: Unicode character ; (U+FF1B) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...��\lambda)=\frac{1}{2\lambda}\end{split} ! Package inputenc Error: Unicode character , (U+FF0C) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...��\lambda)=\frac{1}{2\lambda}\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...��\lambda)=\frac{1}{2\lambda}\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 336 bytes). Transcript written on math.log.

1774年拉普拉斯第一定律指出,误差的频率可以表示为误差绝对大小的指数函数,从而得出拉普拉斯分布。对于经济学和卫生科学中的许多问题,这种分布似乎比标准高斯分布更好地模拟数据。

工具书类

1

Abramowitz,M.和Stegun,I.A.(编辑)。《数学函数与公式、图表和数学表手册》,第9版,纽约:多佛,1972年。

2

Kotz、Samuel等。”拉普拉斯分布和推广“,Birkhauser,2001.

3

拉普拉斯分布〉,摘自《数学世界——沃尔夫拉姆网络资源》。http://mathworld.wolfram.com/laplacedistribution.html

4

维基百科,“拉普拉斯分布”,https://en.wikipedia.org/wiki/laplace_distribution

实例

从分发中提取样本

>>> loc, scale = 0., 1.
>>> s = np.random.default_rng().laplace(loc, scale, 1000)

显示样本的直方图,以及概率密度函数:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, 30, density=True)
>>> x = np.arange(-8., 8., .01)
>>> pdf = np.exp(-abs(x-loc)/scale)/(2.*scale)
>>> plt.plot(x, pdf)

绘制高斯图进行比较:

>>> g = (1/(scale * np.sqrt(2 * np.pi)) *
...      np.exp(-(x - loc)**2 / (2 * scale**2)))
>>> plt.plot(x,g)
../../../_images/numpy-random-Generator-laplace-1.png