flopscope.

flopscope.numpy.random.Generator.logseries

fnp.random.Generator.logseries(self, p, size=None)

Draw samples from a logarithmic series distribution.

Adapted from NumPy docs np.random.Generator.logseries

Arearandom
Typecounted
Cost
numel(output)\text{numel}(\text{output})
Flopscope Context

Log-series distribution; cost = numel(output).

Samples are drawn from a log series distribution with specified shape parameter, 0 <= p < 1.

Parameters

p:float or array_like of floats

Shape parameter for the distribution. Must be in the range [0, 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 p is a scalar. Otherwise, flops.array(p).size samples are drawn.

Returns

out:ndarray or scalar

Drawn samples from the parameterized logarithmic series distribution.

See also

Notes

The probability mass function for the Log Series distribution is

P(k)=pkkln(1p),P(k) = \frac{-p^k}{k \ln(1-p)},

where p = probability.

The log series distribution is frequently used to represent species richness and occurrence, first proposed by Fisher, Corbet, and Williams in 1943 [2]. It may also be used to model the numbers of occupants seen in cars [3].

References

footnote
1

Buzas, Martin A.; Culver, Stephen J.,  Understanding regional
species diversity through the log series distribution of
occurrences: BIODIVERSITY RESEARCH Diversity & Distributions,
Volume 5, Number 5, September 1999 , pp. 187-195(9).
footnote
2

Fisher, R.A,, A.S. Corbet, and C.B. Williams. 1943. The
relation between the number of species and the number of
individuals in a random sample of an animal population.
Journal of Animal Ecology, 12:42-58.
footnote
3

D. J. Hand, F. Daly, D. Lunn, E. Ostrowski, A Handbook of Small
Data Sets, CRC Press, 1994.
footnote
4

Wikipedia, "Logarithmic distribution",
https://en.wikipedia.org/wiki/Logarithmic_distribution

Examples

Draw samples from the distribution:

>>> a = .6
>>> rng = flops.random.default_rng()
>>> s = rng.logseries(a, 10000)
>>> import matplotlib.pyplot as plt
>>> bins = flops.arange(-.5, max(s) + .5 )
>>> count, bins, _ = plt.hist(s, bins=bins, label='Sample count')

# plot against distribution

>>> def logseries(k, p):
... return -p**k/(k*flops.log(1-p))
>>> centres = flops.arange(1, max(s) + 1)
>>> plt.plot(centres, logseries(centres, a) * s.size, 'r', label='logseries PMF')
>>> plt.legend()
>>> plt.show()