python-igraph API reference

List of all classes, functions and methods in python-igraph

module documentation

Statistics related stuff in igraph

Class FittedPowerLaw Result of fitting a power-law to a vector of samples
Class Histogram Generic histogram class for real numbers
Class RunningMean Running mean calculator.
Function mean Returns the mean of an iterable.
Function median Returns the median of an unsorted or sorted numeric vector.
Function percentile Returns the pth percentile of an unsorted or sorted numeric vector.
Function power_law_fit Fitting a power-law distribution to empirical data
Function quantile Returns the qth quantile of an unsorted or sorted numeric vector.
Function sd Returns the standard deviation of an iterable.
Function var Returns the variance of an iterable.
def mean(xs):

Returns the mean of an iterable.

Example:

>>> mean([1, 4, 7, 11])
5.75
Parametersxsan iterable yielding numbers.
Returnsthe mean of the numbers provided by the iterable.
See AlsoRunningMean() if you also need the variance or the standard deviation
def median(xs, sort=True):

Returns the median of an unsorted or sorted numeric vector.

Parametersxsthe vector itself.
sortwhether to sort the vector. If you know that the vector is sorted already, pass False here.
Returnsthe median, which will always be a float, even if the vector contained integers originally.
def percentile(xs, p=(25, 50, 75), sort=True):

Returns the pth percentile of an unsorted or sorted numeric vector.

This is equivalent to calling quantile(xs, p/100.0); see quantile for more details on the calculation.

Example:

>>> round(percentile([15, 20, 40, 35, 50], 40), 2)
26.0
>>> for perc in percentile([15, 20, 40, 35, 50], (0, 25, 50, 75, 100)):
...     print("%.2f" % perc)
...
15.00
17.50
35.00
45.00
50.00
Parametersxsthe vector itself.
pthe percentile we are looking for. It may also be a list if you want to calculate multiple quantiles with a single call. The default value calculates the 25th, 50th and 75th percentile.
sortwhether to sort the vector. If you know that the vector is sorted already, pass False here.
Returnsthe pth percentile, which will always be a float, even if the vector contained integers originally. If p is a list, the result will also be a list containing the percentiles for each item in the list.
def power_law_fit(data, xmin=None, method='auto', return_alpha_only=False):

Fitting a power-law distribution to empirical data

Parametersdatathe data to fit, a list containing integer values
xminthe lower bound for fitting the power-law. If None, the optimal xmin value will be estimated as well. Zero means that the smallest possible xmin value will be used.
methodthe fitting method to use. The following methods are implemented so far:
  • continuous, hill: exact maximum likelihood estimation when the input data comes from a continuous scale. This is known as the Hill estimator. The statistical error of this estimator is (alpha-1) / sqrt(n), where alpha is the estimated exponent and n is the number of data points above xmin. The estimator is known to exhibit a small finite sample-size bias of order O(n^-1), which is small when n > 100. igraph will try to compensate for the finite sample size if n is small.
  • discrete: exact maximum likelihood estimation when the input comes from a discrete scale (see Clauset et al among the references).
  • auto: exact maximum likelihood estimation where the continuous method is used if the input vector contains at least one fractional value and the discrete method is used if the input vector contains integers only.
return_alpha_onlyUndocumented
Returnsa FittedPowerLaw object. The fitted xmin value and the power-law exponent can be queried from the xmin and alpha properties of the returned object.
Unknown Field: newfieldrefReference
Unknown Field: refMEJ Newman: Power laws, Pareto distributions and Zipf's law. Contemporary Physics 46, 323-351 (2005)
A Clauset, CR Shalizi, MEJ Newman: Power-law distributions in empirical data. E-print (2007). arXiv:0706.1062
def quantile(xs, q=(0.25, 0.5, 0.75), sort=True):

Returns the qth quantile of an unsorted or sorted numeric vector.

There are a number of different ways to calculate the sample quantile. The method implemented by igraph is the one recommended by NIST. First we calculate a rank n as q(N+1), where N is the number of items in xs, then we split n into its integer component k and decimal component d. If k <= 1, we return the first element; if k >= N, we return the last element, otherwise we return the linear interpolation between xs[k-1] and xs[k] using a factor d.

Example:

>>> round(quantile([15, 20, 40, 35, 50], 0.4), 2)
26.0
Parametersxsthe vector itself.
qthe quantile we are looking for. It may also be a list if you want to calculate multiple quantiles with a single call. The default value calculates the 25th, 50th and 75th percentile.
sortwhether to sort the vector. If you know that the vector is sorted already, pass False here.
Returnsthe qth quantile, which will always be a float, even if the vector contained integers originally. If q is a list, the result will also be a list containing the quantiles for each item in the list.
def sd(xs):

Returns the standard deviation of an iterable.

Example:

>>> sd([1, 4, 7, 11])       #doctest:+ELLIPSIS
4.2720...
Parametersxsan iterable yielding numbers.
Returnsthe standard deviation of the numbers provided by the iterable.
See AlsoRunningMean() if you also need the mean
def var(xs):

Returns the variance of an iterable.

Example:

>>> var([1, 4, 8, 11])            #doctest:+ELLIPSIS
19.333333...
Parametersxsan iterable yielding numbers.
Returnsthe variance of the numbers provided by the iterable.
See AlsoRunningMean() if you also need the mean
API Documentation for igraph, generated by pydoctor 21.2.2.