nlcpy.random.Generator.logistic

Generator.logistic(self, loc=0.0, scale=1.0, size=None)

Draws samples from a logistic distribution.

Samples are drawn from a logistic distribution with specified parameters, loc (location or mean, also median), and scale (>0).

Parameters
locfloat, optional

Parameter of the distribution. Default is 0.

scalefloat, optional

Parameter of the distribution. Must be non-negative. Default is 1.

sizeint or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn.

Returns
outndarray

Drawn samples from the parameterized logistic distribution.

Note

The probability density for the Logistic distribution is

P(x) = \frac{e^{-(x-\mu)/s}}{s(1+e^{-(x-\mu)/s})^2},

where \mu = location and s = scale.

Restriction

  • If loc is neither a scalar nor None : NotImplementedError occurs.

  • If scale is neither a scalar nor None : NotImplementedError occurs.

Examples

Draw samples from the distribution:

>>> import nlcpy as vp
>>> loc, scale = 10, 1
>>> s = vp.random.default_rng().logistic(loc, scale, 10000)
>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s.get(), bins=50)

Plot against distribution

>>> def logist(x, loc, scale):
...     return vp.exp((loc-x)/scale)/(scale*(1+vp.exp((loc-x)/scale))**2)
>>> lgst_val = logist(bins, loc, scale)
>>> plt.plot(bins, lgst_val * count.max() / lgst_val.max()) 
... 
>>> plt.show()
../../_images/nlcpy-random-Generator-logistic-1.png