dask 2021.10.0

NotesParametersReturns
laplace(self, loc=0.0, scale=1.0, size=None, chunks='auto', **kwargs)

This docstring was copied from numpy.random.mtrand.RandomState.laplace.

Some inconsistencies with the Dask version may exist.

The Laplace distribution is similar to the Gaussian/normal distribution, but is sharper at the peak and has fatter tails. It represents the difference between two independent, identically distributed exponential random variables.

note

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

Notes

It has the probability density function

$$f(x; \mu, \lambda) = \frac{1}{2\lambda}\exp\left(-\frac{|x - \mu|}{\lambda}\right).$$

The first law of Laplace, from 1774, states that the frequency of an error can be expressed as an exponential function of the absolute magnitude of the error, which leads to the Laplace distribution. For many problems in economics and health sciences, this distribution seems to model the data better than the standard Gaussian distribution.

Parameters

loc : float or array_like of floats, optional

The position, $\mu$ , of the distribution peak. Default is 0.

scale : float or array_like of floats, optional

$\lambda$ , the exponential decay. Default is 1. 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 loc and scale are both scalars. Otherwise, np.broadcast(loc, scale).size samples are drawn.

Returns

out : ndarray or scalar

Drawn samples from the parameterized Laplace distribution.

Draw samples from the Laplace or double exponential distribution with specified location (or mean) and scale (decay).

See Also

Generator.laplace

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
>>> loc, scale = 0., 1.  # doctest: +SKIP
... s = np.random.laplace(loc, scale, 1000) # 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, 30, density=True) # doctest: +SKIP
... x = np.arange(-8., 8., .01) # doctest: +SKIP
... pdf = np.exp(-abs(x-loc)/scale)/(2.*scale) # doctest: +SKIP
... plt.plot(x, pdf) # doctest: +SKIP

Plot Gaussian for comparison:

This example is valid syntax, but we were not able to check execution
>>> g = (1/(scale * np.sqrt(2 * np.pi)) *  # doctest: +SKIP
...  np.exp(-(x - loc)**2 / (2 * scale**2)))
... plt.plot(x,g) # 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#307
type: <class 'function'>
Commit: