dask 2021.10.0

NotesParametersRaisesReturns
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.

note

New code should use the power method of a default_rng() instance instead; please see the :None:ref:`random-quick-start`.

Notes

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.

Parameters

a : float or array_like of floats

Parameter of the distribution. 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 a is a scalar. Otherwise, np.array(a).size samples are drawn.

Raises

ValueError

If a <= 0.

Returns

out : ndarray or scalar

Drawn samples from the parameterized power distribution.

Draws samples in [0, 1] from a power distribution with positive exponent a - 1.

See Also

Generator.power

which should be used for new code.

Examples

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: +SKIP
... 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
This example is valid syntax, but we were not able to check execution
>>> plt.figure()  # doctest: +SKIP
... plt.hist(rvs, bins=50, density=True) # doctest: +SKIP
... plt.plot(xx,powpdf,'r-') # doctest: +SKIP
... plt.title('np.random.power(5)') # doctest: +SKIP
This example is valid syntax, but we were not able to check execution
>>> plt.figure()  # doctest: +SKIP
... 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
This example is valid syntax, but we were not able to check execution
>>> plt.figure()  # doctest: +SKIP
... 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
See :

Local connectivity graph

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


File: /dask/array/random.py#373
type: <class 'function'>
Commit: