noncentral_chisquare#
- class brainstate.random.noncentral_chisquare(df, nonc, size=None, key=None, dtype=None)#
Draw samples from a noncentral chi-square distribution.
The noncentral \(\chi^2\) distribution is a generalization of the \(\chi^2\) distribution.
- 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|Sequence[int] |integer|Sequence[integer] |None) – Output shape. If the given shape is, e.g.,(m, n, k), thenm * n * ksamples are drawn. If size isNone(default), a single value is returned ifdfandnoncare both scalars. Otherwise,np.broadcast(df, nonc).sizesamples are drawn.key (
int|Array|ndarray|None) – The key for the random number generator. If not given, the default random number generator is used.
- Returns:
out – Drawn samples from the parameterized noncentral chi-square distribution.
- Return type:
ndarray or scalar
Notes
The probability density function for the noncentral Chi-square distribution is
\[P(x;df,nonc) = \sum^{\infty}_{i=0} \frac{e^{-nonc/2}(nonc/2)^{i}}{i!} P_{Y_{df+2i}}(x),\]where \(Y_{q}\) is the Chi-square with q degrees of freedom.
References
Examples
Draw values from the distribution and plot the histogram
>>> import brainstate >>> import matplotlib.pyplot as plt # noqa >>> values = plt.hist(brainstate.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(brainstate.random.noncentral_chisquare(3, .0000001, 100000), ... bins=np.arange(0., 25, .1), density=True) >>> values2 = plt.hist(brainstate.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()
Demonstrate how large values of non-centrality lead to a more symmetric distribution.
>>> plt.figure() >>> values = plt.hist(brainstate.random.noncentral_chisquare(3, 20, 100000), ... bins=200, density=True) >>> plt.show()