numpy.random.Generator.logistic#

method

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

Draw samples from a logistic distribution.

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

Parameters:
locfloat or array_like of floats, optional

Parameter of the distribution. Default is 0.

scalefloat or array_like of floats, 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), thenm*n*k samples are drawn. If size isNone (default),a single value is returned ifloc andscale are both scalars.Otherwise,np.broadcast(loc,scale).size samples are drawn.

Returns:
outndarray or scalar

Drawn samples from the parameterized logistic distribution.

See also

scipy.stats.logistic

probability density function, distribution or cumulative density function, etc.

Notes

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.

The Logistic distribution is used in Extreme Value problems where itcan act as a mixture of Gumbel distributions, in Epidemiology, and bythe World Chess Federation (FIDE) where it is used in the Elo rankingsystem, assuming the performance of each player is a logisticallydistributed random variable.

References

[1]

Reiss, R.-D. and Thomas M. (2001), “Statistical Analysis ofExtreme Values, from Insurance, Finance, Hydrology and OtherFields,” Birkhauser Verlag, Basel, pp 132-133.

[2]

Weisstein, Eric W. “Logistic Distribution.” FromMathWorld–A Wolfram Web Resource.https://mathworld.wolfram.com/LogisticDistribution.html

[3]

Wikipedia, “Logistic-distribution”,https://en.wikipedia.org/wiki/Logistic_distribution

Examples

Draw samples from the distribution:

>>>loc,scale=10,1>>>rng=np.random.default_rng()>>>s=rng.logistic(loc,scale,10000)>>>importmatplotlib.pyplotasplt>>>count,bins,_=plt.hist(s,bins=50,label='Sampled data')

# plot sampled data against the exact distribution

>>>deflogistic(x,loc,scale):...returnnp.exp((loc-x)/scale)/(scale*(1+np.exp((loc-x)/scale))**2)>>>logistic_values=logistic(bins,loc,scale)>>>bin_spacing=np.mean(np.diff(bins))>>>plt.plot(bins,logistic_values*bin_spacing*s.size,label='Logistic PDF')>>>plt.legend()>>>plt.show()
../../../_images/numpy-random-Generator-logistic-1.png