logistic

Contents

logistic#

class braincore.random.logistic(loc=None, scale=None, size=None, key=None, dtype=None)[source]#

Draw 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:
  • loc (float or array_like of floats, optional) – Parameter of the distribution. Default is 0.

  • scale (float or array_like of floats, optional) – Parameter of the distribution. Must be non-negative. Default is 1.

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

  • key (PRNGKey, optional) – The key for the random number generator. If not given, the default random number generator is used.

Returns:

out – Drawn samples from the parameterized logistic distribution.

Return type:

ndarray or scalar

Notes

The probability density for the Logistic distribution is

\[P(x) = 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 it can act as a mixture of Gumbel distributions, in Epidemiology, and by the World Chess Federation (FIDE) where it is used in the Elo ranking system, assuming the performance of each player is a logistically distributed random variable.

References

Examples

Draw samples from the distribution:

>>> loc, scale = 10, 1
>>> s = braincore.random.logistic(loc, scale, 10000)
>>> import matplotlib.pyplot as plt  # noqa
>>> count, bins, ignored = plt.hist(s, bins=50)

# plot against distribution

>>> def logist(x, loc, scale):
...     return np.exp((loc-x)/scale)/(scale*(1+np.exp((loc-x)/scale))**2)
>>> lgst_val = logist(bins, loc, scale)
>>> plt.plot(bins, lgst_val * count.max() / lgst_val.max())
>>> plt.show()