方法
random.Generator.
gamma
从伽马分布中提取样本。
从具有指定参数的伽马分布中提取样本, shape (有时称为“k”)和 scale (有时称为“theta”),其中两个参数均大于0。
伽马分布的形状。必须为非负。
伽马分布的尺度。必须为非负。默认值等于1。
输出形状。如果给定的形状是,例如, (m, n, k) 然后 m * n * k 取样。如果尺寸是 None (默认),如果 shape 和 scale 都是标量。否则, np.broadcast(shape, scale).size 取样。
(m, n, k)
m * n * k
None
shape
scale
np.broadcast(shape, scale).size
从参数化伽马分布中提取样本。
参见
scipy.stats.gamma
概率密度函数、分布或累积密度函数等。
笔记
伽马分布的概率密度是
System Message: WARNING/2 (p(x)=x ^ k-1 \frac e ^-x/\theta \theta^k\gamma(k),)
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 ...\theta \theta^k\gamma(k),\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 ...\theta \theta^k\gamma(k),\end{split} ! Missing { inserted. <to be read again> } l.14 ...\theta \theta^k\gamma(k),\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 ...\theta \theta^k\gamma(k),\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 ...\theta \theta^k\gamma(k),\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 ...\theta \theta^k\gamma(k),\end{split} ! Missing } inserted. <inserted text> } l.14 ...\theta \theta^k\gamma(k),\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 ...\theta \theta^k\gamma(k),\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 ...\theta \theta^k\gamma(k),\end{split} ! Missing { inserted. <to be read again> } l.14 ...\theta \theta^k\gamma(k),\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 ...\theta \theta^k\gamma(k),\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 ...\theta \theta^k\gamma(k),\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 ...\theta \theta^k\gamma(k),\end{split} ! Missing } inserted. <inserted text> } l.14 ...\theta \theta^k\gamma(k),\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 472 bytes). Transcript written on math.log.
在哪里? 是形状和 规模和 是伽玛函数。
伽玛分布常被用来模拟电子元件的失效时间,并在泊松分布事件之间的等待时间相关的过程中自然出现。
工具书类
“伽马分布”,摘自《数学世界》——一个Wolfram网络资源。http://mathworld.wolfram.com/gammadistribution.html
维基百科,“gamma分布”,https://en.wikipedia.org/wiki/gamma_分布
实例
从分发中抽取样本:
>>> shape, scale = 2., 2. # mean=4, std=2*sqrt(2) >>> s = np.random.default_rng().gamma(shape, scale, 1000)
显示样本的直方图,以及概率密度函数:
>>> import matplotlib.pyplot as plt >>> import scipy.special as sps >>> count, bins, ignored = plt.hist(s, 50, density=True) >>> y = bins**(shape-1)*(np.exp(-bins/scale) / ... (sps.gamma(shape)*scale**shape)) >>> plt.plot(bins, y, linewidth=2, color='r') >>> plt.show()