power(self, a, size=None, chunks='auto', **kwargs)
This docstring was copied from numpy.random.mtrand.RandomState.power.
Some inconsistencies with the Dask version may exist.
Also known as the power function distribution.
New code should use the power
method of a default_rng()
instance instead; please see the :None:ref:`random-quick-start`
.
The probability density function is
$$P(x; a) = ax^{a-1}, 0 \le x \le 1, a>0.$$The power function distribution is just the inverse of the Pareto distribution. It may also be seen as a special case of the Beta distribution.
It is used, for example, in modeling the over-reporting of insurance claims.
Parameter of the distribution. Must be non-negative.
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 a
is a scalar. Otherwise, np.array(a).size
samples are drawn.
If a <= 0.
Drawn samples from the parameterized power distribution.
Draws samples in [0, 1] from a power distribution with positive exponent a - 1.
Generator.power
which should be used for new code.
Draw samples from the distribution:
This example is valid syntax, but we were not able to check execution>>> a = 5. # shape # doctest: +SKIP
... samples = 1000 # doctest: +SKIP
... s = np.random.power(a, samples) # doctest: +SKIP
Display the histogram of the samples, along with the probability density function:
This example is valid syntax, but we were not able to check execution>>> import matplotlib.pyplot as plt # doctest: +SKIP
... count, bins, ignored = plt.hist(s, bins=30) # doctest: +SKIP
... x = np.linspace(0, 1, 100) # doctest: +SKIP
... y = a*x**(a-1.) # doctest: +SKIP
... normed_y = samples*np.diff(bins)[0]*y # doctest: +SKIP
... plt.plot(x, normed_y) # doctest: +SKIP
... plt.show() # doctest: +SKIP
Compare the power function distribution to the inverse of the Pareto.
This example is valid syntax, but we were not able to check execution>>> from scipy import stats # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... rvs = np.random.power(5, 1000000) # doctest: +SKIP
... rvsp = np.random.pareto(5, 1000000) # doctest: +SKIP
... xx = np.linspace(0,1,100) # doctest: +SKIP
... powpdf = stats.powerlaw.pdf(xx,5) # doctest: +SKIP
>>> plt.figure() # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... plt.hist(rvs, bins=50, density=True) # doctest: +SKIP
... plt.plot(xx,powpdf,'r-') # doctest: +SKIP
... plt.title('np.random.power(5)') # doctest: +SKIP
>>> plt.figure() # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... plt.hist(1./(1.+rvsp), bins=50, density=True) # doctest: +SKIP
... plt.plot(xx,powpdf,'r-') # doctest: +SKIP
... plt.title('inverse of 1 + np.random.pareto(5)') # doctest: +SKIP
>>> plt.figure() # doctest: +SKIPSee :
... plt.hist(1./(1.+rvsp), bins=50, density=True) # doctest: +SKIP
... plt.plot(xx,powpdf,'r-') # doctest: +SKIP
... plt.title('inverse of stats.pareto(5)') # doctest: +SKIP
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them