numpy.random.RandomState.noncentral_chisquare

方法

random.RandomState.noncentral_chisquare(df, nonc, size=None)

从非中心卡方分布中提取样本。

非中心的 \chi^2 分布是广义的 \chi^2 分布。

注解

新代码应该使用 noncentral_chisquare A方法 default_rng() 请参阅 快速启动 .

参数
df浮点数或类似浮点数的数组

自由度必须大于0。

在 1.10.0 版更改: 早期的numpy版本需要dfnum>1。

nonc浮点数或类似浮点数的数组

非中心性,必须是非负的。

sizeint或int的元组,可选

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

返回
outndarray或scalar

从参数化非中心卡方分布中提取样本。

参见

Generator.noncentral_chisquare

应该用于新代码。

笔记

非中心卡方分布的概率密度函数是

System Message: WARNING/2 (P(x;df,nonc)=\sum^{\infty}{i=0})

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 ...df,nonc)=\sum^{\infty}{i=0}\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 ...df,nonc)=\sum^{\infty}{i=0}\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 ...df,nonc)=\sum^{\infty}{i=0}\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 ...df,nonc)=\sum^{\infty}{i=0}\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 ...df,nonc)=\sum^{\infty}{i=0}\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 ...df,nonc)=\sum^{\infty}{i=0}\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 ...df,nonc)=\sum^{\infty}{i=0}\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 ...df,nonc)=\sum^{\infty}{i=0}\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 432 bytes). Transcript written on math.log.

在哪里? Y_{{q}} 是具有Q自由度的卡方。

工具书类

1

维基百科,“非中心卡方分布”https://en.wikipedia.org/wiki/noncentral_chi-squared_distribution

实例

从分布中绘制值并绘制柱状图

>>> import matplotlib.pyplot as plt
>>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),
...                   bins=200, density=True)
>>> plt.show()
../../../_images/numpy-random-RandomState-noncentral_chisquare-1_00_00.png

从非中心性很小的非中心角砾中提取值,并与角砾进行比较。

>>> plt.figure()
>>> values = plt.hist(np.random.noncentral_chisquare(3, .0000001, 100000),
...                   bins=np.arange(0., 25, .1), density=True)
>>> values2 = plt.hist(np.random.chisquare(3, 100000),
...                    bins=np.arange(0., 25, .1), density=True)
>>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob')
>>> plt.show()
../../../_images/numpy-random-RandomState-noncentral_chisquare-1_01_00.png

演示非中心性的大值如何导致更对称的分布。

>>> plt.figure()
>>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),
...                   bins=200, density=True)
>>> plt.show()
../../../_images/numpy-random-RandomState-noncentral_chisquare-1_02_00.png