flopscope.

flopscope.numpy.random.RandomState.noncentral_chisquare

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

Draw samples from a noncentral chi-square distribution.

Arearandom
Typecounted
Cost
numel(output)\text{numel}(\text{output})
Flopscope Context

Legacy noncentral chi-square; cost = numel(output).

The noncentral χ2\chi^2 distribution is a generalization of the χ2\chi^2 distribution.

Note.

New code should use the noncentral_chisquare method of a Generator instance instead; please see the random-quick-start.

Parameters

df:float or array_like of floats

Degrees of freedom, must be > 0.

nonc:float or array_like of floats

Non-centrality, must be non-negative.

size:int or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if df and nonc are both scalars. Otherwise, flops.broadcast(df, nonc).size samples are drawn.

Returns

out:ndarray or scalar

Drawn samples from the parameterized noncentral chi-square distribution.

See also

Notes

The probability density function for the noncentral Chi-square distribution is

P(x;df,nonc)=i=0enonc/2(nonc/2)ii!PYdf+2i(x),P(x;df,nonc) = \sum^{\infty}_{i=0} \frac{e^{-nonc/2}(nonc/2)^{i}}{i!} P_{Y_{df+2i}}(x),

where YqY_{q} is the Chi-square with q degrees of freedom.

References

footnote
1

Wikipedia, "Noncentral chi-squared distribution"
https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution

Examples

Draw values from the distribution and plot the histogram

>>> import matplotlib.pyplot as plt
>>> values = plt.hist(flops.random.noncentral_chisquare(3, 20, 100000),
... bins=200, density=True)
>>> plt.show()

Draw values from a noncentral chisquare with very small noncentrality, and compare to a chisquare.

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

Demonstrate how large values of non-centrality lead to a more symmetric distribution.

>>> plt.figure()
>>> values = plt.hist(flops.random.noncentral_chisquare(3, 20, 100000),
... bins=200, density=True)
>>> plt.show()